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; }
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); }
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); }
public virtual FieldReference ImportReference(FieldReference field, IGenericParameterProvider context) { Mixin.CheckField(field); return(ImportField(field, ImportGenericContext.For(context))); }
public virtual TypeReference ImportReference(TypeReference type, IGenericParameterProvider context) { Mixin.CheckType(type); return(ImportType(type, ImportGenericContext.For(context))); }
public DefaultMetadataImporter(ModuleDefinition module) { Mixin.CheckModule(module); this.module = module; }
public DefaultReflectionImporter(ModuleDefinition module) { Mixin.CheckModule(module); this.module = module; }
public PointerType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Ptr; }
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); }
public PinnedType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Pinned; }
public CustomAttributeNamedArgument(string name, CustomAttributeArgument argument) { Mixin.CheckName(name); this.name = name; this.argument = argument; }
public CustomAttributeArgument(TypeReference type, object value) { Mixin.CheckType(type); this.type = type; this.value = value; }
public TypeDefinition GetType(string @namespace, string name) { Mixin.CheckName(name); return(((TypeDefinitionCollection)this.Types).GetType(@namespace ?? string.Empty, name)); }
static Stream GetFileStream(string fileName, FileMode mode, FileAccess access, FileShare share) { Mixin.CheckFileName(fileName); return(new FileStream(fileName, mode, access, share)); }
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); }
public virtual MethodReference ImportReference(MethodReference method, IGenericParameterProvider context) { Mixin.CheckMethod(method); return(ImportMethod(method, ImportGenericContext.For(context))); }
protected EventReference(string name, TypeReference eventType) : base(name) { Mixin.CheckType(eventType, Mixin.Argument.eventType); event_type = eventType; }
public SentinelType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Sentinel; }
public ByReferenceType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.ByRef; }
public ArrayType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Array; }