Skip to content

Commit f84b13b

Browse files
author
bumbaram
committed
First version
0 parents  commit f84b13b

File tree

7 files changed

+303
-0
lines changed

7 files changed

+303
-0
lines changed

CommonLibraries.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonLibraries", "CommonLibraries\CommonLibraries.csproj", "{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

CommonLibraries.v11.suo

58 KB
Binary file not shown.

CommonLibraries/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/bin/*
2+
/obj/*
3+
*.pdb
4+
*.xap
5+
*.log

CommonLibraries/ClassProvider.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Reflection;
5+
using System.Reflection.Emit;
6+
7+
8+
9+
namespace CommonLibraries
10+
{
11+
12+
public class ParentClass : INotifyPropertyChanged, INotifyDataErrorInfo
13+
{
14+
#region Property changed
15+
public event PropertyChangedEventHandler PropertyChanged;
16+
public void Notify(string property)
17+
{
18+
if (PropertyChanged != null)
19+
{
20+
PropertyChanged(this, new PropertyChangedEventArgs(property));
21+
}
22+
}
23+
#endregion
24+
25+
26+
27+
#region Error changed
28+
29+
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
30+
31+
public System.Collections.IEnumerable GetErrors(string propertyName)
32+
{
33+
return new string[] { "", };
34+
}
35+
36+
public bool HasErrors
37+
{
38+
get { return false; }
39+
}
40+
41+
#endregion
42+
}
43+
44+
public class ClassProvider
45+
{
46+
/// <summary>
47+
///
48+
/// </summary>
49+
/// <param name="properties">a collection of property name/property type keyvaluespairs.</param>
50+
/// <param name="name">name of class</param>
51+
/// <param name="suppressExceptions">can class returns an exeption, or null(default)</param>
52+
public ClassProvider(Dictionary<string, Type> properties, string name, bool suppressExceptions = true)
53+
{
54+
if (properties == null ||
55+
String.IsNullOrWhiteSpace(name))
56+
throw new Exception("Wrong parameters");
57+
58+
this.properties = properties;
59+
this.className = name;
60+
this.suppressExceptions = suppressExceptions;
61+
}
62+
63+
/// <summary>
64+
/// Create class with name above and numbers of public properties
65+
/// wich support Inotifypropertychanged interface
66+
/// </summary>
67+
/// <returns>returns type of the created class or null if an exception was throwed</returns>
68+
public Type CreateClass()
69+
{
70+
string assemblyName = "AddedAssembly";
71+
72+
try
73+
{
74+
AppDomain domain = AppDomain.CurrentDomain;
75+
AssemblyName newAssembly = new AssemblyName(assemblyName);
76+
AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(newAssembly, AssemblyBuilderAccess.Run);
77+
78+
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(newAssembly.Name);
79+
80+
TypeBuilder newType = moduleBuilder.DefineType(className, TypeAttributes.Public, typeof(ParentClass));
81+
82+
// for notify property changed interface
83+
MethodInfo notify = (typeof(ParentClass)).GetMethod("Notify");
84+
// nessesary arguments for public property
85+
MethodAttributes atrs = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
86+
87+
foreach (var property in properties)
88+
{
89+
// create private field
90+
FieldBuilder field = newType.DefineField("_" + property.Key, property.Value, FieldAttributes.Private);
91+
// create public property
92+
PropertyBuilder prop = newType.DefineProperty(property.Key, PropertyAttributes.HasDefault, property.Value, null);
93+
94+
// Create get method for the public property
95+
MethodBuilder getMethod = newType.DefineMethod("get_" + property.Key, atrs, property.Value, Type.EmptyTypes);
96+
97+
ILGenerator il = getMethod.GetILGenerator();
98+
il.Emit(OpCodes.Ldarg_0);
99+
il.Emit(OpCodes.Ldfld, field);
100+
il.Emit(OpCodes.Ret);
101+
102+
103+
// Create set method for the public property
104+
MethodBuilder setMethod = newType.DefineMethod("set_" + property.Key, atrs, null, new Type[] { property.Value, });
105+
106+
il = setMethod.GetILGenerator();
107+
il.Emit(OpCodes.Ldarg_0);
108+
il.Emit(OpCodes.Ldarg_1);
109+
il.Emit(OpCodes.Stfld, field);
110+
il.Emit(OpCodes.Ldarg_0); //
111+
il.Emit(OpCodes.Ldstr, property.Key); //
112+
il.EmitCall(OpCodes.Call, notify, new Type[] { typeof(string), }); // notify method invoke
113+
il.Emit(OpCodes.Ret);
114+
115+
//
116+
prop.SetGetMethod(getMethod);
117+
prop.SetSetMethod(setMethod);
118+
}
119+
120+
return newType.CreateType();
121+
}
122+
catch (Exception ex)
123+
{
124+
if (suppressExceptions)
125+
return null;
126+
else
127+
throw ex;
128+
}
129+
}
130+
131+
private Dictionary<string, Type> properties;
132+
private string className;
133+
private bool suppressExceptions = true;
134+
}
135+
}
136+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.50727</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{CF23E190-E17D-4A8F-BC4D-B94AE20F8ABD}</ProjectGuid>
9+
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>CommonLibraries</RootNamespace>
13+
<AssemblyName>CommonLibraries</AssemblyName>
14+
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
15+
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
16+
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
17+
<SilverlightApplication>false</SilverlightApplication>
18+
<ValidateXaml>true</ValidateXaml>
19+
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
20+
</PropertyGroup>
21+
<!-- This property group is only here to support building this project using the
22+
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
23+
to set the TargetFrameworkVersion to v3.5 -->
24+
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
25+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
28+
<DebugSymbols>true</DebugSymbols>
29+
<DebugType>full</DebugType>
30+
<Optimize>false</Optimize>
31+
<OutputPath>Bin\Debug</OutputPath>
32+
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
33+
<NoStdLib>true</NoStdLib>
34+
<NoConfig>true</NoConfig>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
39+
<DebugType>pdbonly</DebugType>
40+
<Optimize>true</Optimize>
41+
<OutputPath>Bin\Release</OutputPath>
42+
<DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
43+
<NoStdLib>true</NoStdLib>
44+
<NoConfig>true</NoConfig>
45+
<ErrorReport>prompt</ErrorReport>
46+
<WarningLevel>4</WarningLevel>
47+
</PropertyGroup>
48+
<ItemGroup>
49+
<Reference Include="mscorlib" />
50+
<Reference Include="system" />
51+
<Reference Include="System.Core">
52+
<HintPath>$(TargetFrameworkDirectory)System.Core.dll</HintPath>
53+
</Reference>
54+
<Reference Include="System.Windows" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Compile Include="ClassProvider.cs" />
58+
<Compile Include="Properties\AssemblyInfo.cs" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<WCFMetadata Include="Service References\" />
62+
</ItemGroup>
63+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
64+
<ProjectExtensions>
65+
<VisualStudio>
66+
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
67+
<SilverlightProjectProperties />
68+
</FlavorProperties>
69+
</VisualStudio>
70+
</ProjectExtensions>
71+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
72+
Other similar extension points exist, see Microsoft.Common.targets.
73+
<Target Name="BeforeBuild">
74+
</Target>
75+
<Target Name="AfterBuild">
76+
</Target>
77+
-->
78+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
6+
<SilverlightProjectProperties>
7+
<StartPageUrl>
8+
</StartPageUrl>
9+
<StartAction>DynamicPage</StartAction>
10+
<AspNetDebugging>True</AspNetDebugging>
11+
<NativeDebugging>False</NativeDebugging>
12+
<SQLDebugging>False</SQLDebugging>
13+
<ExternalProgram>
14+
</ExternalProgram>
15+
<StartExternalURL>
16+
</StartExternalURL>
17+
<StartCmdLineArguments>
18+
</StartCmdLineArguments>
19+
<StartWorkingDirectory>
20+
</StartWorkingDirectory>
21+
<ShowWebRefOnDebugPrompt>True</ShowWebRefOnDebugPrompt>
22+
<OutOfBrowserProjectToDebug>
23+
</OutOfBrowserProjectToDebug>
24+
<ShowRiaSvcsOnDebugPrompt>True</ShowRiaSvcsOnDebugPrompt>
25+
</SilverlightProjectProperties>
26+
</FlavorProperties>
27+
</VisualStudio>
28+
</ProjectExtensions>
29+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// Управление общими сведениями о сборке осуществляется с помощью
6+
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
7+
// связанные со сборкой.
8+
[assembly: AssemblyTitle("CommonLibraries")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CommonLibraries")]
13+
[assembly: AssemblyCopyright("Copyright © 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Установка значения false атрибута ComVisible делает типы этой сборки невидимыми
18+
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
19+
// COM, задайте атрибуту ComVisible значение true для требуемого типа.
20+
[assembly: ComVisible(false)]
21+
22+
// Следующий GUID служит для идентификации библиотеки типов, если этот проект видим для COM
23+
[assembly: Guid("cf23e190-e17d-4a8f-bc4d-b94ae20f8abd")]
24+
25+
// Сведения о версии сборки состоят из следующих четырех значений:
26+
//
27+
// Основной номер версии
28+
// Дополнительный номер версии
29+
// Номер построения
30+
// Редакция
31+
//
32+
// Можно задать все значения или принять номер построения и номер редакции по умолчанию,
33+
// с помощью знака "*", как показано ниже:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)