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

C# IMethodSymbol类代码示例

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

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



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

示例1: GenerateMethodDeclarationWorker

        private static MethodDeclarationSyntax GenerateMethodDeclarationWorker(
            IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var hasNoBody = !options.GenerateMethodBodies ||
                            destination == CodeGenerationDestination.InterfaceType ||
                            method.IsAbstract;

            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(method.ExplicitInterfaceImplementations);

            var returnType = method.ReturnsByRef
                ? method.ReturnType.GenerateRefTypeSyntax()
                : method.ReturnType.GenerateTypeSyntax();

            return AddCleanupAnnotationsTo(SyntaxFactory.MethodDeclaration(
                attributeLists: GenerateAttributes(method, options, explicitInterfaceSpecifier != null),
                modifiers: GenerateModifiers(method, destination, options),
                returnType: returnType,
                explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                identifier: method.Name.ToIdentifierToken(),
                typeParameterList: GenerateTypeParameterList(method, options),
                parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, explicitInterfaceSpecifier != null, options),
                constraintClauses: GenerateConstraintClauses(method),
                body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
                expressionBody: default(ArrowExpressionClauseSyntax),
                semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken()));
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:26,代码来源:MethodGenerator.cs


示例2: GetDelegateTypeParameters

        private IEnumerable<SignatureHelpParameter> GetDelegateTypeParameters(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position, CancellationToken cancellationToken)
        {
            const string TargetName = "target";

            var parts = new List<SymbolDisplayPart>();
            parts.AddRange(invokeMethod.ReturnType.ToMinimalDisplayParts(semanticModel, position));
            parts.Add(Space());
            parts.Add(Punctuation(SyntaxKind.OpenParenToken));

            var first = true;
            foreach (var parameter in invokeMethod.Parameters)
            {
                if (!first)
                {
                    parts.Add(Punctuation(SyntaxKind.CommaToken));
                    parts.Add(Space());
                }

                first = false;
                parts.AddRange(parameter.Type.ToMinimalDisplayParts(semanticModel, position));
            }

            parts.Add(Punctuation(SyntaxKind.CloseParenToken));
            parts.Add(Space());
            parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, null, TargetName));

            yield return new SignatureHelpParameter(
                TargetName,
                isOptional: false,
                documentationFactory: null,
                displayParts: parts);
        }
开发者ID:daking2014,项目名称:roslyn,代码行数:32,代码来源:ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs


示例3: IsDestructor

        private static bool IsDestructor(IMethodSymbol method)
        {
            if (method.MethodKind == MethodKind.Destructor)
            {
                return true; // for C#
            }

            if (method.Name != "Finalize" || method.Parameters.Length != 0 || !method.ReturnsVoid)
            {
                return false;
            }

            var overridden = method.OverriddenMethod;
            if (overridden == null)
            {
                return false;
            }

            for (var o = overridden.OverriddenMethod; o != null; o = o.OverriddenMethod)
            {
                overridden = o;
            }

            return overridden.ContainingType.SpecialType == SpecialType.System_Object; // it is object.Finalize
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:25,代码来源:CA1821DiagnosticAnalyzer.cs


示例4: IsMethodCandidate

 private static bool IsMethodCandidate(IMethodSymbol methodSymbol, Compilation compilation)
 {
     return methodSymbol.IsAsync &&
         methodSymbol.ReturnsVoid &&
         methodSymbol.IsChangeable() &&
         !methodSymbol.IsProbablyEventHandler(compilation);
 }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:7,代码来源:AsyncVoidMethod.cs


示例5: IsSingleParameterLinqMethod

 /// <summary>
 /// Is this a method on <see cref="Enumerable" /> which takes only a single parameter?
 /// </summary>
 /// <remarks>
 /// Many of the methods we target, like Last, have overloads that take a filter delegate.  It is 
 /// completely appropriate to use such methods even with <see cref="IReadOnlyList{T}" />.  Only the single parameter
 /// ones are suspect
 /// </remarks>
 private static bool IsSingleParameterLinqMethod(IMethodSymbol methodSymbol, ITypeSymbol enumerableType)
 {
     Debug.Assert(methodSymbol.ReducedFrom == null);
     return
         methodSymbol.ContainingSymbol.Equals(enumerableType) &&
         methodSymbol.Parameters.Length == 1;
 }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:15,代码来源:DoNotUseEnumerableMethodsOnIndexableCollectionsInsteadUseTheCollectionDirectly.cs


示例6: ParameterTypesMatch

        private static bool ParameterTypesMatch(SemanticDocument document, IList<ITypeSymbol> parameterTypes, IMethodSymbol method)
        {
            if (method == null)
            {
                return false;
            }

            if (parameterTypes.Count < method.Parameters.Length)
            {
                return false;
            }

            var compilation = document.SemanticModel.Compilation;
            var semanticFactsService = document.Document.GetLanguageService<ISemanticFactsService>();

            for (var i = 0; i < parameterTypes.Count; i++)
            {
                var type1 = parameterTypes[i];
                if (type1 != null)
                {
                    var type2 = method.Parameters[i].Type;

                    if (!semanticFactsService.IsAssignableTo(type1, type2, compilation))
                    {
                        return false;
                    }
                }
            }

            return true;
        }
开发者ID:hbarve1,项目名称:roslyn,代码行数:31,代码来源:GenerateConstructorHelpers.cs


示例7: GetMethodOverloadsWithDesiredParameterAtTrailing

 /// <summary>
 /// Returns a list of method symbols from a given list of the method symbols, which has its parameter type as
 /// expectedParameterType as its last parameter in addition to matching all the other parameter types of the 
 /// selectedOverload method symbol
 /// </summary>
 /// <param name="methods">List of <see cref="IMethodSymbol"/> to scan for possible overloads</param>
 /// <param name="selectedOverload"><see cref="IMethodSymbol"/> that is currently picked by the user</param>
 /// <param name="expectedTrailingParameterType"><see cref="INamedTypeSymbol"/> type of the leading parameter or the trailing parameter</param>
 public static IEnumerable<IMethodSymbol> GetMethodOverloadsWithDesiredParameterAtTrailing(
      this IEnumerable<IMethodSymbol> methods,
      IMethodSymbol selectedOverload,
      INamedTypeSymbol expectedTrailingParameterType)
 {
     return GetMethodOverloadsWithDesiredParameterAtLeadingOrTrailing(methods, selectedOverload, expectedTrailingParameterType, trailingOnly: true);
 }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:15,代码来源:IEnumerableOfIMethodSymbolExtensions.cs


示例8: ReadSymbol

        protected override void ReadSymbol(IMethodSymbol methodSymbol)
        {
            // we don't need to know about static members
            // because they won't be delegated from child to mixin
            if (methodSymbol.IsStatic)
                return;

            // skip methods that are not visible to the outside world
            if (methodSymbol.DeclaredAccessibility == Accessibility.Private ||
                methodSymbol.DeclaredAccessibility == Accessibility.Protected)
                return;

            // skip all property accessors and ctors
            if (methodSymbol.MethodKind == MethodKind.Ordinary)
            {
                var isOverrideFromObject = 
                    methodSymbol.IsOverride &&
                    methodSymbol.OverriddenMethod
                    ?.ContainingType.SpecialType == SpecialType.System_Object;
                var method = new Method(
                    methodSymbol.Name,
                    methodSymbol.ReturnType,
                    isOverrideFromObject)
                {
                    IsAbstract = methodSymbol.IsAbstract,
                    IsOverride = methodSymbol.IsOverride,
                    IsInternal = methodSymbol.DeclaredAccessibility.HasFlag(Accessibility.Internal),
                    Documentation = new DocumentationComment(methodSymbol.GetDocumentationCommentXml())
                };

                var parameterReader = new ParameterSymbolReader(method);
                parameterReader.VisitSymbol(methodSymbol);
                _methods.AddMethod(method);
            }
        }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:35,代码来源:MethodSymbolReader.cs


示例9: GetParameterSymbol

        public static IParameterSymbol GetParameterSymbol(ArgumentSyntax argument, ArgumentListSyntax argumentList, IMethodSymbol method)
        {
            if (!argumentList.Arguments.Contains(argument) ||
                method == null)
            {
                return null;
            }

            if (argument.NameColon != null)
            {
                return method.Parameters
                    .FirstOrDefault(symbol => symbol.Name == argument.NameColon.Name.Identifier.ValueText);
            }

            var argumentIndex = argumentList.Arguments.IndexOf(argument);
            var parameterIndex = argumentIndex;

            if (parameterIndex >= method.Parameters.Length)
            {
                var p = method.Parameters.Last();
                return p.IsParams ? p : null;
            }
            var parameter = method.Parameters[parameterIndex];
            return parameter;
        }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:25,代码来源:MethodParameterLookup.cs


示例10: GetInvertedStatement

 private SyntaxNode GetInvertedStatement(
     SyntaxGenerator generator, IMethodSymbol containingOperator, Compilation compilation)
 {
     if (containingOperator.Name == WellKnownMemberNames.EqualityOperatorName)
     {
         return generator.ReturnStatement(
             generator.LogicalNotExpression(
                 generator.ValueEqualsExpression(
                     generator.IdentifierName(containingOperator.Parameters[0].Name),
                     generator.IdentifierName(containingOperator.Parameters[1].Name))));
     }
     else if (containingOperator.Name == WellKnownMemberNames.InequalityOperatorName)
     {
         return generator.ReturnStatement(
             generator.LogicalNotExpression(
                 generator.ValueNotEqualsExpression(
                     generator.IdentifierName(containingOperator.Parameters[0].Name),
                     generator.IdentifierName(containingOperator.Parameters[1].Name))));
     }
     else
     {
         // If it's a  <   >   <=   or  >=   operator then we can't simply invert a call
         // to the existing operator.  i.e. the body of the "<" method should *not* be:
         //    return !(a > b);
         // Just provide a throwing impl for now.
         return generator.DefaultMethodStatement(compilation);
     }
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:28,代码来源:OperatorsShouldHaveSymmetricalOverloads.Fixer.cs


示例11: IsGetHashCodeOverride

 private static bool IsGetHashCodeOverride(IMethodSymbol method)
 {
     return method.IsOverride &&
            method.ReturnType.SpecialType == SpecialType.System_Int32 &&
            method.Parameters.Length == 0 &&
            IsObjectMethodOverride(method);
 }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:7,代码来源:INamedTypeSymbolExtensions.cs


示例12: getMethodDeclaration

 public static SyntaxNode getMethodDeclaration(IMethodSymbol el)
 {
     var meth = (el.PartialImplementationPart != null) ? el.PartialImplementationPart : el;
     var declarings = meth.DeclaringSyntaxReferences;
     if (declarings == null || declarings.Count() == 0) return null;
     return declarings.First().GetSyntax();
 }
开发者ID:Emettant,项目名称:Metr2,代码行数:7,代码来源:MetrCore.cs


示例13: MarkedWithStringFormatMethodAttribute

 private static bool MarkedWithStringFormatMethodAttribute(IMethodSymbol method)
 {
     return 
         method.GetAttributes()
         .Select(a => a.AttributeClass.FullName())
         .Any(a => a == "JetBrains.Annotations.StringFormatMethodAttribute");
 }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:7,代码来源:FormatHelper.cs


示例14: IsFormattableCall

        public static bool IsFormattableCall(IMethodSymbol method, SemanticModel semanticModel)
        {
            _formattableMembersByNamedTypes = GetFormattableMembers(semanticModel);
            LazyInitializer.EnsureInitialized(ref _formattableMembersByFullName, () => GetFormattableMembersByFullName());

            // Some well-known types we know upfront
            string methodName;
            if (_formattableMembersByNamedTypes.TryGetValue(method.ReceiverType, out methodName))
            {
                if (method.Name == methodName)
                {
                    return true;
                }
            }

            // But some types we can't reference from Portable library, for instance, System.Console
            if (_formattableMembersByFullName.TryGetValue(method.ReceiverType.FullName(), out methodName))
            {
                // Valid only if method has 'format' argument! 
                // TODO: need to extend the dictionary and provide format argument name!
                if (method.Name == methodName && method.Parameters.Any(p => p.Name == expectedFormatArgumentName))
                {
                    return true;
                }
            }

            if (MarkedWithStringFormatMethodAttribute(method))
            {
                return true;
            }

            return false;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:33,代码来源:FormatHelper.cs


示例15: CreatePropertySymbol

 internal static IPropertySymbol CreatePropertySymbol(
     INamedTypeSymbol containingType,
     IList<AttributeData> attributes,
     Accessibility accessibility,
     DeclarationModifiers modifiers,
     ITypeSymbol type,
     IPropertySymbol explicitInterfaceSymbol,
     string name,
     IList<IParameterSymbol> parameters,
     IMethodSymbol getMethod,
     IMethodSymbol setMethod,
     bool isIndexer = false,
     SyntaxNode initializer = null)
 {
     var result = new CodeGenerationPropertySymbol(
         containingType,
         attributes,
         accessibility,
         modifiers,
         type,
         explicitInterfaceSymbol,
         name,
         isIndexer,
         parameters,
         getMethod,
         setMethod);
     CodeGenerationPropertyInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, initializer);
     return result;
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:29,代码来源:CodeGenerationSymbolFactory.cs


示例16: TryGetParameterSymbol

        public static bool TryGetParameterSymbol(ArgumentSyntax argument, ArgumentListSyntax argumentList,
            IMethodSymbol method, out IParameterSymbol parameter)
        {
            parameter = null;
            if (!argumentList.Arguments.Contains(argument) ||
                method == null ||
                method.IsVararg)
            {
                return false;
            }

            if (argument.NameColon != null)
            {
                parameter = method.Parameters
                    .FirstOrDefault(symbol => symbol.Name == argument.NameColon.Name.Identifier.ValueText);
                return parameter != null;
            }

            var argumentIndex = argumentList.Arguments.IndexOf(argument);
            var parameterIndex = argumentIndex;

            if (parameterIndex >= method.Parameters.Length)
            {
                var lastParameter = method.Parameters.Last();
                parameter = lastParameter.IsParams ? lastParameter : null;
                return parameter != null;
            }
            parameter = method.Parameters[parameterIndex];
            return true;
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:30,代码来源:MethodParameterLookup.cs


示例17: ExpandedMethodName

        private static string ExpandedMethodName(IMethodSymbol method)
        {
            var ret = new StringBuilder(20);

            ret.Append(method.Name);
            ret.Append("_");

            foreach (var param in method.Parameters)
            {
                ret.Append(param.Type.Name);

                var named = param.Type as INamedTypeSymbol;
                if (named != null)
                {
                    foreach (var typeArg in named.TypeArguments)
                    {
                        if (typeArg.TypeKind != TypeKind.TypeParameter)
                            ret.Append(typeArg.Name);
                    }
                }

                ret.Append("_");
            }

            ret.Remove(ret.Length - 1, 1);
            return ret.ToString();
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:27,代码来源:OverloadResolver.cs


示例18: IsEqualsOverride

 private static bool IsEqualsOverride(IMethodSymbol method)
 {
     return method.IsOverride &&
            method.ReturnType.SpecialType == SpecialType.System_Boolean &&
            method.Parameters.Length == 1 &&
            method.Parameters[0].Type.SpecialType == SpecialType.System_Object;
 }
开发者ID:ondrejsevcik,项目名称:roslyn-analyzers,代码行数:7,代码来源:INamedTypeSymbolExtensions.cs


示例19: UnusedParametersAnalyzer

 public UnusedParametersAnalyzer(IMethodSymbol method)
 {
     // Initialization: Assume all parameters are unused.
     var parameters = method.Parameters.Where(p => !p.IsImplicitlyDeclared && p.Locations.Length > 0);
     _unusedParameters = new HashSet<IParameterSymbol>(parameters);
     _unusedParameterNames = new HashSet<string>(parameters.Select(p => p.Name));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:CodeBlockStartedAnalyzer.cs


示例20: RenderMethodSymbol

        private void RenderMethodSymbol(IMethodSymbol methodSymbol)
        {
            var nonInferredTypeArguments = NonInferredTypeArguments(methodSymbol);
            _sb.Append(methodSymbol.Name);

            if (nonInferredTypeArguments.Any())
            {
                _sb.Append("<");
                var last = nonInferredTypeArguments.Last();
                foreach (var arg in nonInferredTypeArguments)
                {
                    RenderSnippetStartMarker();
                    _sb.Append(arg);
                    RenderSnippetEndMarker();

                    if (arg != last)
                    {
                        _sb.Append(", ");
                    }
                }
                _sb.Append(">");
            }

            RenderParameters(methodSymbol);
            if (methodSymbol.ReturnsVoid && IncludeMarkers)
            {
                _sb.Append(";");
            }
        }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:29,代码来源:SnippetGenerator.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IMigration类代码示例发布时间:2022-05-24
下一篇:
C# IMethodSignature类代码示例发布时间: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