• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cecil.GenericInstanceType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



GenericInstanceType类属于Mono.Cecil命名空间,在下文中一共展示了GenericInstanceType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: MakeHostInstanceGeneric

    public static MethodReference MakeHostInstanceGeneric(this MethodReference @this, params TypeReference[] genericArguments)
    {
        var genericDeclaringType = new GenericInstanceType(@this.DeclaringType);
        foreach (var genericArgument in genericArguments)
        {
            genericDeclaringType.GenericArguments.Add(genericArgument);
        }

        var reference = new MethodReference(@this.Name, @this.ReturnType, genericDeclaringType)
        {
            HasThis = @this.HasThis,
            ExplicitThis = @this.ExplicitThis,
            CallingConvention = @this.CallingConvention
        };

        foreach (var parameter in @this.Parameters)
        {
            reference.Parameters.Add(new ParameterDefinition(parameter.ParameterType));
        }

        foreach (var genericParam in @this.GenericParameters)
        {
            reference.GenericParameters.Add(new GenericParameter(genericParam.Name, reference));
        }

        return reference;
    }
开发者ID:realm,项目名称:realm-dotnet,代码行数:27,代码来源:MethodReferenceExtensions.cs


示例2: EmitArchsInit

        private static void EmitArchsInit(MethodBody body, FieldReference archRef, Action<Instruction> emit)
        {
            var module = body.Method.Module;
              GenericInstanceType dictStrStrRef = (GenericInstanceType)archRef.FieldType;
              TypeReference dictOpenRef = dictStrStrRef.ElementType;
              GenericInstanceType iEqCompStrRef = new GenericInstanceType(module.Import(typeof(IEqualityComparer<>)));
              iEqCompStrRef.GenericArguments.Add(dictOpenRef.GenericParameters[0]);
              MethodReference dictStrStrCtor = CecilUtils.ImportInstanceMethodRef(module, dictStrStrRef, ".ctor", null, iEqCompStrRef);
              MethodReference dictAddRef = CecilUtils.ImportInstanceMethodRef(module, dictStrStrRef, "Add", null, dictOpenRef.GenericParameters[0], dictOpenRef.GenericParameters[1]);

            // Variables
              body.Variables.Add(new VariableDefinition(dictStrStrRef));
              int varIdx = body.Variables.Count - 1;
            Instruction varSt = CecilUtils.ShortestStloc(varIdx);
            Instruction varLd = CecilUtils.ShortestLdloc(varIdx);

            emit(Instruction.Create(OpCodes.Ldnull));
            emit(Instruction.Create(OpCodes.Newobj, dictStrStrCtor));
              emit(varSt.Clone());
              emit(varLd.Clone());
              emit(Instruction.Create(OpCodes.Stsfld, archRef));
              Action<string, string> emitAddPair = (k, v) =>
              {
              emit(varLd.Clone());
                emit(Instruction.Create(OpCodes.Ldstr, k));
                emit(Instruction.Create(OpCodes.Ldstr, v));
            emit(Instruction.Create(OpCodes.Callvirt, dictAddRef));
              };
              emitAddPair("x86", "Win32");
              emitAddPair("AMD64", "x64");
              emitAddPair("IA64", "Itanium");
              emitAddPair("ARM", "WinCE");
        }
开发者ID:poizan42,项目名称:SQLitePostProcess,代码行数:33,代码来源:Program.cs


