當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。