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


C# Cecil.GenericParameter类代码示例

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


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

示例1: Resolve

        /// <summary>
        /// Resolve the given generic parameter to a generic argument.
        /// </summary>
        public TypeReference Resolve(GenericParameter gp)
        {
            var owner = gp.Owner as TypeReference;
            if (owner == null)
                return gp; // Do not resolve generic method parameters for now

            // Try to resolve the owner
            var ownerDef = owner.GetElementType().Resolve();
            if (ownerDef == null)
                return gp;

            // Try to find the owner in our map
            var map = GetTypeToGit();
            GenericInstanceType git;
            if (!map.TryGetValue(ownerDef, out git))
            {
                // No mapping found
                return gp;
            }

            // Replace with the given generic argument
            var result = git.GenericArguments[gp.Position];
            var resultAsGp = result as GenericParameter;
            return (resultAsGp != null) ? Resolve(resultAsGp) : result;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:GenericsResolver.cs

示例2: Clone

 /// <summary>
 /// Clones the specified generic parameter.
 /// </summary>
 /// <param name="genericParameter">The generic parameter.</param>
 /// <param name="methodDefinition">The method definition.</param>
 /// <returns></returns>
 public static GenericParameter Clone(this GenericParameter genericParameter, MethodDefinition methodDefinition)
 {
     var newGenericParameter = new GenericParameter(methodDefinition);
     newGenericParameter.Attributes = genericParameter.Attributes;
     newGenericParameter.Name = genericParameter.Name;
     return newGenericParameter;
 }
开发者ID:csuffyy,项目名称:MrAdvice,代码行数:13,代码来源:GenericParameterExtensions.cs

示例3: ILGenericParameter

 /// <summary>
 /// Default ctor
 /// </summary>
 public ILGenericParameter(XModule module, GenericParameter p) : 
     base(module)
 {
     this.p = p;
     constraints = new Lazy<XTypeReference[]>(()=>
         p.Constraints.Select(k=>AsTypeReference(module, k)).ToArray());
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:XBuilder.GenericParameter.cs

示例4: GetIndexOfGenericParameter

        public static int GetIndexOfGenericParameter(MethodDefinition method, GenericParameter parameter)
        {
            if (parameter.IsGenericParameter)
            {
                // Genetic parameter has origin on method?
                for (var index = 0; index < method.GenericParameters.Count; index++)
                {
                    if (method.GenericParameters[index].MetadataToken == parameter.MetadataToken)
                    {
                        return index;
                    }
                }

                // Genetic parameter has origin on declared type?
                for (var index = 0; index < method.DeclaringType.GenericParameters.Count; index++)
                {
                    if (method.DeclaringType.GenericParameters[index].MetadataToken ==
                        parameter.MetadataToken)
                    {
                        return index;
                    }
                }
            }

            throw new InvalidOperationException("Could not find generic parameter.");
        }
开发者ID:reicheltp,项目名称:website,代码行数:26,代码来源:CRefHelpers.cs

示例5: GenerateTypeA

        private TypeDefinition GenerateTypeA(AssemblyDefinition assembly)
        {
            var objType = assembly.MainModule.Import(typeof (object));

            // define base class
            var aType = new TypeDefinition("A", "", TypeAttributes.Class, objType);
            assembly.MainModule.Types.Add(aType);

            var typeParameter = new GenericParameter("T", aType);
            aType.GenericParameters.Add(typeParameter);

            var baseMethod = new MethodDefinition("Get",
                                                  MethodAttributes.Assem | MethodAttributes.Virtual |
                                                  MethodAttributes.NewSlot, typeParameter);
            aType.Methods.Add(baseMethod);
            baseMethod.DeclaringType = aType;

            var local = new VariableDefinition(typeParameter);
            baseMethod.Body.Variables.Add(local);

            var cil = baseMethod.Body.CilWorker;
            cil.Emit(OpCodes.Ldloca, local);
            cil.Emit(OpCodes.Initobj, typeParameter);
            cil.Emit(OpCodes.Ldloc, local);
            cil.Emit(OpCodes.Ret);
            return aType;
        }
开发者ID:vestild,项目名称:nemerle,代码行数:27,代码来源:Cecil.GenericBaseClassAndOverrideOfNonPublicVirtualMethod.cs

示例6: Visit

        public override TypeReference Visit(GenericParameter type)
        {
            TypeReference result;
            if (genericTypeMapping.TryGetValue(type, out result))
                return result;

            return base.Visit(type);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:8,代码来源:ResolveGenericsVisitor.cs

示例7: HandleOwnerlessInvalidILCode

 private TypeReference HandleOwnerlessInvalidILCode(GenericParameter genericParameter)
 {
     if (((genericParameter.Type == GenericParameterType.Method) && (this._typeDefinitionContext != null)) && (genericParameter.Position < this._typeDefinitionContext.GenericArguments.Count))
     {
         return this._typeDefinitionContext.GenericArguments[genericParameter.Position];
     }
     return genericParameter.Module.TypeSystem.Object;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:8,代码来源:TypeResolver.cs

示例8: GetGenericParameter

 public TypeReference GetGenericParameter(GenericParameter genericParamter, IGenericParameterProvider[] paramProviders)
 {
     #if GENERIC
     IGenericParameterProvider context = GetContext(genericParamter, paramProviders);
     return context.GenericParameters[genericParamter.Position];
     #else
     return type;
     #endif
 }
开发者ID:Cadla,项目名称:OBFSCTR,代码行数:9,代码来源:ReferenceResolver.cs

示例9: CreateConstraint

	static TypeReference CreateConstraint (string @namespace, string name, GenericParameter parameter)
	{
		return new TypeReference (
			@namespace,
			name,
			parameter.Module,
			parameter.Module.AssemblyReferences.First<AssemblyNameReference> (a => a.Name == "mscorlib"),
			false);
	}
开发者ID:ALyman,项目名称:mono.linq.expressions,代码行数:9,代码来源:patch-constraints.cs

示例10: AddConstraintsFromType

		static void AddConstraintsFromType(ITypeParameter tp, GenericParameter g)
		{
			foreach (TypeReference constraint in g.Constraints) {
				if (tp.Method != null) {
					tp.Constraints.Add(CreateType(tp.Class.ProjectContent, tp.Method, constraint));
				} else {
					tp.Constraints.Add(CreateType(tp.Class.ProjectContent, tp.Class, constraint));
				}
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:10,代码来源:CecilReader.cs

示例11: CreateGenericConstraints

    private List<GenericConstraint> CreateGenericConstraints(GenericParameter genericParameter)
    {
      List<GenericConstraint> result = null;

      if ((genericParameter.Attributes & GenericParameterAttributes.ReferenceTypeConstraint) == GenericParameterAttributes.ReferenceTypeConstraint)
      {
        result = new List<GenericConstraint>();

        result.Add(new BuiltInGenericConstraint(BuiltInGenericConstraintsTypes.Class));
      }
      else if ((genericParameter.Attributes & GenericParameterAttributes.NotNullableValueTypeConstraint) == GenericParameterAttributes.NotNullableValueTypeConstraint)
      {
        result = new List<GenericConstraint>();

        result.Add(new BuiltInGenericConstraint(BuiltInGenericConstraintsTypes.Struct));
      }

      ConstraintCollection baseOrInterfaceConstraints = genericParameter.Constraints;

      if (baseOrInterfaceConstraints != null)
      {
        if (result == null) { result = new List<GenericConstraint>(); }

        for (int i = 0; i < baseOrInterfaceConstraints.Count; i++)
        {
          TypeReference baseTypeOrInterface = baseOrInterfaceConstraints[i];

          if (baseTypeOrInterface.FullName == "System.ValueType")
          {
            continue;
          }

          if (Utils.IsGenericParameter(baseTypeOrInterface))
          {
            result.Add(new NakedTypeConstraint(baseTypeOrInterface.Name));
          }
          else
          {
            string[] readableForms = Tools.GetHumanReadableForms(baseTypeOrInterface);

            result.Add(new TypeGenericConstraint(readableForms[0]));
          }
        }
      }

      if ((genericParameter.Attributes & GenericParameterAttributes.DefaultConstructorConstraint) == GenericParameterAttributes.DefaultConstructorConstraint
       && (genericParameter.Attributes & GenericParameterAttributes.NotNullableValueTypeConstraint) == 0)
      {
        if (result == null) { result = new List<GenericConstraint>(); }

        result.Add(new BuiltInGenericConstraint(BuiltInGenericConstraintsTypes.New));
      }

      return result;
    }
开发者ID:PrintFleet,项目名称:ImmDoc.NET,代码行数:55,代码来源:MyGenericParameterInfo.cs

示例12: GenericParameterEquals

 public static bool GenericParameterEquals(GenericParameter genericParameter, GenericParameter genericParameter2)
 {
     if (genericParameter.Position != genericParameter.Position)
     {
         return false;
     }
     if (!TypeReferenceEquals(genericParameter, genericParameter2, false))
     {
         return false;
     }
     return true; // TODO: Implement this properly
 }
开发者ID:sidecut,项目名称:xaeios,代码行数:12,代码来源:ReferenceComparer.cs

示例13: CloneGenericParameterProperties

 private static void CloneGenericParameterProperties(GenericParameter genericParameter,
     GenericParameter newGenericParameter)
 {
     newGenericParameter.Attributes = genericParameter.Attributes;
     genericParameter.Constraints.ForEach(gp => newGenericParameter.Constraints.Add(gp));
     genericParameter.CustomAttributes.ForEach(ca => newGenericParameter.CustomAttributes.Add(ca));
     newGenericParameter.DeclaringType = genericParameter.DeclaringType;
     genericParameter.GenericParameters.ForEach(gp => newGenericParameter.GenericParameters.Add(gp));
     newGenericParameter.HasDefaultConstructorConstraint = genericParameter.HasDefaultConstructorConstraint;
     newGenericParameter.IsContravariant = genericParameter.IsContravariant;
     newGenericParameter.IsCovariant = genericParameter.IsCovariant;
     newGenericParameter.IsNonVariant = genericParameter.IsNonVariant;
 }
开发者ID:fir3pho3nixx,项目名称:cryo-aop,代码行数:13,代码来源:MethodCloneFactory.cs

示例14: GetEnumType

 TypeReference GetEnumType(CustomAttribute attribute, GenericParameter parameter)
 {
     if (attribute.HasConstructorArguments)
     {
         var typeReference = (TypeReference) attribute.ConstructorArguments[0].Value;
         if (!typeReference.IsEnumType())
         {
             var message = $"The type '{typeReference.FullName}' is not an enum type. Only enum types are permitted in an EnumConstraintAttribute.";
             throw new WeavingException(message);
         }
         return typeReference;
     }
     return CreateConstraint("System", "Enum", parameter);
 }
开发者ID:Fody,项目名称:ExtraConstraints,代码行数:14,代码来源:GenericParameterProcessor.cs

示例15: CollectConstraints

        private static string CollectConstraints(GenericParameter param)
        {
            List<string> constraints = new List<string>();

            if (param.HasDefaultConstructorConstraint)
            {
                constraints.Add("new()");
            }

            if(param.HasReferenceTypeConstraint)
            {
                constraints.Add("class");
            }

            constraints.AddRange(param.Constraints.Select(constraint => constraint.ToString()));

            return string.Join(", ", constraints.ToArray());
        }
开发者ID:adrianoc,项目名称:BlogCode,代码行数:18,代码来源:Driver.cs


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