개정판 97a17f3a
issue #00000 Color List 추가
Change-Id: Ia5334ce5ce6f8f859d1b2ee5f7148e216cfe1770
ColorList/App.Debug.config | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> |
|
3 |
<!-- In case configuration is not the root element, replace it with root element in source configuration file --> |
|
4 |
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> |
|
5 |
</configuration> |
ColorList/App.Release.config | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> |
|
3 |
<!-- In case configuration is not the root element, replace it with root element in source configuration file --> |
|
4 |
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> |
|
5 |
</configuration> |
ColorList/App.config | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<configuration> |
|
3 |
<configSections></configSections> |
|
4 |
<connectionStrings> |
|
5 |
<add name="ColorList.Properties.Settings.설정" connectionString="Data Source=192.168.0.67;Initial Catalog=markus;Persist Security Info=True;User ID=doftech;Password=dof1073#" providerName="System.Data.SqlClient" /> |
|
6 |
<add name="markusEntities" connectionString="metadata=res://*/ModelMarkus.csdl|res://*/ModelMarkus.ssdl|res://*/ModelMarkus.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.67;initial catalog=markus;persist security info=True;user id=doftech;password=dof1073#;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> |
|
7 |
</connectionStrings> |
|
8 |
<startup> |
|
9 |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> |
|
10 |
</startup> |
|
11 |
</configuration> |
ColorList/App.xaml | ||
---|---|---|
1 |
<Application |
|
2 |
x:Class="ColorList.App" |
|
3 |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
4 |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
5 |
xmlns:local="clr-namespace:ColorList" |
|
6 |
StartupUri="MainWindow.xaml"> |
|
7 |
<Application.Resources /> |
|
8 |
</Application> |
ColorList/App.xaml.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Configuration; |
|
4 |
using System.Data; |
|
5 |
using System.Linq; |
|
6 |
using System.Threading.Tasks; |
|
7 |
using System.Windows; |
|
8 |
|
|
9 |
namespace ColorList |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// App.xaml에 대한 상호 작용 논리 |
|
13 |
/// </summary> |
|
14 |
public partial class App : Application |
|
15 |
{ |
|
16 |
} |
|
17 |
} |
ColorList/ColorList.csproj | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
3 |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|
4 |
<PropertyGroup> |
|
5 |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
6 |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
7 |
<ProjectGuid>{AC15A6B9-8556-4492-A1D7-DA16F00EF86B}</ProjectGuid> |
|
8 |
<OutputType>WinExe</OutputType> |
|
9 |
<RootNamespace>ColorList</RootNamespace> |
|
10 |
<AssemblyName>ColorList</AssemblyName> |
|
11 |
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> |
|
12 |
<FileAlignment>512</FileAlignment> |
|
13 |
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|
14 |
<WarningLevel>4</WarningLevel> |
|
15 |
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|
16 |
<Deterministic>true</Deterministic> |
|
17 |
<TargetFrameworkProfile /> |
|
18 |
</PropertyGroup> |
|
19 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
20 |
<PlatformTarget>AnyCPU</PlatformTarget> |
|
21 |
<DebugSymbols>true</DebugSymbols> |
|
22 |
<DebugType>full</DebugType> |
|
23 |
<Optimize>false</Optimize> |
|
24 |
<OutputPath>bin\Debug\</OutputPath> |
|
25 |
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|
26 |
<ErrorReport>prompt</ErrorReport> |
|
27 |
<WarningLevel>4</WarningLevel> |
|
28 |
</PropertyGroup> |
|
29 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
30 |
<PlatformTarget>AnyCPU</PlatformTarget> |
|
31 |
<DebugType>pdbonly</DebugType> |
|
32 |
<Optimize>true</Optimize> |
|
33 |
<OutputPath>bin\Release\</OutputPath> |
|
34 |
<DefineConstants>TRACE</DefineConstants> |
|
35 |
<ErrorReport>prompt</ErrorReport> |
|
36 |
<WarningLevel>4</WarningLevel> |
|
37 |
</PropertyGroup> |
|
38 |
<ItemGroup> |
|
39 |
<Reference Include="System" /> |
|
40 |
<Reference Include="System.Data" /> |
|
41 |
<Reference Include="System.Runtime.Serialization" /> |
|
42 |
<Reference Include="System.Security" /> |
|
43 |
<Reference Include="System.Xml" /> |
|
44 |
<Reference Include="Microsoft.CSharp" /> |
|
45 |
<Reference Include="System.Core" /> |
|
46 |
<Reference Include="System.Xml.Linq" /> |
|
47 |
<Reference Include="System.Data.DataSetExtensions" /> |
|
48 |
<Reference Include="System.Net.Http" /> |
|
49 |
<Reference Include="System.Xaml"> |
|
50 |
<RequiredTargetFramework>4.0</RequiredTargetFramework> |
|
51 |
</Reference> |
|
52 |
<Reference Include="Telerik.Windows.Controls, Version=2019.3.917.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> |
|
53 |
<HintPath>..\lib\RCWPF\2019.3.917.45\Telerik.Windows.Controls.dll</HintPath> |
|
54 |
<Private>True</Private> |
|
55 |
</Reference> |
|
56 |
<Reference Include="Telerik.Windows.Controls.Docking, Version=2019.3.917.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> |
|
57 |
<HintPath>..\lib\RCWPF\2019.3.917.45\Telerik.Windows.Controls.Docking.dll</HintPath> |
|
58 |
<Private>True</Private> |
|
59 |
</Reference> |
|
60 |
<Reference Include="Telerik.Windows.Controls.Input, Version=2019.3.917.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> |
|
61 |
<HintPath>..\lib\RCWPF\2019.3.917.45\Telerik.Windows.Controls.Input.dll</HintPath> |
|
62 |
<Private>True</Private> |
|
63 |
</Reference> |
|
64 |
<Reference Include="Telerik.Windows.Controls.Navigation, Version=2019.3.917.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> |
|
65 |
<HintPath>..\lib\RCWPF\2019.3.917.45\Telerik.Windows.Controls.Navigation.dll</HintPath> |
|
66 |
<Private>True</Private> |
|
67 |
</Reference> |
|
68 |
<Reference Include="Telerik.Windows.Data, Version=2019.3.917.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> |
|
69 |
<HintPath>..\lib\RCWPF\2019.3.917.45\Telerik.Windows.Data.dll</HintPath> |
|
70 |
<Private>True</Private> |
|
71 |
</Reference> |
|
72 |
<Reference Include="WindowsBase" /> |
|
73 |
<Reference Include="PresentationCore" /> |
|
74 |
<Reference Include="PresentationFramework" /> |
|
75 |
</ItemGroup> |
|
76 |
<ItemGroup> |
|
77 |
<ApplicationDefinition Include="App.xaml"> |
|
78 |
<Generator>MSBuild:Compile</Generator> |
|
79 |
<SubType>Designer</SubType> |
|
80 |
</ApplicationDefinition> |
|
81 |
<Compile Include="MainWindow.xaml.cs"> |
|
82 |
<DependentUpon>MainWindow.xaml</DependentUpon> |
|
83 |
</Compile> |
|
84 |
<Compile Include="App.xaml.cs"> |
|
85 |
<DependentUpon>App.xaml</DependentUpon> |
|
86 |
<SubType>Code</SubType> |
|
87 |
</Compile> |
|
88 |
<Compile Include="RaisePropertyChange.cs" /> |
|
89 |
<Page Include="MainWindow.xaml"> |
|
90 |
<Generator>MSBuild:Compile</Generator> |
|
91 |
<SubType>Designer</SubType> |
|
92 |
</Page> |
|
93 |
</ItemGroup> |
|
94 |
<ItemGroup> |
|
95 |
<Compile Include="ModelMarkus.Context.cs"> |
|
96 |
<AutoGen>True</AutoGen> |
|
97 |
<DesignTime>True</DesignTime> |
|
98 |
<DependentUpon>ModelMarkus.Context.tt</DependentUpon> |
|
99 |
</Compile> |
|
100 |
<Compile Include="ModelMarkus.cs"> |
|
101 |
<AutoGen>True</AutoGen> |
|
102 |
<DesignTime>True</DesignTime> |
|
103 |
<DependentUpon>ModelMarkus.tt</DependentUpon> |
|
104 |
</Compile> |
|
105 |
<Compile Include="ModelMarkus.Designer.cs"> |
|
106 |
<AutoGen>True</AutoGen> |
|
107 |
<DesignTime>True</DesignTime> |
|
108 |
<DependentUpon>ModelMarkus.edmx</DependentUpon> |
|
109 |
</Compile> |
|
110 |
<Compile Include="PROPERTIES.cs"> |
|
111 |
<DependentUpon>ModelMarkus.tt</DependentUpon> |
|
112 |
</Compile> |
|
113 |
<Compile Include="Properties\AssemblyInfo.cs"> |
|
114 |
<SubType>Code</SubType> |
|
115 |
</Compile> |
|
116 |
<Compile Include="Properties\Resources.Designer.cs"> |
|
117 |
<AutoGen>True</AutoGen> |
|
118 |
<DesignTime>True</DesignTime> |
|
119 |
<DependentUpon>Resources.resx</DependentUpon> |
|
120 |
</Compile> |
|
121 |
<Compile Include="Properties\Settings.Designer.cs"> |
|
122 |
<AutoGen>True</AutoGen> |
|
123 |
<DependentUpon>Settings.settings</DependentUpon> |
|
124 |
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
|
125 |
</Compile> |
|
126 |
<EmbeddedResource Include="Properties\Resources.resx"> |
|
127 |
<Generator>ResXFileCodeGenerator</Generator> |
|
128 |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
|
129 |
</EmbeddedResource> |
|
130 |
<None Include="App.Debug.config"> |
|
131 |
<DependentUpon>App.config</DependentUpon> |
|
132 |
</None> |
|
133 |
<None Include="App.Release.config"> |
|
134 |
<DependentUpon>App.config</DependentUpon> |
|
135 |
</None> |
|
136 |
<EntityDeploy Include="ModelMarkus.edmx"> |
|
137 |
<Generator>EntityModelCodeGenerator</Generator> |
|
138 |
<LastGenOutput>ModelMarkus.Designer.cs</LastGenOutput> |
|
139 |
</EntityDeploy> |
|
140 |
<None Include="ModelMarkus.edmx.diagram"> |
|
141 |
<DependentUpon>ModelMarkus.edmx</DependentUpon> |
|
142 |
</None> |
|
143 |
<None Include="Properties\Settings.settings"> |
|
144 |
<Generator>SettingsSingleFileGenerator</Generator> |
|
145 |
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
|
146 |
</None> |
|
147 |
</ItemGroup> |
|
148 |
<ItemGroup> |
|
149 |
<None Include="App.config" /> |
|
150 |
</ItemGroup> |
|
151 |
<ItemGroup> |
|
152 |
<Resource Include="sample.png" /> |
|
153 |
</ItemGroup> |
|
154 |
<ItemGroup> |
|
155 |
<ProjectReference Include="..\ZoomAndPan\ZoomAndPan.csproj"> |
|
156 |
<Project>{6c950af4-04d2-4638-8b78-472e39f78b45}</Project> |
|
157 |
<Name>ZoomAndPan</Name> |
|
158 |
</ProjectReference> |
|
159 |
</ItemGroup> |
|
160 |
<ItemGroup> |
|
161 |
<Content Include="ModelMarkus.Context.tt"> |
|
162 |
<Generator>TextTemplatingFileGenerator</Generator> |
|
163 |
<DependentUpon>ModelMarkus.edmx</DependentUpon> |
|
164 |
<LastGenOutput>ModelMarkus.Context.cs</LastGenOutput> |
|
165 |
</Content> |
|
166 |
<Content Include="ModelMarkus.tt"> |
|
167 |
<Generator>TextTemplatingFileGenerator</Generator> |
|
168 |
<DependentUpon>ModelMarkus.edmx</DependentUpon> |
|
169 |
<LastGenOutput>ModelMarkus.cs</LastGenOutput> |
|
170 |
</Content> |
|
171 |
</ItemGroup> |
|
172 |
<ItemGroup> |
|
173 |
<PackageReference Include="EntityFramework"> |
|
174 |
<Version>6.2.0</Version> |
|
175 |
</PackageReference> |
|
176 |
<PackageReference Include="EntityFramework.ko"> |
|
177 |
<Version>6.2.0</Version> |
|
178 |
</PackageReference> |
|
179 |
</ItemGroup> |
|
180 |
<ItemGroup> |
|
181 |
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> |
|
182 |
</ItemGroup> |
|
183 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|
184 |
</Project> |
ColorList/MainWindow.xaml | ||
---|---|---|
1 |
<Window |
|
2 |
x:Class="ColorList.MainWindow" |
|
3 |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
4 |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
5 |
xmlns:ZoomAndPan="clr-namespace:ZoomAndPan;assembly=ZoomAndPan" |
|
6 |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|
7 |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|
8 |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
|
9 |
Title="Color List" |
|
10 |
Width="600" |
|
11 |
Height="600"> |
|
12 |
<Grid> |
|
13 |
<Grid.RowDefinitions> |
|
14 |
<RowDefinition Height="Auto" /> |
|
15 |
<RowDefinition /> |
|
16 |
</Grid.RowDefinitions> |
|
17 |
<Grid.ColumnDefinitions> |
|
18 |
<ColumnDefinition Width="Auto" MinWidth="150" /> |
|
19 |
<ColumnDefinition /> |
|
20 |
</Grid.ColumnDefinitions> |
|
21 |
<ZoomAndPan:ZoomAndPanControl |
|
22 |
x:Name="zoomAndPanControl" |
|
23 |
Grid.Row="1" |
|
24 |
Grid.Column="1" |
|
25 |
Background="LightGray" |
|
26 |
ConstrainedContentViewportHeight="{Binding ActualHeight, ElementName=image, Mode=OneWay}" |
|
27 |
ConstrainedContentViewportWidth="{Binding ActualWidth, ElementName=image, Mode=OneWay}" |
|
28 |
ContentScale="1" |
|
29 |
MouseWheel="zoomAndPanControl_MouseWheel"> |
|
30 |
<Canvas x:Name="canvas"> |
|
31 |
<Canvas.RenderTransform> |
|
32 |
<TransformGroup> |
|
33 |
<RotateTransform x:Name="rotate" Angle="0" /> |
|
34 |
<TranslateTransform x:Name="translate" X="1" Y="1" /> |
|
35 |
</TransformGroup> |
|
36 |
</Canvas.RenderTransform> |
|
37 |
<Image |
|
38 |
x:Name="image" |
|
39 |
Canvas.Left="-226" |
|
40 |
Canvas.Top="-340" |
|
41 |
Source="/sample.png" |
|
42 |
Stretch="None" /> |
|
43 |
</Canvas> |
|
44 |
</ZoomAndPan:ZoomAndPanControl> |
|
45 |
<StackPanel Margin="5"> |
|
46 |
<Button |
|
47 |
Width="100" |
|
48 |
Height="24" |
|
49 |
Click="Button_Click" |
|
50 |
Content="Save" /> |
|
51 |
</StackPanel> |
|
52 |
<telerik:RadListBox x:Name="listBox" Grid.Row="1"> |
|
53 |
<telerik:RadListBox.ItemTemplate> |
|
54 |
<DataTemplate> |
|
55 |
<StackPanel> |
|
56 |
<Border |
|
57 |
Background="{Binding Color}" |
|
58 |
BorderBrush="#FFE0E0E0" |
|
59 |
BorderThickness="1" /> |
|
60 |
<TextBlock Text="{Binding Inx}" /> |
|
61 |
</StackPanel> |
|
62 |
</DataTemplate> |
|
63 |
</telerik:RadListBox.ItemTemplate> |
|
64 |
</telerik:RadListBox> |
|
65 |
</Grid> |
|
66 |
</Window> |
ColorList/MainWindow.xaml.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Windows; |
|
6 |
using System.Windows.Controls; |
|
7 |
using System.Windows.Data; |
|
8 |
using System.Windows.Documents; |
|
9 |
using System.Windows.Input; |
|
10 |
using System.Windows.Media; |
|
11 |
using System.Windows.Media.Imaging; |
|
12 |
using System.Windows.Shapes; |
|
13 |
|
|
14 |
using Telerik.Windows.Controls; |
|
15 |
|
|
16 |
namespace ColorList |
|
17 |
{ |
|
18 |
/// <summary> |
|
19 |
/// Interaction logic for Window.xaml |
|
20 |
/// </summary> |
|
21 |
public partial class MainWindow : Window |
|
22 |
{ |
|
23 |
public const string DISPLAY_COLOR = "DisplayColor"; |
|
24 |
|
|
25 |
public MainWindow() |
|
26 |
{ |
|
27 |
InitializeComponent(); |
|
28 |
|
|
29 |
using(markusEntities entities = new markusEntities()) |
|
30 |
{ |
|
31 |
listBox.ItemsSource = entities.PROPERTIES.Where(x => x.TYPE == DISPLAY_COLOR).Select((x,inx) => new ColorItem {Inx = inx,Color = x.VALUE }); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
private void zoomAndPanControl_MouseWheel(object sender, MouseWheelEventArgs e) |
|
36 |
{ |
|
37 |
e.Handled = true; |
|
38 |
if (e.Delta > 0) |
|
39 |
{ |
|
40 |
Point currentContentMousePoint = e.GetPosition(canvas); |
|
41 |
ZoomIn(currentContentMousePoint); |
|
42 |
} |
|
43 |
else |
|
44 |
{ |
|
45 |
Point currentContentMousePoint = e.GetPosition(canvas); |
|
46 |
ZoomOut(currentContentMousePoint); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
private void ZoomOut(Point contentZoomCenter) |
|
51 |
{ |
|
52 |
if (zoomAndPanControl.ContentScale > 0.39) |
|
53 |
{ |
|
54 |
zoomAndPanControl.ZoomAboutPoint(zoomAndPanControl.ContentScale - 0.2, contentZoomCenter); |
|
55 |
} |
|
56 |
else |
|
57 |
{ |
|
58 |
zoomAndPanControl.ZoomAboutPoint(zoomAndPanControl.ContentScale / 2, contentZoomCenter); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
private void ZoomIn(Point contentZoomCenter) |
|
63 |
{ |
|
64 |
if (zoomAndPanControl.ContentScale > 0.19) |
|
65 |
{ |
|
66 |
zoomAndPanControl.ZoomAboutPoint(zoomAndPanControl.ContentScale + 0.2, contentZoomCenter); |
|
67 |
} |
|
68 |
else |
|
69 |
{ |
|
70 |
zoomAndPanControl.ZoomAboutPoint(zoomAndPanControl.ContentScale * 2, contentZoomCenter); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
private async void Button_Click(object sender, RoutedEventArgs e) |
|
75 |
{ |
|
76 |
using (markusEntities entities = new markusEntities()) |
|
77 |
{ |
|
78 |
foreach (var item in listBox.ItemsSource.Cast<ColorItem>()) |
|
79 |
{ |
|
80 |
var result = await entities.PROPERTIES.FindAsync(item.ID); |
|
81 |
|
|
82 |
if(result != null) |
|
83 |
{ |
|
84 |
result.VALUE = item.Color; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
var value = await entities.SaveChangesAsync(); |
|
89 |
|
|
90 |
if(value > -1) |
|
91 |
{ |
|
92 |
|
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public class ColorItem : NotifyPropertyChange |
|
99 |
{ |
|
100 |
private int id; |
|
101 |
private int inx; |
|
102 |
private string color; |
|
103 |
public int ID { get => id; set => SetProperty(ref id, value); } |
|
104 |
public int Inx { get => inx; set => SetProperty(ref inx, value); } |
|
105 |
public string Color { get => color; set => SetProperty(ref color, value); } |
|
106 |
} |
|
107 |
} |
ColorList/ModelMarkus.Context.cs | ||
---|---|---|
1 |
//------------------------------------------------------------------------------ |
|
2 |
// <auto-generated> |
|
3 |
// 이 코드는 템플릿에서 생성되었습니다. |
|
4 |
// |
|
5 |
// 이 파일을 수동으로 변경하면 응용 프로그램에서 예기치 않은 동작이 발생할 수 있습니다. |
|
6 |
// 이 파일을 수동으로 변경하면 코드가 다시 생성될 때 변경 내용을 덮어씁니다. |
|
7 |
// </auto-generated> |
|
8 |
//------------------------------------------------------------------------------ |
|
9 |
|
|
10 |
namespace ColorList |
|
11 |
{ |
|
12 |
using System; |
|
13 |
using System.Data.Entity; |
|
14 |
using System.Data.Entity.Infrastructure; |
|
15 |
|
|
16 |
public partial class markusEntities : DbContext |
|
17 |
{ |
|
18 |
public markusEntities() |
|
19 |
: base("name=markusEntities") |
|
20 |
{ |
|
21 |
} |
|
22 |
|
|
23 |
protected override void OnModelCreating(DbModelBuilder modelBuilder) |
|
24 |
{ |
|
25 |
throw new UnintentionalCodeFirstException(); |
|
26 |
} |
|
27 |
|
|
28 |
public virtual DbSet<PROPERTIES> PROPERTIES { get; set; } |
|
29 |
} |
|
30 |
} |
ColorList/ModelMarkus.Context.tt | ||
---|---|---|
1 |
<#@ template language="C#" debug="false" hostspecific="true"#> |
|
2 |
<#@ include file="EF6.Utility.CS.ttinclude"#><#@ |
|
3 |
output extension=".cs"#><# |
|
4 |
|
|
5 |
const string inputFile = @"ModelMarkus.edmx"; |
|
6 |
var textTransform = DynamicTextTransformation.Create(this); |
|
7 |
var code = new CodeGenerationTools(this); |
|
8 |
var ef = new MetadataTools(this); |
|
9 |
var typeMapper = new TypeMapper(code, ef, textTransform.Errors); |
|
10 |
var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors); |
|
11 |
var itemCollection = loader.CreateEdmItemCollection(inputFile); |
|
12 |
var modelNamespace = loader.GetModelNamespace(inputFile); |
|
13 |
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef); |
|
14 |
|
|
15 |
var container = itemCollection.OfType<EntityContainer>().FirstOrDefault(); |
|
16 |
if (container == null) |
|
17 |
{ |
|
18 |
return string.Empty; |
|
19 |
} |
|
20 |
#> |
|
21 |
//------------------------------------------------------------------------------ |
|
22 |
// <auto-generated> |
|
23 |
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine1")#> |
|
24 |
// |
|
25 |
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine2")#> |
|
26 |
// <#=CodeGenerationTools.GetResourceString("Template_GeneratedCodeCommentLine3")#> |
|
27 |
// </auto-generated> |
|
28 |
//------------------------------------------------------------------------------ |
|
29 |
|
|
30 |
<# |
|
31 |
|
|
32 |
var codeNamespace = code.VsNamespaceSuggestion(); |
|
33 |
if (!String.IsNullOrEmpty(codeNamespace)) |
|
34 |
{ |
|
35 |
#> |
|
36 |
namespace <#=code.EscapeNamespace(codeNamespace)#> |
|
37 |
{ |
|
38 |
<# |
|
39 |
PushIndent(" "); |
|
40 |
} |
|
41 |
|
|
42 |
#> |
|
43 |
using System; |
|
44 |
using System.Data.Entity; |
|
45 |
using System.Data.Entity.Infrastructure; |
|
46 |
<# |
|
47 |
if (container.FunctionImports.Any()) |
|
48 |
{ |
|
49 |
#> |
|
50 |
using System.Data.Entity.Core.Objects; |
|
51 |
using System.Linq; |
|
52 |
<# |
|
53 |
} |
|
54 |
#> |
|
55 |
|
|
56 |
<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext |
|
57 |
{ |
|
58 |
public <#=code.Escape(container)#>() |
|
59 |
: base("name=<#=container.Name#>") |
|
60 |
{ |
|
61 |
<# |
|
62 |
if (!loader.IsLazyLoadingEnabled(container)) |
|
63 |
{ |
|
64 |
#> |
|
65 |
this.Configuration.LazyLoadingEnabled = false; |
|
66 |
<# |
|
67 |
} |
|
68 |
|
|
69 |
foreach (var entitySet in container.BaseEntitySets.OfType<EntitySet>()) |
|
70 |
{ |
|
71 |
// Note: the DbSet members are defined below such that the getter and |
|
72 |
// setter always have the same accessibility as the DbSet definition |
|
73 |
if (Accessibility.ForReadOnlyProperty(entitySet) != "public") |
|
74 |
{ |
|
75 |
#> |
|
76 |
<#=codeStringGenerator.DbSetInitializer(entitySet)#> |
|
77 |
<# |
|
78 |
} |
|
79 |
} |
|
80 |
#> |
|
81 |
} |
|
82 |
|
|
83 |
protected override void OnModelCreating(DbModelBuilder modelBuilder) |
|
84 |
{ |
|
85 |
throw new UnintentionalCodeFirstException(); |
|
86 |
} |
|
87 |
|
|
88 |
<# |
|
89 |
foreach (var entitySet in container.BaseEntitySets.OfType<EntitySet>()) |
|
90 |
{ |
|
91 |
#> |
|
92 |
<#=codeStringGenerator.DbSet(entitySet)#> |
|
93 |
<# |
|
94 |
} |
|
95 |
|
|
96 |
foreach (var edmFunction in container.FunctionImports) |
|
97 |
{ |
|
98 |
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: false); |
|
99 |
} |
|
100 |
#> |
|
101 |
} |
|
102 |
<# |
|
103 |
|
|
104 |
if (!String.IsNullOrEmpty(codeNamespace)) |
|
105 |
{ |
|
106 |
PopIndent(); |
|
107 |
#> |
|
108 |
} |
|
109 |
<# |
|
110 |
} |
|
111 |
#> |
|
112 |
<#+ |
|
113 |
|
|
114 |
private void WriteFunctionImport(TypeMapper typeMapper, CodeStringGenerator codeStringGenerator, EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) |
|
115 |
{ |
|
116 |
if (typeMapper.IsComposable(edmFunction)) |
|
117 |
{ |
|
118 |
#> |
|
119 |
|
|
120 |
[DbFunction("<#=edmFunction.NamespaceName#>", "<#=edmFunction.Name#>")] |
|
121 |
<#=codeStringGenerator.ComposableFunctionMethod(edmFunction, modelNamespace)#> |
|
122 |
{ |
|
123 |
<#+ |
|
124 |
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter); |
|
125 |
#> |
|
126 |
<#=codeStringGenerator.ComposableCreateQuery(edmFunction, modelNamespace)#> |
|
127 |
} |
|
128 |
<#+ |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
#> |
|
133 |
|
|
134 |
<#=codeStringGenerator.FunctionMethod(edmFunction, modelNamespace, includeMergeOption)#> |
|
135 |
{ |
|
136 |
<#+ |
|
137 |
codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter); |
|
138 |
#> |
|
139 |
<#=codeStringGenerator.ExecuteFunction(edmFunction, modelNamespace, includeMergeOption)#> |
|
140 |
} |
|
141 |
<#+ |
|
142 |
if (typeMapper.GenerateMergeOptionFunction(edmFunction, includeMergeOption)) |
|
143 |
{ |
|
144 |
WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: true); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
public void WriteFunctionParameter(string name, string isNotNull, string notNullInit, string nullInit) |
|
150 |
{ |
|
151 |
#> |
|
152 |
var <#=name#> = <#=isNotNull#> ? |
|
153 |
<#=notNullInit#> : |
|
154 |
<#=nullInit#>; |
|
155 |
|
|
156 |
<#+ |
|
157 |
} |
|
158 |
|
|
159 |
public const string TemplateId = "CSharp_DbContext_Context_EF6"; |
|
160 |
|
|
161 |
public class CodeStringGenerator |
|
162 |
{ |
|
163 |
private readonly CodeGenerationTools _code; |
|
164 |
private readonly TypeMapper _typeMapper; |
|
165 |
private readonly MetadataTools _ef; |
|
166 |
|
|
167 |
public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef) |
|
168 |
{ |
|
169 |
ArgumentNotNull(code, "code"); |
|
170 |
ArgumentNotNull(typeMapper, "typeMapper"); |
|
171 |
ArgumentNotNull(ef, "ef"); |
|
172 |
|
|
173 |
_code = code; |
|
174 |
_typeMapper = typeMapper; |
|
175 |
_ef = ef; |
|
176 |
} |
|
177 |
|
|
178 |
public string Property(EdmProperty edmProperty) |
|
179 |
{ |
|
180 |
return string.Format( |
|
181 |
CultureInfo.InvariantCulture, |
|
182 |
"{0} {1} {2} {{ {3}get; {4}set; }}", |
|
183 |
Accessibility.ForProperty(edmProperty), |
|
184 |
_typeMapper.GetTypeName(edmProperty.TypeUsage), |
|
185 |
_code.Escape(edmProperty), |
|
186 |
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)), |
|
187 |
_code.SpaceAfter(Accessibility.ForSetter(edmProperty))); |
|
188 |
} |
|
189 |
|
|
190 |
public string NavigationProperty(NavigationProperty navProp) |
|
191 |
{ |
|
192 |
var endType = _typeMapper.GetTypeName(navProp.ToEndMember.GetEntityType()); |
|
193 |
return string.Format( |
|
194 |
CultureInfo.InvariantCulture, |
|
195 |
"{0} {1} {2} {{ {3}get; {4}set; }}", |
|
196 |
AccessibilityAndVirtual(Accessibility.ForNavigationProperty(navProp)), |
|
197 |
navProp.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, |
|
198 |
_code.Escape(navProp), |
|
199 |
_code.SpaceAfter(Accessibility.ForGetter(navProp)), |
|
200 |
_code.SpaceAfter(Accessibility.ForSetter(navProp))); |
|
201 |
} |
|
202 |
|
|
203 |
public string AccessibilityAndVirtual(string accessibility) |
|
204 |
{ |
|
205 |
return accessibility + (accessibility != "private" ? " virtual" : ""); |
|
206 |
} |
|
207 |
|
|
208 |
public string EntityClassOpening(EntityType entity) |
|
209 |
{ |
|
210 |
return string.Format( |
|
211 |
CultureInfo.InvariantCulture, |
|
212 |
"{0} {1}partial class {2}{3}", |
|
213 |
Accessibility.ForType(entity), |
|
214 |
_code.SpaceAfter(_code.AbstractOption(entity)), |
|
215 |
_code.Escape(entity), |
|
216 |
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType))); |
|
217 |
} |
|
218 |
|
|
219 |
public string EnumOpening(SimpleType enumType) |
|
220 |
{ |
|
221 |
return string.Format( |
|
222 |
CultureInfo.InvariantCulture, |
|
223 |
"{0} enum {1} : {2}", |
|
224 |
Accessibility.ForType(enumType), |
|
225 |
_code.Escape(enumType), |
|
226 |
_code.Escape(_typeMapper.UnderlyingClrType(enumType))); |
|
227 |
} |
|
228 |
|
|
229 |
public void WriteFunctionParameters(EdmFunction edmFunction, Action<string, string, string, string> writeParameter) |
|
230 |
{ |
|
231 |
var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); |
|
232 |
foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable)) |
|
233 |
{ |
|
234 |
var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"; |
|
235 |
var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")"; |
|
236 |
var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + TypeMapper.FixNamespaces(parameter.RawClrTypeName) + "))"; |
|
237 |
writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit); |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace) |
|
242 |
{ |
|
243 |
var parameters = _typeMapper.GetParameters(edmFunction); |
|
244 |
|
|
245 |
return string.Format( |
|
246 |
CultureInfo.InvariantCulture, |
|
247 |
"{0} IQueryable<{1}> {2}({3})", |
|
248 |
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), |
|
249 |
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), |
|
250 |
_code.Escape(edmFunction), |
|
251 |
string.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray())); |
|
252 |
} |
|
253 |
|
|
254 |
public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace) |
|
255 |
{ |
|
256 |
var parameters = _typeMapper.GetParameters(edmFunction); |
|
257 |
|
|
258 |
return string.Format( |
|
259 |
CultureInfo.InvariantCulture, |
|
260 |
"return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});", |
|
261 |
_typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), |
|
262 |
edmFunction.NamespaceName, |
|
263 |
edmFunction.Name, |
|
264 |
string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()), |
|
265 |
_code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))); |
|
266 |
} |
|
267 |
|
|
268 |
public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) |
|
269 |
{ |
|
270 |
var parameters = _typeMapper.GetParameters(edmFunction); |
|
271 |
var returnType = _typeMapper.GetReturnType(edmFunction); |
|
272 |
|
|
273 |
var paramList = String.Join(", ", parameters.Select(p => TypeMapper.FixNamespaces(p.FunctionParameterType) + " " + p.FunctionParameterName).ToArray()); |
|
274 |
if (includeMergeOption) |
|
275 |
{ |
|
276 |
paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption"; |
|
277 |
} |
|
278 |
|
|
279 |
return string.Format( |
|
280 |
CultureInfo.InvariantCulture, |
|
281 |
"{0} {1} {2}({3})", |
|
282 |
AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), |
|
283 |
returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", |
|
284 |
_code.Escape(edmFunction), |
|
285 |
paramList); |
|
286 |
} |
|
287 |
|
|
288 |
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) |
|
289 |
{ |
|
290 |
var parameters = _typeMapper.GetParameters(edmFunction); |
|
291 |
var returnType = _typeMapper.GetReturnType(edmFunction); |
|
292 |
|
|
293 |
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())); |
|
294 |
if (includeMergeOption) |
|
295 |
{ |
|
296 |
callParams = ", mergeOption" + callParams; |
|
297 |
} |
|
298 |
|
|
299 |
return string.Format( |
|
300 |
CultureInfo.InvariantCulture, |
|
301 |
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});", |
|
302 |
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", |
|
303 |
edmFunction.Name, |
|
304 |
callParams); |
|
305 |
} |
|
306 |
|
|
307 |
public string DbSet(EntitySet entitySet) |
|
308 |
{ |
|
309 |
return string.Format( |
|
310 |
CultureInfo.InvariantCulture, |
|
311 |
"{0} virtual DbSet<{1}> {2} {{ get; set; }}", |
|
312 |
Accessibility.ForReadOnlyProperty(entitySet), |
|
313 |
_typeMapper.GetTypeName(entitySet.ElementType), |
|
314 |
_code.Escape(entitySet)); |
|
315 |
} |
|
316 |
|
|
317 |
public string DbSetInitializer(EntitySet entitySet) |
|
318 |
{ |
|
319 |
return string.Format( |
|
320 |
CultureInfo.InvariantCulture, |
|
321 |
"{0} = Set<{1}>();", |
|
322 |
_code.Escape(entitySet), |
|
323 |
_typeMapper.GetTypeName(entitySet.ElementType)); |
|
324 |
} |
|
325 |
|
|
326 |
public string UsingDirectives(bool inHeader, bool includeCollections = true) |
|
327 |
{ |
|
328 |
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) |
|
329 |
? string.Format( |
|
330 |
CultureInfo.InvariantCulture, |
|
331 |
"{0}using System;{1}" + |
|
332 |
"{2}", |
|
333 |
inHeader ? Environment.NewLine : "", |
|
334 |
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", |
|
335 |
inHeader ? "" : Environment.NewLine) |
|
336 |
: ""; |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
public class TypeMapper |
|
341 |
{ |
|
342 |
private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName"; |
|
343 |
|
|
344 |
private readonly System.Collections.IList _errors; |
|
345 |
private readonly CodeGenerationTools _code; |
|
346 |
private readonly MetadataTools _ef; |
|
347 |
|
|
348 |
public static string FixNamespaces(string typeName) |
|
349 |
{ |
|
350 |
return typeName.Replace("System.Data.Spatial.", "System.Data.Entity.Spatial."); |
|
351 |
} |
|
352 |
|
|
353 |
public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors) |
|
354 |
{ |
|
355 |
ArgumentNotNull(code, "code"); |
|
356 |
ArgumentNotNull(ef, "ef"); |
|
357 |
ArgumentNotNull(errors, "errors"); |
|
358 |
|
|
359 |
_code = code; |
|
360 |
_ef = ef; |
|
361 |
_errors = errors; |
|
362 |
} |
|
363 |
|
|
364 |
public string GetTypeName(TypeUsage typeUsage) |
|
365 |
{ |
|
366 |
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null); |
|
367 |
} |
|
368 |
|
|
369 |
public string GetTypeName(EdmType edmType) |
|
370 |
{ |
|
371 |
return GetTypeName(edmType, isNullable: null, modelNamespace: null); |
|
372 |
} |
|
373 |
|
|
374 |
public string GetTypeName(TypeUsage typeUsage, string modelNamespace) |
|
375 |
{ |
|
376 |
return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace); |
|
377 |
} |
|
378 |
|
|
379 |
public string GetTypeName(EdmType edmType, string modelNamespace) |
|
380 |
{ |
|
381 |
return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace); |
|
382 |
} |
|
383 |
|
|
384 |
public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace) |
|
385 |
{ |
|
386 |
if (edmType == null) |
|
387 |
{ |
|
388 |
return null; |
|
389 |
} |
|
390 |
|
|
391 |
var collectionType = edmType as CollectionType; |
|
392 |
if (collectionType != null) |
|
393 |
{ |
|
394 |
return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace)); |
|
395 |
} |
|
396 |
|
|
397 |
var typeName = _code.Escape(edmType.MetadataProperties |
|
398 |
.Where(p => p.Name == ExternalTypeNameAttributeName) |
|
399 |
.Select(p => (string)p.Value) |
|
400 |
.FirstOrDefault()) |
|
401 |
?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ? |
|
402 |
_code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) : |
|
403 |
_code.Escape(edmType)); |
|
404 |
|
|
405 |
if (edmType is StructuralType) |
|
406 |
{ |
|
407 |
return typeName; |
|
408 |
} |
|
409 |
|
|
410 |
if (edmType is SimpleType) |
|
411 |
{ |
|
412 |
var clrType = UnderlyingClrType(edmType); |
|
413 |
if (!IsEnumType(edmType)) |
|
414 |
{ |
|
415 |
typeName = _code.Escape(clrType); |
|
416 |
} |
|
417 |
|
|
418 |
typeName = FixNamespaces(typeName); |
|
419 |
|
|
420 |
return clrType.IsValueType && isNullable == true ? |
|
421 |
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) : |
|
422 |
typeName; |
|
423 |
} |
|
424 |
|
|
425 |
throw new ArgumentException("edmType"); |
|
426 |
} |
|
427 |
|
|
428 |
public Type UnderlyingClrType(EdmType edmType) |
|
429 |
{ |
|
430 |
ArgumentNotNull(edmType, "edmType"); |
|
431 |
|
|
432 |
var primitiveType = edmType as PrimitiveType; |
|
433 |
if (primitiveType != null) |
|
434 |
{ |
|
435 |
return primitiveType.ClrEquivalentType; |
|
436 |
} |
|
437 |
|
|
438 |
if (IsEnumType(edmType)) |
|
439 |
{ |
|
440 |
return GetEnumUnderlyingType(edmType).ClrEquivalentType; |
|
441 |
} |
|
442 |
|
|
443 |
return typeof(object); |
|
444 |
} |
|
445 |
|
|
446 |
public object GetEnumMemberValue(MetadataItem enumMember) |
|
447 |
{ |
|
448 |
ArgumentNotNull(enumMember, "enumMember"); |
|
449 |
|
|
450 |
var valueProperty = enumMember.GetType().GetProperty("Value"); |
|
451 |
return valueProperty == null ? null : valueProperty.GetValue(enumMember, null); |
|
452 |
} |
|
453 |
|
|
454 |
public string GetEnumMemberName(MetadataItem enumMember) |
|
455 |
{ |
|
456 |
ArgumentNotNull(enumMember, "enumMember"); |
|
457 |
|
|
458 |
var nameProperty = enumMember.GetType().GetProperty("Name"); |
|
459 |
return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null); |
|
460 |
} |
|
461 |
|
|
462 |
public System.Collections.IEnumerable GetEnumMembers(EdmType enumType) |
|
463 |
{ |
|
464 |
ArgumentNotNull(enumType, "enumType"); |
|
465 |
|
|
466 |
var membersProperty = enumType.GetType().GetProperty("Members"); |
|
467 |
return membersProperty != null |
|
468 |
? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null) |
|
469 |
: Enumerable.Empty<MetadataItem>(); |
|
470 |
} |
|
471 |
|
|
472 |
public bool EnumIsFlags(EdmType enumType) |
|
473 |
{ |
|
474 |
ArgumentNotNull(enumType, "enumType"); |
|
475 |
|
|
476 |
var isFlagsProperty = enumType.GetType().GetProperty("IsFlags"); |
|
477 |
return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null); |
|
478 |
} |
|
479 |
|
|
480 |
public bool IsEnumType(GlobalItem edmType) |
|
481 |
{ |
|
482 |
ArgumentNotNull(edmType, "edmType"); |
|
483 |
|
|
484 |
return edmType.GetType().Name == "EnumType"; |
|
485 |
} |
|
486 |
|
|
487 |
public PrimitiveType GetEnumUnderlyingType(EdmType enumType) |
|
488 |
{ |
|
489 |
ArgumentNotNull(enumType, "enumType"); |
|
490 |
|
|
491 |
return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null); |
|
492 |
} |
|
493 |
|
|
494 |
public string CreateLiteral(object value) |
|
495 |
{ |
|
496 |
if (value == null || value.GetType() != typeof(TimeSpan)) |
|
497 |
{ |
|
498 |
return _code.CreateLiteral(value); |
|
499 |
} |
|
500 |
|
|
501 |
return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks); |
|
502 |
} |
|
503 |
|
|
504 |
public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable<string> types, string sourceFile) |
|
505 |
{ |
|
506 |
ArgumentNotNull(types, "types"); |
|
507 |
ArgumentNotNull(sourceFile, "sourceFile"); |
|
508 |
|
|
509 |
var hash = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase); |
|
510 |
if (types.Any(item => !hash.Add(item))) |
|
511 |
{ |
|
512 |
_errors.Add( |
|
513 |
new CompilerError(sourceFile, -1, -1, "6023", |
|
514 |
String.Format(CultureInfo.CurrentCulture, CodeGenerationTools.GetResourceString("Template_CaseInsensitiveTypeConflict")))); |
|
515 |
return false; |
|
516 |
} |
|
517 |
return true; |
|
518 |
} |
|
519 |
|
|
520 |
public IEnumerable<SimpleType> GetEnumItemsToGenerate(IEnumerable<GlobalItem> itemCollection) |
|
521 |
{ |
|
522 |
return GetItemsToGenerate<SimpleType>(itemCollection) |
|
523 |
.Where(e => IsEnumType(e)); |
|
524 |
} |
|
525 |
|
|
526 |
public IEnumerable<T> GetItemsToGenerate<T>(IEnumerable<GlobalItem> itemCollection) where T: EdmType |
|
527 |
{ |
|
528 |
return itemCollection |
|
529 |
.OfType<T>() |
|
530 |
.Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) |
|
531 |
.OrderBy(i => i.Name); |
|
532 |
} |
|
533 |
|
|
534 |
public IEnumerable<string> GetAllGlobalItems(IEnumerable<GlobalItem> itemCollection) |
|
535 |
{ |
|
536 |
return itemCollection |
|
537 |
.Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i)) |
|
538 |
.Select(g => GetGlobalItemName(g)); |
|
539 |
} |
|
540 |
|
|
541 |
public string GetGlobalItemName(GlobalItem item) |
|
542 |
{ |
|
543 |
if (item is EdmType) |
|
544 |
{ |
|
545 |
return ((EdmType)item).Name; |
|
546 |
} |
|
547 |
else |
|
548 |
{ |
|
549 |
return ((EntityContainer)item).Name; |
|
550 |
} |
|
551 |
} |
|
552 |
|
|
553 |
public IEnumerable<EdmProperty> GetSimpleProperties(EntityType type) |
|
554 |
{ |
|
555 |
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); |
|
556 |
} |
|
557 |
|
|
558 |
public IEnumerable<EdmProperty> GetSimpleProperties(ComplexType type) |
|
559 |
{ |
|
560 |
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); |
|
561 |
} |
|
562 |
|
|
563 |
public IEnumerable<EdmProperty> GetComplexProperties(EntityType type) |
|
564 |
{ |
|
565 |
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); |
|
566 |
} |
|
567 |
|
|
568 |
public IEnumerable<EdmProperty> GetComplexProperties(ComplexType type) |
|
569 |
{ |
|
570 |
return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); |
|
571 |
} |
|
572 |
|
|
573 |
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(EntityType type) |
|
574 |
{ |
|
575 |
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); |
|
576 |
} |
|
577 |
|
|
578 |
public IEnumerable<EdmProperty> GetPropertiesWithDefaultValues(ComplexType type) |
|
579 |
{ |
|
580 |
return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); |
|
581 |
} |
|
582 |
|
|
583 |
public IEnumerable<NavigationProperty> GetNavigationProperties(EntityType type) |
|
584 |
{ |
|
585 |
return type.NavigationProperties.Where(np => np.DeclaringType == type); |
|
586 |
} |
|
587 |
|
|
588 |
public IEnumerable<NavigationProperty> GetCollectionNavigationProperties(EntityType type) |
|
589 |
{ |
|
590 |
return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many); |
|
591 |
} |
|
592 |
|
|
593 |
public FunctionParameter GetReturnParameter(EdmFunction edmFunction) |
|
594 |
{ |
|
595 |
ArgumentNotNull(edmFunction, "edmFunction"); |
|
596 |
|
|
597 |
var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters"); |
|
598 |
return returnParamsProperty == null |
|
599 |
? edmFunction.ReturnParameter |
|
600 |
: ((IEnumerable<FunctionParameter>)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault(); |
|
601 |
} |
|
602 |
|
|
603 |
public bool IsComposable(EdmFunction edmFunction) |
|
604 |
{ |
|
605 |
ArgumentNotNull(edmFunction, "edmFunction"); |
|
606 |
|
|
607 |
var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute"); |
|
608 |
return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null); |
|
609 |
} |
|
610 |
|
|
611 |
public IEnumerable<FunctionImportParameter> GetParameters(EdmFunction edmFunction) |
|
612 |
{ |
|
613 |
return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); |
|
614 |
} |
|
615 |
|
|
616 |
public TypeUsage GetReturnType(EdmFunction edmFunction) |
|
617 |
{ |
|
618 |
var returnParam = GetReturnParameter(edmFunction); |
|
619 |
return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage); |
|
620 |
} |
|
621 |
|
|
622 |
public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption) |
|
623 |
{ |
|
624 |
var returnType = GetReturnType(edmFunction); |
|
625 |
return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType; |
|
626 |
} |
|
627 |
} |
|
628 |
|
|
629 |
public static void ArgumentNotNull<T>(T arg, string name) where T : class |
|
630 |
{ |
|
631 |
if (arg == null) |
|
632 |
{ |
|
633 |
throw new ArgumentNullException(name); |
|
634 |
} |
|
635 |
} |
|
636 |
#> |
ColorList/ModelMarkus.Designer.cs | ||
---|---|---|
1 |
// 모델 'D:\Source\Repos\MARKUS\ColorList\ModelMarkus.edmx'에 대해 T4 코드 생성이 사용됩니다. |
|
2 |
// 레거시 코드 생성을 사용하려면 '코드 생성 전략' 디자이너 속성의 값을 |
|
3 |
// 'Legacy ObjectContext'로 변경하십시오. 이 속성은 모델이 디자이너에서 열릴 때 |
|
4 |
// 속성 창에서 사용할 수 있습니다. |
|
5 |
|
|
6 |
// 컨텍스트 및 엔터티 클래스가 생성되지 않은 경우 빈 모델을 만들었기 때문일 수도 있지만 |
|
7 |
// 사용할 Entity Framework 버전을 선택하지 않았기 때문일 수도 있습니다. 모델에 맞는 컨텍스트 클래스 및 |
|
8 |
// 엔터티 클래스를 생성하려면 디자이너에서 모델을 열고 디자이너 화면에서 마우스 오른쪽 단추를 클릭한 |
|
9 |
// 다음 '데이터베이스에서 모델 업데이트...', '모델에서 데이터베이스 생성...' 또는 '코드 생성 항목 추가...'를 |
|
10 |
// 선택하십시오. |
ColorList/ModelMarkus.cs | ||
---|---|---|
1 |
//------------------------------------------------------------------------------ |
|
2 |
// <auto-generated> |
|
3 |
// 이 코드는 템플릿에서 생성되었습니다. |
|
4 |
// |
|
5 |
// 이 파일을 수동으로 변경하면 응용 프로그램에서 예기치 않은 동작이 발생할 수 있습니다. |
|
6 |
// 이 파일을 수동으로 변경하면 코드가 다시 생성될 때 변경 내용을 덮어씁니다. |
|
7 |
// </auto-generated> |
|
8 |
//------------------------------------------------------------------------------ |
|
9 |
|
ColorList/ModelMarkus.edmx | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"> |
|
3 |
<!-- EF Runtime content --> |
|
4 |
<edmx:Runtime> |
|
5 |
<!-- SSDL content --> |
|
6 |
<edmx:StorageModels> |
|
7 |
<Schema Namespace="markusModel.Store" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"> |
|
8 |
<EntityType Name="PROPERTIES"> |
|
9 |
<Key> |
|
10 |
<PropertyRef Name="ID" /> |
|
11 |
</Key> |
|
12 |
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" /> |
|
13 |
<Property Name="TYPE" Type="nvarchar" MaxLength="50" Nullable="false" /> |
|
14 |
<Property Name="PROPERTY" Type="nvarchar" MaxLength="100" Nullable="false" /> |
|
15 |
<Property Name="VALUE" Type="varchar(max)" Nullable="false" /> |
|
16 |
</EntityType> |
|
17 |
<EntityContainer Name="markusModelStoreContainer"> |
|
18 |
<EntitySet Name="PROPERTIES" EntityType="Self.PROPERTIES" Schema="dbo" store:Type="Tables" /> |
|
19 |
</EntityContainer> |
|
20 |
</Schema> |
|
21 |
</edmx:StorageModels> |
|
22 |
<!-- CSDL content --> |
|
23 |
<edmx:ConceptualModels> |
|
24 |
<Schema Namespace="markusModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm"> |
|
25 |
<EntityType Name="PROPERTIES"> |
|
26 |
<Key> |
|
27 |
<PropertyRef Name="ID" /> |
|
28 |
</Key> |
|
29 |
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /> |
|
30 |
<Property Name="TYPE" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" /> |
|
31 |
<Property Name="PROPERTY" Type="String" MaxLength="100" FixedLength="false" Unicode="true" Nullable="false" /> |
|
32 |
<Property Name="VALUE" Type="String" MaxLength="Max" FixedLength="false" Unicode="false" Nullable="false" /> |
|
33 |
</EntityType> |
|
34 |
<EntityContainer Name="markusEntities" annotation:LazyLoadingEnabled="true"> |
|
35 |
<EntitySet Name="PROPERTIES" EntityType="Self.PROPERTIES" /> |
|
36 |
</EntityContainer> |
|
37 |
</Schema> |
|
38 |
</edmx:ConceptualModels> |
|
39 |
<!-- C-S mapping content --> |
|
40 |
<edmx:Mappings> |
|
41 |
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs"> |
|
42 |
<EntityContainerMapping StorageEntityContainer="markusModelStoreContainer" CdmEntityContainer="markusEntities"> |
|
43 |
<EntitySetMapping Name="PROPERTIES"> |
|
44 |
<EntityTypeMapping TypeName="markusModel.PROPERTIES"> |
|
45 |
<MappingFragment StoreEntitySet="PROPERTIES"> |
|
46 |
<ScalarProperty Name="ID" ColumnName="ID" /> |
|
47 |
<ScalarProperty Name="TYPE" ColumnName="TYPE" /> |
|
48 |
<ScalarProperty Name="PROPERTY" ColumnName="PROPERTY" /> |
|
49 |
<ScalarProperty Name="VALUE" ColumnName="VALUE" /> |
|
50 |
</MappingFragment> |
|
51 |
</EntityTypeMapping> |
|
52 |
</EntitySetMapping> |
|
53 |
</EntityContainerMapping> |
|
54 |
</Mapping> |
|
55 |
</edmx:Mappings> |
|
56 |
</edmx:Runtime> |
|
57 |
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> |
|
58 |
<Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx"> |
|
59 |
<Connection> |
|
60 |
<DesignerInfoPropertySet> |
|
61 |
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /> |
|
62 |
</DesignerInfoPropertySet> |
|
63 |
</Connection> |
|
64 |
<Options> |
|
65 |
<DesignerInfoPropertySet> |
|
66 |
<DesignerProperty Name="ValidateOnBuild" Value="true" /> |
|
67 |
<DesignerProperty Name="EnablePluralization" Value="false" /> |
|
68 |
<DesignerProperty Name="IncludeForeignKeysInModel" Value="true" /> |
|
69 |
<DesignerProperty Name="UseLegacyProvider" Value="false" /> |
|
70 |
<DesignerProperty Name="CodeGenerationStrategy" Value="없음" /> |
|
71 |
</DesignerInfoPropertySet> |
|
72 |
</Options> |
|
73 |
<!-- Diagram content (shape and connector positions) --> |
|
74 |
<Diagrams></Diagrams> |
|
75 |
</Designer> |
|
76 |
</edmx:Edmx> |
ColorList/ModelMarkus.edmx.diagram | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"> |
|
3 |
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> |
|
4 |
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx"> |
|
5 |
<!-- Diagram content (shape and connector positions) --> |
|
6 |
<edmx:Diagrams> |
|
7 |
<Diagram DiagramId="dfd82d7b4582489a96da29feb9d4fd95" Name="Diagram1"> |
|
8 |
<EntityTypeShape EntityType="markusModel.PROPERTIES" Width="1.5" PointX="0.75" PointY="0.75" IsExpanded="true" /> |
|
9 |
</Diagram> |
|
10 |
</edmx:Diagrams> |
|
11 |
</edmx:Designer> |
|
12 |
</edmx:Edmx> |
ColorList/ModelMarkus.tt | ||
---|---|---|
1 |
<#@ template language="C#" debug="false" hostspecific="true"#> |
|
2 |
<#@ include file="EF6.Utility.CS.ttinclude"#><#@ |
|
3 |
output extension=".cs"#><# |
|
4 |
|
|
5 |
const string inputFile = @"ModelMarkus.edmx"; |
|
6 |
var textTransform = DynamicTextTransformation.Create(this); |
|
7 |
var code = new CodeGenerationTools(this); |
|
8 |
var ef = new MetadataTools(this); |
|
9 |
var typeMapper = new TypeMapper(code, ef, textTransform.Errors); |
|
10 |
var fileManager = EntityFrameworkTemplateFileManager.Create(this); |
|
11 |
var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile); |
|
12 |
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef); |
|
13 |
|
|
14 |
if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile)) |
|
15 |
{ |
|
16 |
return string.Empty; |
|
17 |
} |
|
18 |
|
|
19 |
WriteHeader(codeStringGenerator, fileManager); |
|
20 |
|
|
21 |
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection)) |
|
22 |
{ |
|
23 |
fileManager.StartNewFile(entity.Name + ".cs"); |
|
24 |
BeginNamespace(code); |
|
25 |
#> |
|
26 |
<#=codeStringGenerator.UsingDirectives(inHeader: false)#> |
|
27 |
<#=codeStringGenerator.EntityClassOpening(entity)#> |
|
28 |
{ |
|
29 |
<# |
|
30 |
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity); |
|
31 |
var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity); |
|
32 |
var complexProperties = typeMapper.GetComplexProperties(entity); |
|
33 |
|
|
34 |
if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any()) |
|
35 |
{ |
|
36 |
#> |
|
37 |
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] |
|
38 |
public <#=code.Escape(entity)#>() |
|
39 |
{ |
|
40 |
<# |
|
41 |
foreach (var edmProperty in propertiesWithDefaultValues) |
|
42 |
{ |
|
43 |
#> |
|
44 |
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; |
|
45 |
<# |
|
46 |
} |
|
47 |
|
|
48 |
foreach (var navigationProperty in collectionNavigationProperties) |
|
49 |
{ |
|
50 |
#> |
|
51 |
this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>(); |
|
52 |
<# |
|
53 |
} |
|
54 |
|
|
55 |
foreach (var complexProperty in complexProperties) |
|
56 |
{ |
|
57 |
#> |
|
58 |
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); |
|
59 |
<# |
|
60 |
} |
|
61 |
#> |
|
62 |
} |
|
63 |
|
|
64 |
<# |
|
65 |
} |
|
66 |
|
|
67 |
var simpleProperties = typeMapper.GetSimpleProperties(entity); |
|
68 |
if (simpleProperties.Any()) |
|
69 |
{ |
|
70 |
foreach (var edmProperty in simpleProperties) |
|
71 |
{ |
|
72 |
#> |
|
73 |
<#=codeStringGenerator.Property(edmProperty)#> |
|
74 |
<# |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
if (complexProperties.Any()) |
|
79 |
{ |
|
80 |
#> |
|
81 |
|
|
82 |
<# |
|
83 |
foreach(var complexProperty in complexProperties) |
|
84 |
{ |
|
85 |
#> |
|
86 |
<#=codeStringGenerator.Property(complexProperty)#> |
|
87 |
<# |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
var navigationProperties = typeMapper.GetNavigationProperties(entity); |
|
92 |
if (navigationProperties.Any()) |
|
93 |
{ |
|
94 |
#> |
|
95 |
|
|
96 |
<# |
|
97 |
foreach (var navigationProperty in navigationProperties) |
|
98 |
{ |
|
99 |
if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many) |
|
100 |
{ |
|
101 |
#> |
|
102 |
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] |
|
103 |
<# |
|
104 |
} |
|
105 |
#> |
|
106 |
<#=codeStringGenerator.NavigationProperty(navigationProperty)#> |
|
107 |
<# |
|
108 |
} |
|
109 |
} |
|
110 |
#> |
|
111 |
} |
|
112 |
<# |
|
113 |
EndNamespace(code); |
|
114 |
} |
|
115 |
|
|
116 |
foreach (var complex in typeMapper.GetItemsToGenerate<ComplexType>(itemCollection)) |
|
117 |
{ |
|
118 |
fileManager.StartNewFile(complex.Name + ".cs"); |
|
119 |
BeginNamespace(code); |
|
120 |
#> |
|
121 |
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> |
|
122 |
<#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#> |
|
123 |
{ |
|
124 |
<# |
|
125 |
var complexProperties = typeMapper.GetComplexProperties(complex); |
|
126 |
var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(complex); |
|
127 |
|
|
128 |
if (propertiesWithDefaultValues.Any() || complexProperties.Any()) |
|
129 |
{ |
|
130 |
#> |
|
131 |
public <#=code.Escape(complex)#>() |
|
132 |
{ |
|
133 |
<# |
|
134 |
foreach (var edmProperty in propertiesWithDefaultValues) |
|
135 |
{ |
|
136 |
#> |
|
137 |
this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; |
|
138 |
<# |
|
139 |
} |
|
140 |
|
|
141 |
foreach (var complexProperty in complexProperties) |
|
142 |
{ |
|
143 |
#> |
|
144 |
this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); |
|
145 |
<# |
|
146 |
} |
|
147 |
#> |
|
148 |
} |
|
149 |
|
|
150 |
<# |
|
151 |
} |
|
152 |
|
|
153 |
var simpleProperties = typeMapper.GetSimpleProperties(complex); |
|
154 |
if (simpleProperties.Any()) |
|
155 |
{ |
|
156 |
foreach(var edmProperty in simpleProperties) |
|
157 |
{ |
|
158 |
#> |
|
159 |
<#=codeStringGenerator.Property(edmProperty)#> |
|
160 |
<# |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
if (complexProperties.Any()) |
|
165 |
{ |
|
166 |
#> |
|
167 |
|
|
168 |
<# |
|
169 |
foreach(var edmProperty in complexProperties) |
|
170 |
{ |
|
171 |
#> |
|
172 |
<#=codeStringGenerator.Property(edmProperty)#> |
|
173 |
<# |
|
174 |
} |
|
175 |
} |
|
176 |
#> |
|
177 |
} |
|
178 |
<# |
|
179 |
EndNamespace(code); |
|
180 |
} |
|
181 |
|
|
182 |
foreach (var enumType in typeMapper.GetEnumItemsToGenerate(itemCollection)) |
|
183 |
{ |
|
184 |
fileManager.StartNewFile(enumType.Name + ".cs"); |
|
185 |
BeginNamespace(code); |
|
186 |
#> |
|
187 |
<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> |
|
188 |
<# |
|
189 |
if (typeMapper.EnumIsFlags(enumType)) |
|
190 |
{ |
|
191 |
#> |
|
192 |
[Flags] |
|
193 |
<# |
|
194 |
} |
|
195 |
#> |
|
196 |
<#=codeStringGenerator.EnumOpening(enumType)#> |
|
197 |
{ |
|
198 |
<# |
|
199 |
var foundOne = false; |
|
200 |
|
|
201 |
foreach (MetadataItem member in typeMapper.GetEnumMembers(enumType)) |
|
202 |
{ |
|
203 |
foundOne = true; |
|
204 |
#> |
|
205 |
<#=code.Escape(typeMapper.GetEnumMemberName(member))#> = <#=typeMapper.GetEnumMemberValue(member)#>, |
|
206 |
<# |
|
207 |
} |
|
208 |
|
|
209 |
if (foundOne) |
|
210 |
{ |
|
211 |
this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1); |
|
212 |
} |
|
213 |
#> |
|
214 |
} |
|
215 |
<# |
|
216 |
EndNamespace(code); |
|
217 |
} |
|
218 |
|
내보내기 Unified diff