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


C# IMethodSymbol类代码示例

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


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


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