本文整理汇总了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()));
}
示例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
}
示例4: IsMethodCandidate
private static bool IsMethodCandidate(IMethodSymbol methodSymbol, Compilation compilation)
{
return methodSymbol.IsAsync &&
methodSymbol.ReturnsVoid &&
methodSymbol.IsChangeable() &&
!methodSymbol.IsProbablyEventHandler(compilation);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例11: IsGetHashCodeOverride
private static bool IsGetHashCodeOverride(IMethodSymbol method)
{
return method.IsOverride &&
method.ReturnType.SpecialType == SpecialType.System_Int32 &&
method.Parameters.Length == 0 &&
IsObjectMethodOverride(method);
}
示例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();
}
示例13: MarkedWithStringFormatMethodAttribute
private static bool MarkedWithStringFormatMethodAttribute(IMethodSymbol method)
{
return
method.GetAttributes()
.Select(a => a.AttributeClass.FullName())
.Any(a => a == "JetBrains.Annotations.StringFormatMethodAttribute");
}
示例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;
}
示例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;
}