示例#1
0
		public static ModuleDefinition CreateModule (string name, ModuleParameters parameters)
		{
			Mixin.CheckName (name);
			Mixin.CheckParameters (parameters);

			var module = new ModuleDefinition {
				Name = name,
				kind = parameters.Kind,
				timestamp = parameters.Timestamp ?? Mixin.GetTimestamp (),
				Runtime = parameters.Runtime,
				architecture = parameters.Architecture,
				mvid = Guid.NewGuid (),
				Attributes = ModuleAttributes.ILOnly,
				Characteristics = (ModuleCharacteristics) 0x8540,
			};

			if (parameters.AssemblyResolver != null)
				module.assembly_resolver = Disposable.NotOwned (parameters.AssemblyResolver);

			if (parameters.MetadataResolver != null)
				module.metadata_resolver = parameters.MetadataResolver;

			if (parameters.MetadataImporterProvider != null)
				module.metadata_importer = parameters.MetadataImporterProvider.GetMetadataImporter (module);

			if (parameters.ReflectionImporterProvider != null)
				module.reflection_importer = parameters.ReflectionImporterProvider.GetReflectionImporter (module);

			if (parameters.Kind != ModuleKind.NetModule) {
				var assembly = new AssemblyDefinition ();
				module.assembly = assembly;
				module.assembly.Name = CreateAssemblyName (name);
				assembly.main_module = module;
			}

			module.Types.Add (new TypeDefinition (string.Empty, "<Module>", TypeAttributes.NotPublic));

			return module;
		}
示例#2
0
文件: Import.cs 项目: zwinter/ET
        public virtual AssemblyNameReference ImportReference(SR.AssemblyName name)
        {
            Mixin.CheckName(name);

            AssemblyNameReference reference;

            if (TryGetAssemblyNameReference(name, out reference))
            {
                return(reference);
            }

            reference = new AssemblyNameReference(name.Name, name.Version)
            {
                PublicKeyToken = name.GetPublicKeyToken(),
                Culture        = name.CultureInfo.Name,
                HashAlgorithm  = (AssemblyHashAlgorithm)name.HashAlgorithm,
            };

            module.AssemblyReferences.Add(reference);

            return(reference);
        }
示例#3
0
        public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }
            if (moduleName == null)
            {
                throw new ArgumentNullException("moduleName");
            }
            Mixin.CheckParameters(parameters);
            if (parameters.Kind == ModuleKind.NetModule)
            {
                throw new ArgumentException("kind");
            }

            var assembly = ModuleDefinition.CreateModule(moduleName, parameters).Assembly;

            assembly.Name = assemblyName;

            return(assembly);
        }
示例#4
0
 public virtual FieldReference ImportReference(FieldReference field, IGenericParameterProvider context)
 {
     Mixin.CheckField(field);
     return(ImportField(field, ImportGenericContext.For(context)));
 }
示例#5
0
 public virtual TypeReference ImportReference(TypeReference type, IGenericParameterProvider context)
 {
     Mixin.CheckType(type);
     return(ImportType(type, ImportGenericContext.For(context)));
 }
示例#6
0
        public DefaultMetadataImporter(ModuleDefinition module)
        {
            Mixin.CheckModule(module);

            this.module = module;
        }
示例#7
0
        public DefaultReflectionImporter(ModuleDefinition module)
        {
            Mixin.CheckModule(module);

            this.module = module;
        }
示例#8
0
 public PointerType(TypeReference type)
     : base(type)
 {
     Mixin.CheckType(type);
     this.etype = MD.ElementType.Ptr;
 }
示例#9
0
        public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
        {
            Mixin.CheckName(name);
            Mixin.CheckParameters(parameters);

            var assembly = SearchDirectory(name, directories, parameters);

            if (assembly != null)
            {
                return(assembly);
            }

            if (name.IsRetargetable)
            {
                // if the reference is retargetable, zero it
                name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion)
                {
                    PublicKeyToken = Empty <byte> .Array,
                };
            }

#if NET_CORE
            assembly = SearchTrustedPlatformAssemblies(name, parameters);
            if (assembly != null)
            {
                return(assembly);
            }
#else
            var framework_dir  = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName);
            var framework_dirs = on_mono
                                ? new [] { framework_dir, Path.Combine(framework_dir, "Facades") }
                                : new [] { framework_dir };

            if (IsZero(name.Version))
            {
                assembly = SearchDirectory(name, framework_dirs, parameters);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            if (name.Name == "mscorlib")
            {
                assembly = GetCorlib(name, parameters);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            assembly = GetAssemblyInGac(name, parameters);
            if (assembly != null)
            {
                return(assembly);
            }

            assembly = SearchDirectory(name, framework_dirs, parameters);
            if (assembly != null)
            {
                return(assembly);
            }
#endif
            if (ResolveFailure != null)
            {
                assembly = ResolveFailure(this, name);
                if (assembly != null)
                {
                    return(assembly);
                }
            }

            throw new AssemblyResolutionException(name);
        }
示例#10
0
 public PinnedType(TypeReference type)
     : base(type)
 {
     Mixin.CheckType(type);
     this.etype = MD.ElementType.Pinned;
 }
示例#11
0
 public CustomAttributeNamedArgument(string name, CustomAttributeArgument argument)
 {
     Mixin.CheckName(name);
     this.name     = name;
     this.argument = argument;
 }
示例#12
0
 public CustomAttributeArgument(TypeReference type, object value)
 {
     Mixin.CheckType(type);
     this.type  = type;
     this.value = value;
 }
示例#13
0
        public TypeDefinition GetType(string @namespace, string name)
        {
            Mixin.CheckName(name);

            return(((TypeDefinitionCollection)this.Types).GetType(@namespace ?? string.Empty, name));
        }
示例#14
0
        static Stream GetFileStream(string fileName, FileMode mode, FileAccess access, FileShare share)
        {
            Mixin.CheckFileName(fileName);

            return(new FileStream(fileName, mode, access, share));
        }
示例#15
0
		public void Write (string fileName, WriterParameters parameters)
		{
			Mixin.CheckParameters (parameters);
			var file = GetFileStream (fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
			ModuleWriter.WriteModule (this, Disposable.Owned (file), parameters);
		}
示例#16
0
 public virtual MethodReference ImportReference(MethodReference method, IGenericParameterProvider context)
 {
     Mixin.CheckMethod(method);
     return(ImportMethod(method, ImportGenericContext.For(context)));
 }
示例#17
0
 protected EventReference(string name, TypeReference eventType)
     : base(name)
 {
     Mixin.CheckType(eventType, Mixin.Argument.eventType);
     event_type = eventType;
 }
示例#18
0
 public SentinelType(TypeReference type)
     : base(type)
 {
     Mixin.CheckType(type);
     this.etype = MD.ElementType.Sentinel;
 }
示例#19
0
 public ByReferenceType(TypeReference type)
     : base(type)
 {
     Mixin.CheckType(type);
     this.etype = MD.ElementType.ByRef;
 }
示例#20
0
文件: ArrayType.cs 项目: zwinter/ET
 public ArrayType(TypeReference type)
     : base(type)
 {
     Mixin.CheckType(type);
     this.etype = MD.ElementType.Array;
 }