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


C# ITypeParameterSymbol类代码示例

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


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

示例1: VisitTypeParameter

 public override void VisitTypeParameter(ITypeParameterSymbol symbol)
 {
     ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem
     {
         DisplayName = symbol.Name,
         DisplayQualifiedNames = symbol.Name,
     });
 }
开发者ID:yonglehou,项目名称:docfx,代码行数:8,代码来源:ReferenceItemVisitor.cs

示例2: GenerateTypeParameter

        private static TypeParameterSyntax GenerateTypeParameter(ITypeParameterSymbol symbol, CodeGenerationOptions options)
        {
            var varianceKeyword =
                symbol.Variance == VarianceKind.In ? SyntaxFactory.Token(SyntaxKind.InKeyword) :
                symbol.Variance == VarianceKind.Out ? SyntaxFactory.Token(SyntaxKind.OutKeyword) : default(SyntaxToken);

            return SyntaxFactory.TypeParameter(
                AttributeGenerator.GenerateAttributeLists(symbol.GetAttributes(), options),
                varianceKeyword,
                symbol.Name.ToIdentifierToken());
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:TypeParameterGenerator.cs

示例3: VisitTypeParameter

        public sealed override void VisitTypeParameter(ITypeParameterSymbol symbol)
        {
            // Using an if, rather than assert condition, to make debugging easier.
            if (!_acceptableTypeParameters.Contains(symbol))
            {
                Debug.Assert(false,
                    string.Format("Unexpected type parameter {0} owned by {1}", symbol, symbol.ContainingSymbol));
            }

            foreach (var constraintType in symbol.ConstraintTypes)
            {
                Visit(constraintType);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:14,代码来源:AbstractTypeParameterChecker.cs

示例4: GetTypeParameter

        private SDTypeParameter GetTypeParameter(ITypeParameterSymbol typeParameter)
        {
            var sdTypeParameter = new SDTypeParameter
            {
                Name = typeParameter.Name,
                HasDefaultConstructorConstraint = typeParameter.HasConstructorConstraint,
                HasReferenceTypeConstraint = typeParameter.HasReferenceTypeConstraint,
                HasValueTypeConstraint = typeParameter.HasValueTypeConstraint
            };
            foreach (var constraintType in typeParameter.ConstraintTypes)
            {
                sdTypeParameter.ConstraintTypes.Add(_typeRefParser.GetParsedTypeReference(constraintType));
            }

            return sdTypeParameter;
        }
开发者ID:Geaz,项目名称:sharpDox,代码行数:16,代码来源:TypeParameterParser.cs

示例5: VisitTypeParameter

            public override void VisitTypeParameter(ITypeParameterSymbol symbol)
            {
                if (_visited.Add(symbol))
                {
                    if (symbol.TypeParameterKind == TypeParameterKind.Method || !_onlyMethodTypeParameters)
                    {
                        if (!_typeParameters.Contains(symbol))
                        {
                            _typeParameters.Add(symbol);
                        }
                    }

                    foreach (var constraint in symbol.ConstraintTypes)
                    {
                        constraint.Accept(this);
                    }
                }
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:18,代码来源:ITypeSymbolExtensions.CollectTypeParameterSymbolsVisitor.cs

示例6: AddConstraintClauses

        private static void AddConstraintClauses(
            List<TypeParameterConstraintClauseSyntax> clauses,
            ITypeParameterSymbol typeParameter)
        {
            var constraints = new List<TypeParameterConstraintSyntax>();

            if (typeParameter.HasReferenceTypeConstraint)
            {
                constraints.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.ClassConstraint));
            }
            else if (typeParameter.HasValueTypeConstraint)
            {
                constraints.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.StructConstraint));
            }

            var constraintTypes =
                typeParameter.ConstraintTypes.Where(t => t.TypeKind == TypeKind.Class).Concat(
                typeParameter.ConstraintTypes.Where(t => t.TypeKind == TypeKind.Interface).Concat(
                typeParameter.ConstraintTypes.Where(t => t.TypeKind != TypeKind.Class && t.TypeKind != TypeKind.Interface)));

            foreach (var type in constraintTypes)
            {
                if (type.SpecialType != SpecialType.System_Object)
                {
                    constraints.Add(SyntaxFactory.TypeConstraint(type.GenerateTypeSyntax()));
                }
            }

            if (typeParameter.HasConstructorConstraint)
            {
                constraints.Add(SyntaxFactory.ConstructorConstraint());
            }

            if (constraints.Count == 0)
            {
                return;
            }

            clauses.Add(SyntaxFactory.TypeParameterConstraintClause(
                typeParameter.Name.ToIdentifierName(),
                SyntaxFactory.SeparatedList(constraints)));
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:42,代码来源:ITypeParameterSymbolExtensions.cs

示例7: CheckTypeParameter

        private static bool CheckTypeParameter(ITypeParameterSymbol typeParameter, VarianceKind variance,
            INamedTypeSymbol delegateType, ITypeSymbol returnType, ImmutableArray<IParameterSymbol> parameters)
        {
            var canBe = CheckTypeParameterContraintsInSymbol(typeParameter, variance, delegateType);
            if (!canBe)
            {
                return false;
            }

            canBe = CanTypeParameterBeVariant(typeParameter, variance, returnType,
                true, false, delegateType);

            if (!canBe)
            {
                return false;
            }

            canBe = CheckTypeParameterInParameters(typeParameter, variance, parameters, delegateType);
            return canBe;
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:20,代码来源:GenericTypeParameterInOut.cs

示例8: CanTypeParameterBeVariant

        private static bool CanTypeParameterBeVariant(
            ITypeParameterSymbol parameter,
            VarianceKind variance,
            INamedTypeSymbol namedType,
            bool requireOutputSafety,
            bool requireInputSafety,
            ISymbol context)
        {

            switch (namedType.TypeKind)
            {
                case TypeKind.Class:
                case TypeKind.Struct:
                case TypeKind.Enum:
                case TypeKind.Interface:
                case TypeKind.Delegate:
                case TypeKind.Error:
                    break;
                default:
                    return true;
            }

            var currentNamedType = namedType;
            while (currentNamedType != null)
            {
                for (int i = 0; i < currentNamedType.Arity; i++)
                {
                    var typeParam = currentNamedType.TypeParameters[i];
                    var typeArg = currentNamedType.TypeArguments[i];

                    if (!typeArg.Equals(parameter))
                    {
                        return false;
                    }

                    var requireOut = false;
                    var requireIn = false;

                    switch (typeParam.Variance)
                    {
                        case VarianceKind.Out:
                            requireOut = requireOutputSafety;
                            requireIn = requireInputSafety;
                            break;
                        case VarianceKind.In:
                            requireOut = requireInputSafety;
                            requireIn = requireOutputSafety;
                            break;
                        case VarianceKind.None:
                            requireIn = true;
                            requireOut = true;
                            break;
                        default:
                            throw new NotSupportedException();
                    }

                    if (!CanTypeParameterBeVariant(parameter, variance, typeArg, requireOut, requireIn, context))
                    {
                        return false;
                    }
                }

                currentNamedType = currentNamedType.ContainingType;
            }

            return true;
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:67,代码来源:GenericTypeParameterInOut.cs

示例9: CheckTypeParameterContraintsInSymbol

        private static bool CheckTypeParameterContraintsInSymbol(ITypeParameterSymbol typeParameter, VarianceKind variance,
            ISymbol context)
        {
            foreach (ITypeSymbol constraintType in typeParameter.ConstraintTypes)
            {
                var canBe = CanTypeParameterBeVariant(
                    typeParameter,
                    variance,
                    constraintType,
                    false,
                    true,
                    context);

                if (!canBe)
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:20,代码来源:GenericTypeParameterInOut.cs

示例10: CheckTypeParameterInEvent

 private static bool CheckTypeParameterInEvent(ITypeParameterSymbol typeParameter, VarianceKind variance,
     IEventSymbol @event)
 {
     return CanTypeParameterBeVariant(
         typeParameter, variance,
         @event.Type,
         false,
         true,
         @event);
 }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:10,代码来源:GenericTypeParameterInOut.cs

示例11: ReportIssue

        private static void ReportIssue(ITypeParameterSymbol typeParameter, VarianceKind variance, SyntaxNodeAnalysisContext context)
        {
            if (!typeParameter.DeclaringSyntaxReferences.Any())
            {
                return;
            }

            var location = typeParameter.DeclaringSyntaxReferences.First().GetSyntax().GetLocation();

            if (variance == VarianceKind.In)
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, location, "in", typeParameter.Name, "contravariant"));
                return;
            }

            if (variance == VarianceKind.Out)
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, location, "out", typeParameter.Name, "covariant"));
                return;
            }
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:21,代码来源:GenericTypeParameterInOut.cs