示例3: CheckGenericArgument

		static bool CheckGenericArgument (GenericInstanceType git)
		{
			if ((git == null) || !git.HasGenericArguments)
				return false; // should not happen with the '`1' but...

			TypeReference arg = git.GenericArguments [0];
			switch (arg.MetadataType) {
			case MetadataType.MVar:
				return (arg.IsGenericParameter && arg.IsNamed (String.Empty, "T"));
			case MetadataType.ValueType:
				return arg.IsNamed ("System", "Decimal");
			case MetadataType.Boolean:
			case MetadataType.Byte:
			case MetadataType.Char:
			case MetadataType.Double:
			case MetadataType.Single:
			case MetadataType.Int16:
			case MetadataType.Int32:
			case MetadataType.Int64:
			case MetadataType.SByte:
			case MetadataType.UInt16:
			case MetadataType.UInt32:
			case MetadataType.UInt64:
				return true;
			default:
				return false;
			}
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:28,代码来源:PreferInterfaceConstraintOnGenericParameterForPrimitiveInterfaceRule.cs


示例4: ResolveGenericParameters

 private TypeReference ResolveGenericParameters(TypeReference typeReference)
 {
     if (typeReference.IsGenericParameter)
     {
         GenericParameter parameter = (GenericParameter) typeReference;
         return Enumerable.ElementAt<TypeReference>(this.GenericArguments, parameter.Position);
     }
     if (typeReference.IsGenericInstance)
     {
         GenericInstanceType type = (GenericInstanceType) typeReference;
         GenericInstanceType type2 = new GenericInstanceType(this.ResolveGenericParameters(type.ElementType));
         foreach (TypeReference reference2 in type.GenericArguments)
         {
             type2.GenericArguments.Add(this.ResolveGenericParameters(reference2));
         }
         return type2;
     }
     if (typeReference.IsArray)
     {
         ArrayType type3 = (ArrayType) typeReference;
         return new ArrayType(this.ResolveGenericParameters(type3.ElementType), type3.Rank);
     }
     if (typeReference.IsPointer)
     {
         return new PointerType(this.ResolveGenericParameters(((PointerType) typeReference).ElementType));
     }
     if (typeReference.IsByReference)
     {
         return new ByReferenceType(this.ResolveGenericParameters(((ByReferenceType) typeReference).ElementType));
     }
     return typeReference;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:32,代码来源:GenericFieldTypeResolver.cs


示例5: Generate

        protected override AssemblyDefinition Generate()
        {
            var assembly = AssemblyFactory.DefineAssembly(DllName, TargetRuntime.NET_2_0, AssemblyKind.Dll);

            var objectTypeRef = assembly.MainModule.Import(typeof (object));
            var module = assembly.MainModule;

            var xType = new TypeDefinition("X", "", TypeAttributes.Class, objectTypeRef);
            xType.GenericParameters.Add(new GenericParameter("T", xType));
            module.Types.Add(xType);
            xType.Module = module;

            var aType = new TypeDefinition("A", "", TypeAttributes.Class, null);
            var bType = new TypeDefinition("B", "", TypeAttributes.Class, null);

            var aBaseType = new GenericInstanceType(xType);
            aBaseType.GenericArguments.Add(bType);
            aType.BaseType = aBaseType;

            var bBaseType = new GenericInstanceType(xType);
            bBaseType.GenericArguments.Add(aType);
            bType.BaseType = bBaseType;

            module.Types.Add(aType);
            aType.Module = module;

            module.Types.Add(bType);
            bType.Module = module;

            return assembly;
        }
开发者ID:vestild,项目名称:nemerle,代码行数:31,代码来源:Cecil.MutuallyRecursiveTypes.cs


示例6: ResolveConstituentType

        public TypeReference ResolveConstituentType(TypeReference sourceType)
        {
            if (sourceType == null) throw new ArgumentNullException("sourceType");

              sourceType = Import(sourceType);

              if (sourceType is GenericParameter) {
            return _map[sourceType.Name];
              }

              {
            var sourceTypeAsGenericInstance = sourceType as GenericInstanceType;
            if (sourceTypeAsGenericInstance != null) {
              var targetType = new GenericInstanceType(sourceTypeAsGenericInstance.ElementType);
              foreach (TypeReference sourceArgument in sourceTypeAsGenericInstance.GenericArguments) {
            var targetArgument = ResolveConstituentType(sourceArgument);
            targetType.GenericArguments.Add(targetArgument);
              }
              return targetType;
            }
              }

              {
            var sourceTypeAsArray = sourceType as ArrayType;
            if (sourceTypeAsArray != null) {
              return new ArrayType(ResolveConstituentType(sourceTypeAsArray.ElementType));
            }
              }

              {
            var sourceTypeAsReference = sourceType as ByReferenceType;
            if (sourceTypeAsReference != null) {
              return new ByReferenceType(ResolveConstituentType(sourceTypeAsReference.ElementType));
            }
              }

              {
            var sourceTypeAsOptional = sourceType as OptionalModifierType;
            if (sourceTypeAsOptional != null) {
              return new OptionalModifierType(ResolveConstituentType(sourceTypeAsOptional.ElementType), ResolveConstituentType(sourceTypeAsOptional.ModifierType));
            }
              }

              {
            var sourceTypeAsRequired = sourceType as RequiredModifierType;
            if (sourceTypeAsRequired != null) {
              return new RequiredModifierType(ResolveConstituentType(sourceTypeAsRequired.ElementType), ResolveConstituentType(sourceTypeAsRequired.ModifierType));
            }
              }

              // TODO:
              //FunctionPointerType?
              //SentinelType??

              // PinnedType is never used as a parameter (TODO: or is it?)
              // PointerType never has a generic element type

              return sourceType;
        }
开发者ID:cessationoftime,项目名称:nroles,代码行数:59,代码来源:MemberResolver.cs


示例7: RecursiveGenericDepthFor

 public static int RecursiveGenericDepthFor(GenericInstanceType type)
 {
     if (type == null)
     {
         return 0;
     }
     return RecursiveGenericDepthFor(type, !type.HasGenericArguments ? 0 : 1);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:8,代码来源:GenericsUtilities.cs


示例8: AddICollectionTProxy

    private static void AddICollectionTProxy(ModuleDefinition moduleDefinition, TypeDefinition type, GenericInstanceType collectionT)
    {
        var itemType = collectionT.GenericArguments[0];
        var itemArray = itemType.MakeArrayType();

        var proxyType = CreateProxy(moduleDefinition, type);
        TypeReference proxyTypeRef = proxyType;
        if (type.HasGenericParameters)
            proxyTypeRef = proxyType.MakeGenericInstanceType(type.GenericParameters.Select(gp => new GenericParameter(gp.Position, gp.Type, gp.Module)).ToArray());

        var field = proxyType.Fields[0];
        var fieldRef = new FieldReference(field.Name, field.FieldType, proxyTypeRef);

        var countProperty = type.Properties.First(p => p.Name == "Count" || p.Name == "System.Collections.ICollection.Count");
        MethodReference countMethod = countProperty.GetMethod;
        MethodReference copyToMethod = type.Methods.First(p => p.Name == "CopyTo" || p.Name == "System.Collections.ICollection.CopyTo");

        if (type.HasGenericParameters)
        {
            countMethod = countMethod.MakeHostInstanceGeneric(type.GenericParameters.Select(gp => new GenericParameter(gp.Position, gp.Type, gp.Module)).ToArray());
            copyToMethod = copyToMethod.MakeHostInstanceGeneric(type.GenericParameters.Select(gp => new GenericParameter(gp.Position, gp.Type, gp.Module)).ToArray());
        }

        var getMethod = new MethodDefinition("get_Items", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, itemArray);
        var getMethodBody = getMethod.Body;

        var localItems = new VariableDefinition("items", itemArray);
        getMethodBody.Variables.Add(localItems);

        getMethodBody.SimplifyMacros();
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldfld, fieldRef));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Callvirt, countMethod));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Newarr, itemType));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Stloc, localItems));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldfld, fieldRef));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldloc, localItems));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldloc, localItems));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldlen));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Conv_I4));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Callvirt, copyToMethod));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ldloc, localItems));
        getMethodBody.Instructions.Add(Instruction.Create(OpCodes.Ret));
        getMethodBody.InitLocals = true;
        getMethodBody.OptimizeMacros();

        proxyType.Methods.Add(getMethod);

        var property = new PropertyDefinition("Items", PropertyAttributes.None, itemArray);
        property.GetMethod = getMethod;
        var debuggerBrowsableAttribute = new CustomAttribute(ReferenceFinder.DebuggerBrowsableAttributeCtor);
        debuggerBrowsableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(ReferenceFinder.DebuggerBrowsableStateType, DebuggerBrowsableState.RootHidden));
        property.CustomAttributes.Add(debuggerBrowsableAttribute);
        proxyType.Properties.Add(property);

        AddDebuggerTypeProxyAttribute(type, proxyType);
    }
