本文整理汇总了C#中IPropertySymbol.IsIndexer方法的典型用法代码示例。如果您正苦于以下问题:C# IPropertySymbol.IsIndexer方法的具体用法?C# IPropertySymbol.IsIndexer怎么用?C# IPropertySymbol.IsIndexer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPropertySymbol
的用法示例。
在下文中一共展示了IPropertySymbol.IsIndexer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverridePropertyAsync
public static async Task<IPropertySymbol> OverridePropertyAsync(
this SyntaxGenerator codeFactory,
IPropertySymbol overriddenProperty,
DeclarationModifiers modifiers,
INamedTypeSymbol containingType,
Document document,
CancellationToken cancellationToken)
{
var getAccessibility = overriddenProperty.GetMethod.ComputeResultantAccessibility(containingType);
var setAccessibility = overriddenProperty.SetMethod.ComputeResultantAccessibility(containingType);
SyntaxNode getBody = null;
SyntaxNode setBody = null;
// Implement an abstract property by throwing not implemented in accessors.
if (overriddenProperty.IsAbstract)
{
var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
getBody = codeFactory.CreateThrowNotImplementStatement(compilation);
setBody = getBody;
}
else if (overriddenProperty.IsIndexer() && document.Project.Language == LanguageNames.CSharp)
{
// Indexer: return or set base[]. Only in C#, since VB must refer to these by name.
getBody = codeFactory.ReturnStatement(
codeFactory.ElementAccessExpression(
codeFactory.BaseExpression(),
codeFactory.CreateArguments(overriddenProperty.Parameters)));
setBody = codeFactory.ExpressionStatement(
codeFactory.AssignmentStatement(
codeFactory.ElementAccessExpression(
codeFactory.BaseExpression(),
codeFactory.CreateArguments(overriddenProperty.Parameters)),
codeFactory.IdentifierName("value")));
}
else if (overriddenProperty.GetParameters().Any())
{
// Call accessors directly if C# overriding VB
if (document.Project.Language == LanguageNames.CSharp
&& (await SymbolFinder.FindSourceDefinitionAsync(overriddenProperty, document.Project.Solution, cancellationToken).ConfigureAwait(false))
.Language == LanguageNames.VisualBasic)
{
var getName = overriddenProperty.GetMethod != null ? overriddenProperty.GetMethod.Name : null;
var setName = overriddenProperty.SetMethod != null ? overriddenProperty.SetMethod.Name : null;
getBody = getName == null
? null
: codeFactory.ReturnStatement(
codeFactory.InvocationExpression(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(getName)),
codeFactory.CreateArguments(overriddenProperty.Parameters)));
setBody = setName == null
? null
: codeFactory.ExpressionStatement(
codeFactory.InvocationExpression(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(setName)),
codeFactory.CreateArguments(overriddenProperty.SetMethod.GetParameters())));
}
else
{
getBody = codeFactory.ReturnStatement(
codeFactory.InvocationExpression(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(overriddenProperty.Name)), codeFactory.CreateArguments(overriddenProperty.Parameters)));
setBody = codeFactory.ExpressionStatement(
codeFactory.AssignmentStatement(
codeFactory.InvocationExpression(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(overriddenProperty.Name)), codeFactory.CreateArguments(overriddenProperty.Parameters)),
codeFactory.IdentifierName("value")));
}
}
else
{
// Regular property: return or set the base property
getBody = codeFactory.ReturnStatement(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(overriddenProperty.Name)));
setBody = codeFactory.ExpressionStatement(
codeFactory.AssignmentStatement(
codeFactory.MemberAccessExpression(
codeFactory.BaseExpression(),
codeFactory.IdentifierName(overriddenProperty.Name)),
codeFactory.IdentifierName("value")));
}
// Only generate a getter if the base getter is accessible.
IMethodSymbol accessorGet = null;
if (overriddenProperty.GetMethod != null && overriddenProperty.GetMethod.IsAccessibleWithin(containingType))
{
accessorGet = CodeGenerationSymbolFactory.CreateMethodSymbol(
//.........这里部分代码省略.........