示例12: CheckTypeParameterInMethod

        private static bool CheckTypeParameterInMethod(ITypeParameterSymbol typeParameter, VarianceKind variance,
            IMethodSymbol method)
        {
            var canBe = CheckTypeParameterContraintsInSymbol(typeParameter, variance, method);
            if (!canBe)
            {
                return false;
            }

            canBe = CanTypeParameterBeVariant(
                typeParameter, variance,
                method.ReturnType,
                true,
                false,
                method);

            if (!canBe)
            {
                return false;
            }

            return CheckTypeParameterInParameters(typeParameter, variance, method.Parameters, method);
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:23,代码来源:GenericTypeParameterInOut.cs

示例13: HaveSameConstraints

        private bool HaveSameConstraints(ITypeParameterSymbol typeParameter1, ITypeParameterSymbol typeParameter2)
        {
            if (typeParameter1.HasConstructorConstraint != typeParameter2.HasConstructorConstraint ||
                typeParameter1.HasReferenceTypeConstraint != typeParameter2.HasReferenceTypeConstraint ||
                typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint)
            {
                return false;
            }

            if (typeParameter1.ConstraintTypes.Length != typeParameter2.ConstraintTypes.Length)
            {
                return false;
            }

            return typeParameter1.ConstraintTypes.SetEquals(
                typeParameter2.ConstraintTypes, this.SignatureTypeEquivalenceComparer);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:17,代码来源:SignatureComparer.cs

示例14: GetVarianceToken

 private static SyntaxToken GetVarianceToken(ITypeParameterSymbol t)
 {
     if (t.Variance == VarianceKind.In)
         return SyntaxFactory.Token(SyntaxKind.InKeyword);
     if (t.Variance == VarianceKind.Out)
         return SyntaxFactory.Token(SyntaxKind.OutKeyword);
     return new SyntaxToken();
 }
开发者ID:dotnet,项目名称:docfx,代码行数:8,代码来源:CSYamlModelGenerator.cs

示例15: TypeParameterHasConstraints

 private static bool TypeParameterHasConstraints(ITypeParameterSymbol typeParam)
 {
     return !typeParam.ConstraintTypes.IsEmpty || typeParam.HasConstructorConstraint ||
         typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint;
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:5,代码来源:SymbolDisplayVisitor.Types.cs


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