本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax.GetReference方法的典型用法代码示例。如果您正苦于以下问题:C# AccessorDeclarationSyntax.GetReference方法的具体用法?C# AccessorDeclarationSyntax.GetReference怎么用?C# AccessorDeclarationSyntax.GetReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax
的用法示例。
在下文中一共展示了AccessorDeclarationSyntax.GetReference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SourceCustomEventAccessorSymbol
internal SourceCustomEventAccessorSymbol(
SourceEventSymbol @event,
AccessorDeclarationSyntax syntax,
EventSymbol explicitlyImplementedEventOpt,
string aliasQualifierOpt,
DiagnosticBag diagnostics)
: base(@event,
syntax.GetReference(),
syntax.Body.GetReferenceOrNull(),
ImmutableArray.Create(syntax.Keyword.GetLocation()))
{
Debug.Assert(syntax != null);
Debug.Assert(syntax.Kind == SyntaxKind.AddAccessorDeclaration || syntax.Kind == SyntaxKind.RemoveAccessorDeclaration);
bool isAdder = syntax.Kind == SyntaxKind.AddAccessorDeclaration;
string name;
ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
if ((object)explicitlyImplementedEventOpt == null)
{
name = SourceEventSymbol.GetAccessorName(@event.Name, isAdder);
explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
}
else
{
MethodSymbol implementedAccessor = isAdder ? explicitlyImplementedEventOpt.AddMethod : explicitlyImplementedEventOpt.RemoveMethod;
string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name : SourceEventSymbol.GetAccessorName(explicitlyImplementedEventOpt.Name, isAdder);
name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedEventOpt.ContainingType, aliasQualifierOpt);
explicitInterfaceImplementations = (object)implementedAccessor == null ? ImmutableArray<MethodSymbol>.Empty : ImmutableArray.Create<MethodSymbol>(implementedAccessor);
}
this.explicitInterfaceImplementations = explicitInterfaceImplementations;
this.name = name;
this.flags = MakeFlags(
isAdder ? MethodKind.EventAdd : MethodKind.EventRemove,
@event.Modifiers,
returnsVoid: false, // until we learn otherwise (in LazyMethodChecks).
isExtensionMethod: false,
isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any());
if (@event.ContainingType.IsInterface)
{
diagnostics.Add(ErrorCode.ERR_EventPropertyInInterface, this.Location);
}
else
{
var bodyOpt = syntax.Body;
if (bodyOpt != null)
{
if (IsExtern && !IsAbstract)
{
diagnostics.Add(ErrorCode.ERR_ExternHasBody, this.Location, this);
}
else if (IsAbstract && !IsExtern)
{
diagnostics.Add(ErrorCode.ERR_AbstractHasBody, this.Location, this);
}
// Do not report error for IsAbstract && IsExtern. Dev10 reports CS0180 only
// in that case ("member cannot be both extern and abstract").
}
}
this.name = GetOverriddenAccessorName(@event, isAdder) ?? this.name;
}
示例2: SourcePropertyAccessorSymbol
private SourcePropertyAccessorSymbol(
NamedTypeSymbol containingType,
string name,
SourcePropertySymbol property,
DeclarationModifiers propertyModifiers,
ImmutableArray<MethodSymbol> explicitInterfaceImplementations,
Location location,
AccessorDeclarationSyntax syntax,
MethodKind methodKind,
bool isAutoPropertyAccessor,
DiagnosticBag diagnostics) :
base(containingType, syntax.GetReference(), syntax.Body?.GetReference(), location)
{
_property = property;
_explicitInterfaceImplementations = explicitInterfaceImplementations;
_name = name;
_isAutoPropertyAccessor = isAutoPropertyAccessor;
bool modifierErrors;
var declarationModifiers = this.MakeModifiers(syntax, location, diagnostics, out modifierErrors);
// Include modifiers from the containing property.
propertyModifiers &= ~DeclarationModifiers.AccessibilityMask;
if ((declarationModifiers & DeclarationModifiers.Private) != 0)
{
// Private accessors cannot be virtual.
propertyModifiers &= ~DeclarationModifiers.Virtual;
}
declarationModifiers |= propertyModifiers & ~DeclarationModifiers.Indexer;
// ReturnsVoid property is overridden in this class so
// returnsVoid argument to MakeFlags is ignored.
this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false,
isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any());
var bodyOpt = syntax.Body;
if (bodyOpt != null)
{
CheckModifiersForBody(location, diagnostics);
}
var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers);
if (info != null)
{
diagnostics.Add(info, location);
}
if (!modifierErrors)
{
this.CheckModifiers(location, isAutoPropertyAccessor, diagnostics);
}
if (this.IsOverride)
{
MethodSymbol overriddenMethod = this.OverriddenMethod;
if ((object)overriddenMethod != null)
{
// If this accessor is overriding a method from metadata, it is possible that
// the name of the overridden method doesn't follow the C# get_X/set_X pattern.
// We should copy the name so that the runtime will recognize this as an override.
_name = overriddenMethod.Name;
}
}
}
示例3: SourcePropertyAccessorSymbol
private SourcePropertyAccessorSymbol(
NamedTypeSymbol containingType,
string name,
SourcePropertySymbol property,
DeclarationModifiers propertyModifiers,
ImmutableArray<MethodSymbol> explicitInterfaceImplementations,
Location location,
AccessorDeclarationSyntax syntax,
MethodKind methodKind,
bool isAutoPropertyAccessor,
DiagnosticBag diagnostics) :
base(containingType, syntax.GetReference(), syntax.Body.GetReferenceOrNull(), location)
{
this.property = property;
this.explicitInterfaceImplementations = explicitInterfaceImplementations;
this.name = name;
this.isAutoPropertyAccessor = isAutoPropertyAccessor;
bool modifierErrors;
var declarationModifiers = this.MakeModifiers(syntax, location, diagnostics, out modifierErrors);
// Include modifiers from the containing property.
propertyModifiers &= ~DeclarationModifiers.AccessibilityMask;
if ((declarationModifiers & DeclarationModifiers.Private) != 0)
{
// Private accessors cannot be virtual.
propertyModifiers &= ~DeclarationModifiers.Virtual;
}
declarationModifiers |= propertyModifiers;
// ReturnsVoid property is overridden in this class so
// returnsVoid argument to MakeFlags is ignored.
this.flags = MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false,
isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any());
var bodyOpt = syntax.Body;
if (bodyOpt != null)
{
if (containingType.IsInterface)
{
diagnostics.Add(ErrorCode.ERR_InterfaceMemberHasBody, location, this);
}
else if (IsExtern && !IsAbstract)
{
diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this);
}
else if (IsAbstract && !IsExtern)
{
diagnostics.Add(ErrorCode.ERR_AbstractHasBody, location, this);
}
// Do not report error for IsAbstract && IsExtern. Dev10 reports CS0180 only
// in that case ("member cannot be both extern and abstract").
}
var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers);
if (info != null)
{
diagnostics.Add(info, location);
}
if (!modifierErrors)
{
this.CheckModifiers(location, isAutoPropertyAccessor, diagnostics);
}
if (this.IsOverride)
{
MethodSymbol overriddenMethod = this.OverriddenMethod;
if ((object)overriddenMethod != null)
{
// If this accessor is overriding a method from metadata, it is possible that
// the name of the overridden method doesn't follow the C# get_X/set_X pattern.
// We should copy the name so that the runtime will recognize this as an override.
this.name = overriddenMethod.Name;
}
}
}