开发者ID:RobertGiesecke,项目名称:Visualize,代码行数:58,代码来源:DebuggerTypeProxyInjector.cs


示例9: GetGenericInstanceType

 private static GenericInstanceType GetGenericInstanceType(TypeDefinition type, Collection<GenericParameter> parameters)
 {
     var genericInstanceType = new GenericInstanceType(type);
     foreach (var genericParameter in parameters)
     {
         genericInstanceType.GenericArguments.Add(genericParameter);
     }
     return genericInstanceType;
 }
开发者ID:kzaikin,项目名称:Equals,代码行数:9,代码来源:PropertyDefinitionExtensions.cs


示例10: NewGenericInstanceTypeWithArgumentsFrom

		private static GenericInstanceType NewGenericInstanceTypeWithArgumentsFrom(TypeReference referenceType, GenericInstanceType argumentSource)
		{
			GenericInstanceType replacementTypeReference = new GenericInstanceType(referenceType);
			foreach (TypeReference argument in argumentSource.GenericArguments)
			{
				replacementTypeReference.GenericArguments.Add(argument);
			}
			return replacementTypeReference;
		}
开发者ID:superyfwy,项目名称:db4o,代码行数:9,代码来源:TACollectionsStep.cs


示例11: AsMethodOfGenericTypeInstance

 public static MethodReference AsMethodOfGenericTypeInstance(this MethodDefinition methodDef, GenericInstanceType genericInstanceType)
 {
     if (!genericInstanceType.ElementType.IsEqualTo(methodDef.DeclaringType)) {
         throw new ArgumentException("The generic instance type doesn't match the method's declaring type.", "genericInstanceType");
     }
     var methodRef = methodDef.Clone();
     methodRef.DeclaringType = genericInstanceType;
     return methodRef;
 }
