当前位置: 首页>>代码示例>>C#>>正文


C# ModuleDefinition.Import方法代码示例

本文整理汇总了C#中Mono.Cecil.ModuleDefinition.Import方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleDefinition.Import方法的具体用法?C# ModuleDefinition.Import怎么用?C# ModuleDefinition.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.ModuleDefinition的用法示例。


在下文中一共展示了ModuleDefinition.Import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

 internal static void Initialize(ModuleDefinition moduleDefinition)
 {
     ModuleDefinition = moduleDefinition;
     typeType = ModuleDefinition.Import(typeof(Type));
     taskType = ModuleDefinition.Import(typeof(Task));
     getTypeFromRuntimeHandleMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetTypeFromHandle"));
     typeGetMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetMethod" && x.Parameters.Count == 5));
     taskTType = ModuleDefinition.Import(typeof(Task<>));
     taskFromResult = ModuleDefinition.Import(taskType.Resolve().Methods.Single(x => x.Name == "FromResult"));
 }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:10,代码来源:CecilExtensions.cs

示例2: AddAttribute

 /// <summary>
 /// Adds the specified attribute to the specified method.
 /// </summary>
 /// <param name="field">The method to add the attribute to.</param>
 /// <param name="attribute">The attribute to add.</param>
 /// <param name="module">The module the field is defined in.</param>
 public static void AddAttribute(MethodDefinition method, Type attribute, ModuleDefinition module)
 {
     TypeDefinition tr = module.Import(attribute).Resolve();
     MethodDefinition mr = tr.Methods.First(value => value.IsConstructor);
     MethodReference rf = module.Import(mr);
     method.CustomAttributes.Add(new CustomAttribute(rf));
 }
开发者ID:hach-que,项目名称:Dx,代码行数:13,代码来源:Utility.cs

示例3: Convert

        public Either<MemberReference, PropertyReferenceContainer> Convert(IAstReference astReference, ModuleDefinition module)
        {
            var reflectedType = astReference as AstReflectedType;
            if (reflectedType != null)
                return module.Import(reflectedType.ActualType);

            var reflectedMethod = astReference as AstReflectedMethod;
            if (reflectedMethod != null)
                return module.Import(reflectedMethod.Method);

            var reflectedConstructor = astReference as AstReflectedConstructor;
            if (reflectedConstructor != null)
                return module.Import(reflectedConstructor.Constructor);

            var reflectedProperty = astReference as AstReflectedProperty;
            if (reflectedProperty != null) {
                var getMethod = reflectedProperty.Property.GetGetMethod();
                var setMethod = reflectedProperty.Property.GetSetMethod();
                return new PropertyReferenceContainer(
                    getMethod != null ? module.Import(getMethod) : null,
                    setMethod != null ? module.Import(setMethod) : null
                );
            }

            return null;
        }
开发者ID:izobr,项目名称:light,代码行数:26,代码来源:ReflectedProvider.cs

示例4: AddMixing

        public void AddMixing(ModuleDefinition targetModule)
        {
            var objectType = targetModule.Import(typeof(object)).Resolve();
            var mixesAttributeBaseType = targetModule.Import(typeof(MixesAttributeBase)).Resolve();

            var originalTypes = new List<TypeDefinition>(targetModule.Types);
            foreach (var type in originalTypes)
            {
                if(type.CustomAttributes.Any(
                    customAttribute =>
                    {
                        var attributeType = customAttribute.AttributeType.Resolve();
                        while (attributeType != objectType &&
                            attributeType != mixesAttributeBaseType &&
                            attributeType.BaseType != null)
                        {
                            attributeType = attributeType.BaseType.Resolve();
                        }
                        return attributeType == mixesAttributeBaseType;
                    }))
                {
                    this.AddIMixes(type);
                    this.AddISerializable(type);
                }
            }
        }
开发者ID:rileywhite,项目名称:Bix,代码行数:26,代码来源:MixMixer.cs

示例5: CreateCustomAttributeType

        protected override TypeDefinition CreateCustomAttributeType(ModuleDefinition targetModule)
        {
            ArgumentUtility.CheckNotNull ("targetModule", targetModule);

              var customType = new TypeDefinition (_attributeNamespace,
                                           _attributeName,
                                           TypeAttributes.Public | TypeAttributes.Class,
                                           targetModule.Import (typeof (Attribute)));

              var ctor = new MethodDefinition (
              ".ctor",
              MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName,
              targetModule.Import (typeof (void)));
              ctor.HasThis = true;

              var il = ctor.Body.GetILProcessor ();
              il.Emit (OpCodes.Ldarg_0);
              il.Emit (
              OpCodes.Call,
              targetModule.Import (typeof (Attribute).GetConstructor (BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null)));
              il.Emit (OpCodes.Ret);

              customType.Methods.Add (ctor);
              return customType;
        }
开发者ID:rubicon-oss,项目名称:AssemblyTransformer,代码行数:25,代码来源:GeneratedMarkingAttributeStrategy.cs

示例6: Hooker

        public Hooker(ModuleDefinition module)
        {
            Module = module;

            hookRegistryType = Module.Import(typeof(Hooks.HookRegistry));
            rmhType = Module.Import(typeof(System.RuntimeMethodHandle));
            onCallMethod = Module.Import(
                typeof(Hooks.HookRegistry).GetMethods()
                .First(mi => mi.Name.Contains("OnCall")));
            Module.AssemblyReferences.Add(new AssemblyNameReference("HookRegistry", new Version(1, 0, 0, 0)));
        }
开发者ID:synap5e,项目名称:UnityHook,代码行数:11,代码来源:Hooker.cs

示例7: CopyTo

        void CopyTo(CustomAttribute target, ModuleDefinition context)
        {
            foreach (var arg in ConstructorArguments)
                target.ConstructorArguments.Add(new CustomAttributeArgument(context.Import(arg.Type), arg.Value));

            foreach (var field in Fields)
                target.Fields.Add(new CustomAttributeNamedArgument(field.Name, new CustomAttributeArgument(context.Import(field.Argument.Type), field.Argument.Value)));

            foreach (var prop in Properties)
                target.Properties.Add(new CustomAttributeNamedArgument(prop.Name, new CustomAttributeArgument(context.Import(prop.Argument.Type), prop.Argument.Value)));
        }
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:11,代码来源:CustomAttribute.cs

示例8: TypeReferenceProvider

 public TypeReferenceProvider(TraceLoggingConfiguration configuration, ILoggerAdapterMetadataScopeProvider loggerAdapterMetadataScopeProvider, ModuleDefinition moduleDefinition)
 {
     _configuration = configuration;
     _moduleDefinition = moduleDefinition;
     _loggerAdapterMetadataScopeProvider = loggerAdapterMetadataScopeProvider;
     _stringArray = new Lazy<TypeReference>(() => moduleDefinition.Import((typeof(string[]))));
     _objectArray = new Lazy<TypeReference>(() => moduleDefinition.Import(typeof(object[])));
     _type = new Lazy<TypeReference>(() => moduleDefinition.Import(typeof(Type)));
     _stopwatch = new Lazy<TypeReference>(() => moduleDefinition.Import(typeof(Stopwatch)));
     _exception = new Lazy<TypeReference>(() => moduleDefinition.Import(typeof(Exception)));
 }
开发者ID:ravibpathuri,项目名称:tracer,代码行数:11,代码来源:TypeReferenceProvider.cs

示例9: Construct

        /// <summary>
        /// Constructs a type that implements the
        /// <see cref="IProxy"/> interface.
        /// </summary>
        /// <param name="module">The module that will hold the target type.</param>
        /// <param name="targetType">The type that will implement the <see cref="IProxy"/> interface.</param>
        public void Construct(ModuleDefinition module, TypeDefinition targetType)
        {
            TypeReference proxyInterfaceType = module.Import(typeof (IProxy));
            TypeReference interceptorType = module.Import(typeof (IInterceptor));

            // Implement the IProxy interface only once
            if (targetType.Interfaces.Contains(proxyInterfaceType))
                return;

            targetType.Interfaces.Add(proxyInterfaceType);
            targetType.AddProperty("Interceptor", interceptorType);
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:18,代码来源:ProxyImplementor.cs

示例10: ProcessType

    static void ProcessType(ModuleDefinition moduleDefinition, TypeDefinition type)
    {
        foreach (var toRemove in type.Properties.Where(x => x.IsCompilerGenerated()).ToList())
        {
            type.Properties.Remove(toRemove);
        }
        foreach (var toRemove in type.Methods.Where(x => x.IsCompilerGenerated() && !x.Name.StartsWith("get_") && !x.Name.StartsWith("set_")).ToList())
        {
            type.Methods.Remove(toRemove);
        }
        foreach (var toRemove in type.Fields.Where(x => x.IsCompilerGenerated()).ToList())
        {
            type.Fields.Remove(toRemove);
        }

        foreach (var property in type.Properties)
        {
            property.RemoveUnwantedAttributes();
        }

        foreach (var field in type.Fields)
        {
            field.RemoveUnwantedAttributes();
        }

        var exceptionReference = new TypeReference("System", "Exception", moduleDefinition.TypeSystem.String.Module, moduleDefinition.TypeSystem.String.Scope);
        exceptionReference = moduleDefinition.Import(exceptionReference);
        var ctor = moduleDefinition.Import(exceptionReference.Resolve().GetConstructors().First(c => !c.HasParameters));

        foreach (var method in type.Methods)
        {
            method.RemoveUnwantedAttributes();
            if (method.HasBody)
            {
                //todo: preserve a single pdb line
                var body = method.Body;
                var validSequencePoint = method.GetValidSequencePoint();
                body.Variables.Clear();
                body.ExceptionHandlers.Clear();
                body.Instructions.Clear();

                body.Instructions.Add(Instruction.Create(OpCodes.Newobj, ctor));

                var instruction = Instruction.Create(OpCodes.Throw);
                if (validSequencePoint != null)
                {
                    instruction.SequencePoint = validSequencePoint;
                }
                body.Instructions.Add(instruction);
            }
        }
    }
开发者ID:AntoineGa,项目名称:APIComparer,代码行数:52,代码来源:AssemblyCompressionTests.cs

示例11: ReferenceContainer

        public ReferenceContainer(ModuleDefinition moduleDefinition, IAssemblyResolver assemblyResolver)
        {
            var systemDefinition = assemblyResolver.Resolve("mscorlib");
            var yalfDefinition = assemblyResolver.Resolve("Yalf");
            var yalfTypes = yalfDefinition.MainModule.Types;

            var logType = yalfTypes.Single(x => x.Name == "Log");
            var iContextType = yalfTypes.Single(x => x.Name == "IContext");

            var iDisposableType = systemDefinition.MainModule.Types.Single(x => x.Name == "IDisposable");
            var exceptionType = systemDefinition.MainModule.Types.Single(x => x.Name == "Exception");

            MethodContextMethod = moduleDefinition.Import(logType.Methods.Single(m => m.Name == "MethodContext"));
            TraceExceptionMethod = moduleDefinition.Import(logType.Methods.Single(m => m.Name == "TraceException"));
            CreateRecordReturnMethod = retType => {

                var recordReturn = moduleDefinition.Import(iContextType.Methods.Single(m => m.Name == "RecordReturn"));
                if (retType.IsGenericInstance)
                {
                    return recordReturn.MakeGeneric(retType);
                }
                else
                {
                    return recordReturn.MakeGeneric(retType);
                }
            };
            DisposeMethod = moduleDefinition.Import(iDisposableType.Methods.Single(m => m.Name == "Dispose"));
            LogType = moduleDefinition.Import(logType);
            IContextType = moduleDefinition.Import(iContextType);
            ExceptionType = moduleDefinition.Import(exceptionType);
            PreserveStackTraceMethod = moduleDefinition.Import(iContextType.Methods.Single(m => m.Name == "PreserveStackTrace"));
        }
开发者ID:mdabbagh88,项目名称:YALF,代码行数:32,代码来源:ReferenceContainer.cs

示例12: ResolveGenericParameters

		public static MethodReference ResolveGenericParameters(this MethodReference self, TypeReference declaringTypeRef,
			ModuleDefinition module)
		{
			if (self == null)
				throw new ArgumentNullException(nameof(self));
			if (declaringTypeRef == null)
				throw new ArgumentNullException(nameof(declaringTypeRef));

			var reference = new MethodReference(self.Name, self.ReturnType)
			{
				DeclaringType = declaringTypeRef,
				HasThis = self.HasThis,
				ExplicitThis = self.ExplicitThis,
				CallingConvention = self.CallingConvention
			};

			foreach (var parameter in self.Parameters) {
				var p = parameter.ParameterType.IsGenericParameter ? parameter.ParameterType : module.Import(parameter.ParameterType);
				reference.Parameters.Add(new ParameterDefinition(p));
			}

			foreach (var generic_parameter in self.GenericParameters)
				reference.GenericParameters.Add(new GenericParameter(generic_parameter.Name, reference));

			return reference;
		}
开发者ID:cosullivan,项目名称:Xamarin.Forms,代码行数:26,代码来源:MethodReferenceExtensions.cs

示例13: CecilVisitor

        public CecilVisitor(AssemblyDefinition assembly, ModuleDefinition module)
        {
            _assembly = assembly;
            _module = module;

            var program = _module.Types.First(t => t.Name == "Program");
            _main = program.Methods.First(m => m.Name == "Main");

            _body = _main.Body;
            _instructions = _body.Instructions;
            _instructions.Clear();

            _objCtor = _module.Import(typeof(object).GetConstructor(new System.Type[0]));

            var systemFunctions = _module.Types.First(t => t.Name == "SystemFunctions");
            // Math methods
            _fact = systemFunctions.Methods.First(m => m.Name == "Fact");
            _max = systemFunctions.Methods.First(m => m.Name == "Max");
            _min = systemFunctions.Methods.First(m => m.Name == "Min");
            _pow = systemFunctions.Methods.First(m => m.Name == "Pow");
            // Console methods
            _printBool = systemFunctions.Methods.First(m => m.Name == "PrintBool");
            _printInt = systemFunctions.Methods.First(m => m.Name == "PrintInt");

            _userFunctions = _module.Types.First(t => t.Name == "UserFunctions");
        }
开发者ID:pomma89,项目名称:DanglingLang,代码行数:26,代码来源:CecilVisitor.cs

示例14: Clone

 public static CustomAttribute Clone(CustomAttribute custattr, ModuleDefinition context,
     IImportMapper mapper)
 {
     var ca = new CustomAttribute(context.Import(custattr.Constructor, mapper));
     custattr.CopyTo(ca, context, mapper);
     return ca;
 }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:CustomAttribute.cs

示例15: Convert

        public Either<MemberReference, PropertyReferenceContainer> Convert(IAstReference astReference, ModuleDefinition module, IReferenceProvider recursive)
        {
            if (astReference != AstVoidType.Instance)
                return null;

            return module.Import(typeof(void));
        }
开发者ID:ashmind,项目名称:light,代码行数:7,代码来源:VoidTypeProvider.cs


注:本文中的Mono.Cecil.ModuleDefinition.Import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。