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

C# ITypeParameterSymbol类代码示例

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

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



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


示例16: AddTypeParameterVarianceIfRequired

 private void AddTypeParameterVarianceIfRequired(ITypeParameterSymbol symbol)
 {
     if (format.GenericsOptions.IncludesOption(SymbolDisplayGenericsOptions.IncludeVariance))
     {
         switch (symbol.Variance)
         {
             case VarianceKind.In:
                 AddKeyword(SyntaxKind.InKeyword);
                 AddSpace();
                 break;
             case VarianceKind.Out:
                 AddKeyword(SyntaxKind.OutKeyword);
                 AddSpace();
                 break;
         }
     }
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:17,代码来源:SymbolDisplayVisitor.Types.cs


示例17: VisitTypeParameter

        public override void VisitTypeParameter(ITypeParameterSymbol symbol)
        {
            if (this.isFirstSymbolVisited)
            {
                AddTypeParameterVarianceIfRequired(symbol);
            }

            //variance and constraints are handled by methods and named types
            builder.Add(CreatePart(SymbolDisplayPartKind.TypeParameterName, symbol, symbol.Name));
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:10,代码来源:SymbolDisplayVisitor.Types.cs


示例18: GetSelectedDisplayParts

        private IList<SymbolDisplayPart> GetSelectedDisplayParts(
            ITypeParameterSymbol typeParam,
            SemanticModel semanticModel,
            int position,
            CancellationToken cancellationToken)
        {
            var parts = new List<SymbolDisplayPart>();

            if (TypeParameterHasConstraints(typeParam))
            {
                parts.Add(Space());
                parts.Add(Keyword(SyntaxKind.WhereKeyword));
                parts.Add(Space());

                parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.TypeParameterName, typeParam, typeParam.Name));

                parts.Add(Space());
                parts.Add(Punctuation(SyntaxKind.ColonToken));
                parts.Add(Space());

                bool needComma = false;

                // class/struct constraint must be first
                if (typeParam.HasReferenceTypeConstraint)
                {
                    parts.Add(Keyword(SyntaxKind.ClassKeyword));
                    needComma = true;
                }
                else if (typeParam.HasValueTypeConstraint)
                {
                    parts.Add(Keyword(SyntaxKind.StructKeyword));
                    needComma = true;
                }

                foreach (var baseType in typeParam.ConstraintTypes)
                {
                    if (needComma)
                    {
                        parts.Add(Punctuation(SyntaxKind.CommaToken));
                        parts.Add(Space());
                    }

                    parts.AddRange(baseType.ToMinimalDisplayParts(semanticModel, position));
                    needComma = true;
                }

                // ctor constraint must be last
                if (typeParam.HasConstructorConstraint)
                {
                    if (needComma)
                    {
                        parts.Add(Punctuation(SyntaxKind.CommaToken));
                        parts.Add(Space());
                    }

                    parts.Add(Keyword(SyntaxKind.NewKeyword));
                    parts.Add(Punctuation(SyntaxKind.OpenParenToken));
                    parts.Add(Punctuation(SyntaxKind.CloseParenToken));
                }
            }

            return parts;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:63,代码来源:GenericNameSignatureHelpProvider.cs


示例19: Convert

 private SignatureHelpSymbolParameter Convert(
     ITypeParameterSymbol parameter,
     SemanticModel semanticModel,
     int position,
     IDocumentationCommentFormattingService formatter,
     CancellationToken cancellationToken)
 {
     return new SignatureHelpSymbolParameter(
         parameter.Name,
         isOptional: false,
         documentationFactory: parameter.GetDocumentationPartsFactory(semanticModel, position, formatter),
         displayParts: parameter.ToMinimalDisplayParts(semanticModel, position, s_minimallyQualifiedFormat),
         selectedDisplayParts: GetSelectedDisplayParts(parameter, semanticModel, position, cancellationToken));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:14,代码来源:GenericNameSignatureHelpProvider.cs


示例20: GetTypeParameterConstraint

 private static IEnumerable<TypeParameterConstraintSyntax> GetTypeParameterConstraint(ITypeParameterSymbol symbol)
 {
     if (symbol.HasReferenceTypeConstraint)
     {
         yield return SyntaxFactory.ClassOrStructConstraint(SyntaxKind.ClassConstraint);
     }
     if (symbol.HasValueTypeConstraint)
     {
         yield return SyntaxFactory.ClassOrStructConstraint(SyntaxKind.StructConstraint);
     }
     if (symbol.ConstraintTypes.Length > 0)
     {
         for (int i = 0; i < symbol.ConstraintTypes.Length; i++)
         {
             yield return SyntaxFactory.TypeConstraint(GetTypeSyntax(symbol.ConstraintTypes[i]));
         }
     }
     if (symbol.HasConstructorConstraint)
     {
         yield return SyntaxFactory.ConstructorConstraint();
     }
 }
开发者ID:dotnet,项目名称:docfx,代码行数:22,代码来源:CSYamlModelGenerator.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ITypeProvider类代码示例发布时间:2022-05-24
下一篇:
C# ITypeParameter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap