예제 #1
0
        private static AssemblyBuilder CreateAssemblyForTypeLib(object typeLib, string asmFileName, AssemblyName asmName, bool bPrimaryInteropAssembly, bool bReflectionOnly, bool bNoDefineVersionResource)
        {
            AppDomain domain = Thread.GetDomain();
            string    text   = null;

            if (asmFileName != null)
            {
                text = Path.GetDirectoryName(asmFileName);
                if (string.IsNullOrEmpty(text))
                {
                    text = null;
                }
            }
            AssemblyBuilderAccess access;

            if (bReflectionOnly)
            {
                access = AssemblyBuilderAccess.ReflectionOnly;
            }
            else
            {
                access = AssemblyBuilderAccess.RunAndSave;
            }
            List <CustomAttributeBuilder> list = new List <CustomAttributeBuilder>();
            ConstructorInfo constructor        = typeof(SecurityRulesAttribute).GetConstructor(new Type[]
            {
                typeof(SecurityRuleSet)
            });
            CustomAttributeBuilder item = new CustomAttributeBuilder(constructor, new object[]
            {
                SecurityRuleSet.Level2
            });

            list.Add(item);
            AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(asmName, access, text, false, list);

            TypeLibConverter.SetGuidAttributeOnAssembly(assemblyBuilder, typeLib);
            TypeLibConverter.SetImportedFromTypeLibAttrOnAssembly(assemblyBuilder, typeLib);
            if (bNoDefineVersionResource)
            {
                TypeLibConverter.SetTypeLibVersionAttribute(assemblyBuilder, typeLib);
            }
            else
            {
                TypeLibConverter.SetVersionInformation(assemblyBuilder, typeLib, asmName);
            }
            if (bPrimaryInteropAssembly)
            {
                TypeLibConverter.SetPIAAttributeOnAssembly(assemblyBuilder, typeLib);
            }
            return(assemblyBuilder);
        }
예제 #2
0
        private static AssemblyBuilder CreateAssemblyForTypeLib(object typeLib, string asmFileName, AssemblyName asmName, bool bPrimaryInteropAssembly, bool bReflectionOnly, bool bNoDefineVersionResource)
        {
            AppDomain domain = Thread.GetDomain();
            string    dir    = (string)null;

            if (asmFileName != null)
            {
                dir = Path.GetDirectoryName(asmFileName);
                if (string.IsNullOrEmpty(dir))
                {
                    dir = (string)null;
                }
            }
            AssemblyBuilderAccess access  = !bReflectionOnly ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.ReflectionOnly;
            AssemblyBuilder       asmBldr = domain.DefineDynamicAssembly(asmName, access, dir, false, (System.Collections.Generic.IEnumerable <CustomAttributeBuilder>) new List <CustomAttributeBuilder>()
            {
                new CustomAttributeBuilder(typeof(SecurityRulesAttribute).GetConstructor(new Type[1] {
                    typeof(SecurityRuleSet)
                }), new object[1] {
                    (object)SecurityRuleSet.Level2
                })
            });

            TypeLibConverter.SetGuidAttributeOnAssembly(asmBldr, typeLib);
            TypeLibConverter.SetImportedFromTypeLibAttrOnAssembly(asmBldr, typeLib);
            if (bNoDefineVersionResource)
            {
                TypeLibConverter.SetTypeLibVersionAttribute(asmBldr, typeLib);
            }
            else
            {
                TypeLibConverter.SetVersionInformation(asmBldr, typeLib, asmName);
            }
            if (bPrimaryInteropAssembly)
            {
                TypeLibConverter.SetPIAAttributeOnAssembly(asmBldr, typeLib);
            }
            return(asmBldr);
        }