开发者ID:LoveDuckie,项目名称:Piranha,代码行数:9,代码来源:CecilExtensions.cs


示例12: MemberResolver

 public MemberResolver(TypeReference target, ModuleDefinition targetModule = null)
 {
     if (target == null) throw new ArgumentNullException("target");
       Target = target;
       Module = targetModule ?? Target.Module;
       Source = Target.Resolve();
       TargetWithArguments = Target as GenericInstanceType;
       _map = new GenericParametersMap(Source, TargetWithArguments);
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:9,代码来源:MemberResolver.cs


示例13: ConstructGenericType

 private static GenericInstanceType ConstructGenericType(GenericContext context, TypeDefinition typeDefinition, IEnumerable<TypeReference> genericArguments)
 {
     GenericInstanceType type = new GenericInstanceType(typeDefinition);
     foreach (TypeReference reference in genericArguments)
     {
         type.GenericArguments.Add(InflateType(context, reference));
     }
     return type;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:9,代码来源:Inflater.cs


示例14: GenericReferenceFor

 private static TypeReference GenericReferenceFor(TypeReference type)
 {
     var instance = new GenericInstanceType(type);
     foreach (var param in type.GenericParameters)
     {
         instance.GenericArguments.Add(param);
     }
     return instance;
 }
开发者ID:masroore,项目名称:db4o,代码行数:9,代码来源:MethodEmitter.cs


示例15: CreateNewObjectMethod

        public bool CreateNewObjectMethod(AssemblyDefinition assembly, 
                                        MethodDefinition templateMethod, 
                                        IAssemblyTracker tracker, 
                                        INewTransformerInfoWrapper infoWrapper)
        {
            MethodDefinition factoryMethod = null;
              if ((factoryMethod = infoWrapper.GetFactoryMethod (templateMethod, assembly, tracker)) != null)
              {
            if (factoryMethod.GenericParameters.Count != 1 || factoryMethod.Parameters.Count != 1 || !factoryMethod.IsStatic)
              throw new ArgumentException ("Factory method to create object does not have correct signature [public static T Create<T> (ParamList)]");

            TypeReference returnType = templateMethod.DeclaringType;
            if (templateMethod.DeclaringType.HasGenericParameters)
            {
              returnType = new GenericInstanceType (templateMethod.DeclaringType);
              foreach (var a in templateMethod.DeclaringType.GenericParameters.ToArray ())
              {
            returnType.GenericParameters.Add (a);
            ((GenericInstanceType) returnType).GenericArguments.Add (a);
              }
            }

            var importedFactoryMethod = templateMethod.Module.Import (factoryMethod);
            var genericInstanceMethod = new GenericInstanceMethod (importedFactoryMethod);
            genericInstanceMethod.GenericArguments.Add (templateMethod.DeclaringType);

            var paramlistDef = factoryMethod.Parameters[0].ParameterType.Resolve ();
            var importedParamListCreateMethod = templateMethod.Module.Import (SearchParamListFactoryMethod (paramlistDef, templateMethod));

            if (importedParamListCreateMethod == null)
              throw new ArgumentException ("Factory method: no corresponding 'create' method could have been found. [argument count]");

            var newObjectMethod = new MethodDefinition (
                                                    infoWrapper.GetWrapperMethodName (templateMethod),
                                                    MethodAttributes.Public | MethodAttributes.Static, returnType
                                                    );
            var instructions = newObjectMethod.Body.Instructions;

            foreach (var param in templateMethod.Parameters)
            {
              newObjectMethod.Parameters.Add (param);
              instructions.Add (Instruction.Create (OpCodes.Ldarg, param));
            }

            instructions.Add(Instruction.Create (OpCodes.Call, importedParamListCreateMethod));
            instructions.Add(Instruction.Create (OpCodes.Call, genericInstanceMethod));

            instructions.Add (Instruction.Create (OpCodes.Ret));
            newObjectMethod.Body.OptimizeMacros ();

            newObjectMethod.IsHideBySig = true;
            templateMethod.DeclaringType.Methods.Add (newObjectMethod);
            return true;
              }
              return false;
        }
开发者ID:rubicon-oss,项目名称:AssemblyTransformer,代码行数:56,代码来源:ILCodeRewriter.cs


示例16: GetGenericInstantiationIfGeneric

 public static TypeReference GetGenericInstantiationIfGeneric(this TypeReference definition)
 {
     if (!definition.HasGenericParameters) return definition;
     var instType = new GenericInstanceType(definition);
     foreach (var parameter in definition.GenericParameters)
     {
         instType.GenericArguments.Add(parameter);
     }
     return instType;
 }
开发者ID:ravibpathuri,项目名称:tracer,代码行数:10,代码来源:CecilExtensions.cs


示例17: MakeGenericType

        public static TypeReference MakeGenericType(this TypeReference self, params TypeReference[] arguments)
        {
            if (self.GenericParameters.Count != arguments.Length)
                throw new ArgumentException();

            var instance = new GenericInstanceType(self);
            foreach (var argument in arguments)
                instance.GenericArguments.Add(argument);

            return instance;
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:11,代码来源:CecilExtensions.cs


示例18: IsEqualTo

 public static bool IsEqualTo(this GenericInstanceType a, GenericInstanceType b)
 {
     if (a.GenericArguments.Count != b.GenericArguments.Count) {
         return false;
     }
     for (int i = 0; i < a.GenericArguments.Count; i++) {
         if (!IsEqualTo(a.GenericArguments[i], b.GenericArguments[i])) {
             return false;
         }
     }
     return true;
 }
开发者ID:arcanedreams,项目名称:Piranha,代码行数:12,代码来源:ComparisonExtensions.cs


示例19: Bind

        public static MethodReference Bind(this MethodReference method, GenericInstanceType genericType)
        {
            var reference = new MethodReference(method.Name, method.ReturnType, genericType);
            reference.HasThis = method.HasThis;
            reference.ExplicitThis = method.ExplicitThis;
            reference.CallingConvention = method.CallingConvention;

            foreach (var parameter in method.Parameters)
                reference.Parameters.Add(new ParameterDefinition(parameter.ParameterType));

            return reference;
        }
开发者ID:kswoll,项目名称:sexy-react,代码行数:12,代码来源:CecilExtensions.cs


示例20: MakeGenericType

 public static TypeReference MakeGenericType(TypeReference self, params TypeReference[] arguments)
 {
     if (self.GenericParameters.Count != arguments.Length)
     {
         throw new ArgumentException();
     }
     GenericInstanceType type = new GenericInstanceType(self);
     foreach (TypeReference reference in arguments)
     {
         type.GenericArguments.Add(reference);
     }
     return type;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:13,代码来源:Helpers.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cecil.GenericParameter类代码示例发布时间:2022-05-26
下一篇:
C# Cecil.GenericInstanceMethod类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap