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

C# Cecil.GenericParameter类代码示例

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

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



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


示例16: InjectGenericParameter

        public static void InjectGenericParameter(this IGenericParameterProvider owner, GenericParameter parameter, ReferenceResolver resolver)
        {
            GenericParameter newParameter = new GenericParameter(parameter.Name, owner)
            {
                Attributes = parameter.Attributes
            };

            owner.GenericParameters.Add(newParameter);

            MetadataBuilderHelper.CopyCustomAttributes(newParameter, parameter, resolver);

            foreach (var constraint in parameter.Constraints)
            {
                if (owner is MethodReference)
                    newParameter.Constraints.Add(resolver.ReferenceType(constraint, owner, ((MethodReference)owner).DeclaringType));
                else
                    newParameter.Constraints.Add(resolver.ReferenceType(constraint, owner));
            }
        }
开发者ID:Cadla,项目名称:OBFSCTR,代码行数:19,代码来源:GenericParameterExtensions.cs


示例17: GetCallableObjectFactoryCreateMethod

        public MethodReference GetCallableObjectFactoryCreateMethod(AssemblyDefinition assemblyDef, ModuleDefinition moduleDefinition, TypeReference instantiatedType, IAssemblyTracker tracker)
        {
            var tempRef = GetOrCreateRemotionInterfacesReference (assemblyDef, moduleDefinition, tracker);

              var objectFactoryReference = new TypeReference (_objectFactoryNamespace, _objectFactoryName, moduleDefinition, tempRef);
              var paramListReference = new TypeReference (_paramListNamespace, _paramListName, moduleDefinition, tempRef);

              var createReference = new MethodReference ("Create", moduleDefinition.TypeSystem.Void, objectFactoryReference);
              var createTypeParam = new GenericParameter ("T", createReference);

              createReference.GenericParameters.Add (createTypeParam);
              createReference.ReturnType = createTypeParam;
              createReference.Parameters.Add (new ParameterDefinition (moduleDefinition.TypeSystem.Boolean));
              createReference.Parameters.Add (new ParameterDefinition (paramListReference));
              createReference.Parameters.Add (new ParameterDefinition (new ArrayType (moduleDefinition.TypeSystem.Object)));

              var instanceMethod = new GenericInstanceMethod (createReference);
              instanceMethod.GenericArguments.Add (instantiatedType);

              return instanceMethod;
        }
开发者ID:rubicon-oss,项目名称:AssemblyTransformer,代码行数:21,代码来源:MethodReferenceGeneratorWithImport.cs


示例18: Process

	static void Process (GenericParameter parameter)
	{
		if (!parameter.HasCustomAttributes)
			return;

		var attributes = parameter.CustomAttributes;
		for (int i = 0; i < attributes.Count; i++) {
			var attribute = attributes [i];
			if (IsDelegateConstraintAttribute (attribute)) {
				parameter.Attributes = GenericParameterAttributes.NonVariant;
				parameter.Constraints.Clear ();
				parameter.Constraints.Add (CreateConstraint ("System", "Delegate", parameter));
				attributes.RemoveAt (i--);
			} else if (IsEnumConstraintAttribute (attribute)) {
				parameter.Attributes = GenericParameterAttributes.NonVariant;
				parameter.Constraints.Clear ();
				parameter.Constraints.Add (CreateConstraint ("System", "Enum", parameter));
				attributes.RemoveAt (i--);
			}
		}
	}
开发者ID:ALyman,项目名称:mono.linq.expressions,代码行数:21,代码来源:patch-constraints.cs


示例19: Process

    void Process(GenericParameter parameter)
    {
        var hasDelegateConstraint = false;
        var hasEnumConstraint = false;
        var attributes = parameter.CustomAttributes;
        for (var i = 0; i < attributes.Count; i++)
        {
            var attribute = attributes[i];
            if (IsDelegateConstraintAttribute(attribute))
            {
                hasDelegateConstraint = true;
                parameter.Attributes = GenericParameterAttributes.NonVariant;
                parameter.Constraints.Clear();

                var typeReference = GetDelegateType(attribute, parameter);

                parameter.Constraints.Add(typeReference);
                attributes.RemoveAt(i--);
            }
            else if (IsEnumConstraintAttribute(attribute))
            {
                hasEnumConstraint = true;
                parameter.Attributes = GenericParameterAttributes.NonVariant | GenericParameterAttributes.NotNullableValueTypeConstraint;
                parameter.Constraints.Clear();

                var typeReference = GetEnumType(attribute, parameter);

                parameter.Constraints.Add(typeReference);
                attributes.RemoveAt(i--);
            }
        }
        if (hasDelegateConstraint && hasEnumConstraint)
        {
            throw new WeavingException("Cannot contain both [EnumConstraint] and [DelegateConstraint].");
        }
    }
开发者ID:TylerBrinkley,项目名称:ExtraConstraints,代码行数:36,代码来源:GenericParameterProcessor.cs


示例20: GenerateClass

        public TypeDefinition GenerateClass()
        {
            var commandClass = new TypeDefinition(
                GeneratedCommandClassNamespace
                , GeneratedCommandClassName
                , DefaultTypeAttributesForCommand
                , Assets.TypeReferences.Object);

            commandClass.Interfaces.Add(Assets.TypeReferences.ICommand);

            var genericParameter = new GenericParameter("TParameter", commandClass);
            commandClass.GenericParameters.Add(genericParameter);


            AddFields(commandClass);
            AddConstructors(commandClass);
            AddExecuteMethod(commandClass);
            AddCanExecuteMethod(commandClass);
            Assets.AddCanExecuteChangedEvent(commandClass);

            ModuleDefinition.Types.Add(commandClass);
            Assets.DelegateCommandImplementationWasInjected = true;
            return commandClass;
        }
开发者ID:brainoffline,项目名称:Commander.Fody,代码行数:24,代码来源:DelegateCommandClassInjectionProcessor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Cecil.ImportContext类代码示例发布时间:2022-05-26
下一篇:
C# Cecil.GenericInstanceType类代码示例发布时间: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