//创建动态程序集,并保存[AssemblyBuilderAccess.RunAndSave]
- AssemblyName asmName = new AssemblyName("NXDO.DyORM." + className);
- asmName.Version = new Version(NxContext.CurrentVersion);
- AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave,"Dlls");
//我希望保存输出的程序集带有版本/描述等信息,则代码如下
- string strOrmDllTitleAttribute = "ORM动态程序集";
- if (this.IsIxDataEntityChildren) strOrmDllTitleAttribute += ",实体类映射";
- else if (this.IsIxDataSPChildren) strOrmDllTitleAttribute += ",存储映射";
- else strOrmDllTitleAttribute += ",部分字段映射";
- CustomAttributeBuilder attr1 = new CustomAttributeBuilder(typeof(AssemblyTitleAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { strOrmDllTitleAttribute });
- CustomAttributeBuilder attr2 = new CustomAttributeBuilder(typeof(AssemblyDescriptionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { classT.Name + "接口实现类" });
- CustomAttributeBuilder attr3 = new CustomAttributeBuilder(typeof(AssemblyConfigurationAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "" });
- CustomAttributeBuilder attr4 = new CustomAttributeBuilder(typeof(AssemblyCompanyAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "ITBabySoftware" });
- CustomAttributeBuilder attr5 = new CustomAttributeBuilder(typeof(AssemblyProductAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "NXDO.Data.DyORM." + classT.Name });
- CustomAttributeBuilder attr6 = new CustomAttributeBuilder(typeof(AssemblyCopyrightAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "ITBabySoftware @Copyright2005-" + System.DateTime.Now.Year.ToString() });
- CustomAttributeBuilder attr7 = new CustomAttributeBuilder(typeof(AssemblyTrademarkAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "http://blog.csdn.net/javasuki" });
- CustomAttributeBuilder attr8 = new CustomAttributeBuilder(typeof(AssemblyCultureAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "" });
- CustomAttributeBuilder attr9 = new CustomAttributeBuilder(typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { NxContext.CurrentVersion });
- CustomAttributeBuilder attr10 = new CustomAttributeBuilder(typeof(AssemblyFileVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { NxContext.CurrentVersion });
- assembly.SetCustomAttribute(attr1);
- assembly.SetCustomAttribute(attr2);
- assembly.SetCustomAttribute(attr3);
- assembly.SetCustomAttribute(attr4);
- assembly.SetCustomAttribute(attr5);
- assembly.SetCustomAttribute(attr6);
- assembly.SetCustomAttribute(attr7);
- assembly.SetCustomAttribute(attr8);
- assembly.SetCustomAttribute(attr9);
- assembly.SetCustomAttribute(attr10);
- assembly.DefineVersionInfoResource(); //以上程序集属性将被追加到文件信息中
图例如下:
如需转载请注明出处,http://blog.csdn.net/javasuki
联系邮件:javasuki@hotmail.com