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


C# IGenericParameter类代码示例

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


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

示例1: GenericMapping

		/// <summary>
		/// Constrcuts a new GenericMapping for a specific mapping of generic parameters to type arguments.
		/// </summary>
		/// <param name="parameters">The generic parameters that should be mapped.</param>
		/// <param name="arguments">The type arguments to map generic parameters to.</param>
		protected GenericMapping(IGenericParameter[] parameters, IType[] arguments)
		{
			for (int i = 0; i < parameters.Length; i++)
			{
				_map.Add(parameters[i], arguments[i]);
			}
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:12,代码来源:GenericMapping.cs

示例2: GenericMapping

 /// <summary>
 /// Constrcuts a new GenericMapping for a specific mapping of generic parameters to type arguments.
 /// </summary>
 /// <param name="parameters">The generic parameters that should be mapped.</param>
 /// <param name="arguments">The type arguments to map generic parameters to.</param>
 protected GenericMapping(TypeSystemServices tss, IGenericParameter[] parameters, IType[] arguments)
 {
     _tss = tss;
     for (int i = 0; i < parameters.Length; i++)
     {
         _map.Add(parameters[i], arguments[i]);
     }
 }
开发者ID:boo,项目名称:boo-lang,代码行数:13,代码来源:GenericMapping.cs

示例3: GetInferredType

		public IType GetInferredType(IGenericParameter gp)
		{
			if (InferredTypes.ContainsKey(gp))
			{
				return InferredTypes[gp].ResultingType;
			}
			else
			{
				return null;
			}
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:11,代码来源:TypeInferrer.cs

示例4: WriteGenericParameter

 private void WriteGenericParameter(IGenericParameter param)
 {
     switch (param.Variance)
     {
         case TypeParameterVariance.Contravariant:
             WriteKeyword("in"); break;
         case TypeParameterVariance.Covariant:
             WriteKeyword("out"); break;
     }
     WriteTypeName(param, noSpace: true);
 }
开发者ID:pgavlin,项目名称:ApiTools,代码行数:11,代码来源:CSDeclarationWriter.Generics.cs

示例5: GetConstraints

        private IEnumerable<string> GetConstraints(IGenericParameter parameter)
        {
            if (parameter.MustBeValueType)
                yield return "struct";
            else
            {
                if (parameter.MustBeReferenceType)
                    yield return "class";

                if (parameter.MustHaveDefaultConstructor)
                    yield return "new()";
            }

            foreach (var constraint in parameter.Constraints)
            {
                // Skip valuetype becaue we should get it above.
                if (TypeHelper.TypesAreEquivalent(constraint, constraint.PlatformType.SystemValueType) && parameter.MustBeValueType)
                    continue;

                yield return constraint.FullName();
            }
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:22,代码来源:CannotRemoveGenerics.cs

示例6: GetConstraints

        private IEnumerable<Action> GetConstraints(IGenericParameter parameter)
        {
            if (parameter.MustBeValueType)
                yield return () => WriteKeyword("struct", noSpace: true);
            else
            {
                if (parameter.MustBeReferenceType)
                    yield return () => WriteKeyword("class", noSpace: true);
            }

            foreach (var constraint in parameter.Constraints)
            {
                // Skip valuetype becaue we should get it below.
                if (TypeHelper.TypesAreEquivalent(constraint, constraint.PlatformType.SystemValueType) && parameter.MustBeValueType)
                    continue;

                yield return () => WriteTypeName(constraint, noSpace: true);
            }

            // new constaint cannot be put on structs and needs to be the last constraint
            if (!parameter.MustBeValueType && parameter.MustHaveDefaultConstructor)
                yield return () => { WriteKeyword("new", noSpace: true); WriteSymbol("("); WriteSymbol(")"); };
        }
开发者ID:pgavlin,项目名称:ApiTools,代码行数:23,代码来源:CSDeclarationWriter.Generics.cs

示例7: GenericArgumentMustBeValueType

 public static CompilerError GenericArgumentMustBeValueType(Node node, IGenericParameter parameter, IType argument)
 {
     return new CompilerError("BCE0147", SafeLexicalInfo(node), argument, parameter);
 }
开发者ID:w4x,项目名称:boolangstudio,代码行数:4,代码来源:CompilerErrorFactory.cs

示例8: TraverseChildren

 /// <summary>
 /// Traverses the children of the generic parameter.
 /// </summary>
 public virtual void TraverseChildren(IGenericParameter genericParameter)
 {
     Contract.Requires(genericParameter != null);
       this.TraverseChildren((INamedTypeDefinition)genericParameter);
       if (this.stopTraversal) return;
       this.Traverse(genericParameter.Constraints);
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:10,代码来源:Visitors.cs

示例9: Visit

 /// <summary>
 /// Performs some computation with the given generic parameter.
 /// </summary>
 public virtual void Visit(IGenericParameter genericParameter)
 {
     this.Visit((INamedTypeDefinition)genericParameter);
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:7,代码来源:Visitors.cs

示例10: NoteGenericParameterFlow

    private void NoteGenericParameterFlow(ITypeDefinition actual, IGenericParameter formal) {

      if (createInstanceStrategy == TypeVariableCreateInstanceStrategy.ConstructAllConcreteParameters) {
        if (!(actual is IGenericParameter)) {
          // actual is concrete

          ITypeDefinition unspecializedConcreteType = GarbageCollectHelper.UnspecializeAndResolveTypeReference(actual);

          unspecializedTypesPassedAsTypeVariables.Add(unspecializedConcreteType);

          if (GarbageCollectHelper.TypeIsConstructable(unspecializedConcreteType)) {
            // t-devinc: We should associate a reason with this construction found
            ConstructionFound(unspecializedConcreteType);
            
            IMethodDefinition defaultConstructor = TypeHelper.GetMethod(unspecializedConcreteType, wholeProgram.Host().NameTable.GetNameFor(".ctor"));

            if (!(defaultConstructor is Dummy)) {
              // t-devinc: Add reason for this
              NotePotentialNonVirtualMethodReachedForReason(defaultConstructor, null);
            }
          }      
        }
      }      
    }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:24,代码来源:RapidTypeAnalysis.cs

示例11: Visit

 /// <summary>
 /// Performs some computation with the given generic parameter.
 /// </summary>
 public void Visit(IGenericParameter genericParameter)
 {
     this.Visit((INamedTypeDefinition)genericParameter);
     Hashtable constraintTable = null;
     foreach (var constraint in genericParameter.Constraints) {
       if (constraint.TypeCode == PrimitiveTypeCode.Void)
     this.ReportError(MetadataError.ConstraintMayNotBeVoid, constraint, genericParameter);
       if (constraintTable == null) constraintTable = new Hashtable();
       var key = constraint.InternedKey;
       if (constraintTable.Find(key) == 0)
     constraintTable.Add(key, key);
       else
     this.ReportError(MetadataError.DuplicateConstraint, constraint, genericParameter);
     }
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:18,代码来源:Validator.cs

示例12: ViolatesParameterConstraints

        /// <summary>
        /// Checks if a specified type argument violates the constraints 
        /// declared on a specified type paramter.
        /// </summary>
        public bool ViolatesParameterConstraints(IGenericParameter parameter, IType argument)
        {
            // Ensure argument is a valid type
            if (argument == null || TypeSystemServices.IsError(argument))
            {
                return false;
            }

            bool valid = true;

            // Check type semantics constraints
            if (parameter.IsClass && !argument.IsClass)
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustBeReferenceType(ConstructionNode, parameter, argument));
                valid = false;
            }

            if (parameter.IsValueType && !argument.IsValueType)
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustBeValueType(ConstructionNode, parameter, argument));
                valid = false;
            }

            if (parameter.MustHaveDefaultConstructor && !HasDefaultConstructor(argument))
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveDefaultConstructor(ConstructionNode, parameter, argument));
                valid = false;
            }

            // Check base type constraints
            IType[] baseTypes = parameter.GetTypeConstraints();
            if (baseTypes != null)
            {
                foreach (IType baseType in baseTypes)
                {
                    // Don't check for System.ValueType supertype constraint
                    // if parameter also has explicit value type constraint
                    if (baseType == _tss.ValueTypeType && parameter.IsValueType)
                        continue;

                    if (!baseType.IsAssignableFrom(argument))
                    {
                        Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveBaseType(ConstructionNode, parameter, argument, baseType));
                        valid = false;
                    }
                }
            }

            return !valid;
        }
开发者ID:boo,项目名称:boo-lang,代码行数:54,代码来源:GenericsServices.cs

示例13: GenericArgumentMustHaveBaseType

 public static CompilerError GenericArgumentMustHaveBaseType(Node node, IGenericParameter parameter, IType argument, IType baseType)
 {
     return Instantiate("BCE0149", node, argument, baseType, parameter, parameter.DeclaringEntity);
 }
开发者ID:neonux,项目名称:boo,代码行数:4,代码来源:CompilerErrorFactory.cs

示例14: DeclareGenericParameters

 public void DeclareGenericParameters(INodeWithGenericParameters node, IGenericParameter[] parameters, int parameterIndexDelta)
 {
     for (int i=0; i < parameters.Length; ++i)
     {
         var prototype = parameters[i];
         var newParameter = CreateGenericParameterDeclaration(parameterIndexDelta + i, prototype.Name);
         node.GenericParameters.Add(newParameter);
     }
 }
开发者ID:0xb1dd1e,项目名称:boo,代码行数:9,代码来源:BooCodeBuilder.cs

示例15: RecordClosureDependency

        private void RecordClosureDependency(BlockExpression closure, IGenericParameter genericParameter)
        {
            if (!_closureDependencies.ContainsKey(closure))
            {
                _closureDependencies.Add(closure, new List<InferredType>());
            }

            _closureDependencies[closure].AddUnique(InferredTypes[genericParameter]);
        }
开发者ID:BITechnologies,项目名称:boo,代码行数:9,代码来源:GenericParameterInferrer.cs


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