本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax.GetPropertySymbol方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDeclarationSyntax.GetPropertySymbol方法的具体用法?C# PropertyDeclarationSyntax.GetPropertySymbol怎么用?C# PropertyDeclarationSyntax.GetPropertySymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax
的用法示例。
在下文中一共展示了PropertyDeclarationSyntax.GetPropertySymbol方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitPropertyDeclaration
/// <summary>
/// Normalizes the <paramref name="declaration" />.
/// </summary>
public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax declaration)
{
var propertySymbol = declaration.GetPropertySymbol(SemanticModel);
if (!propertySymbol.ContainingType.IsComponent(SemanticModel) || !propertySymbol.IsExtern)
return declaration;
var originalDeclaration = declaration;
var index = declaration.Modifiers.IndexOf(SyntaxKind.ExternKeyword);
declaration = declaration.WithModifiers(declaration.Modifiers.RemoveAt(index)).WithSemicolonToken(default(SyntaxToken));
var accessors = SyntaxFactory.List(NormalizerAccessors(originalDeclaration.AccessorList.Accessors));
return declaration.WithAccessorList(declaration.AccessorList.WithAccessors(accessors)).EnsureLineCount(originalDeclaration);
}
示例2: VisitPropertyDeclaration
/// <summary>
/// Normalizes the <paramref name="declaration" />.
/// </summary>
public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax declaration)
{
var objectCreation = declaration?.Initializer?.Value as ObjectCreationExpressionSyntax;
if (objectCreation == null)
return declaration;
var symbol = declaration.GetPropertySymbol(SemanticModel);
var fault = SemanticModel.GetTypeSymbol<Fault>();
if (!symbol.Type.Equals(fault) && !symbol.Type.IsDerivedFrom(fault))
return declaration;
return declaration.WithInitializer(declaration.Initializer.WithValue(AddNameInitializer(fault, objectCreation, symbol.Name)));
}
示例3: VisitPropertyDeclaration
/// <summary>
/// Normalizes the <paramref name="declaration" />.
/// </summary>
public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax declaration)
{
// Nothing to do here for properties without expression bodies
if (declaration.ExpressionBody == null)
return declaration;
// Nothing to do here for properties not defined in fault effects or for properties that are no overrides of some port
var propertySymbol = declaration.GetPropertySymbol(SemanticModel);
if (!propertySymbol.ContainingType.IsFaultEffect(SemanticModel) || !propertySymbol.IsOverride)
return declaration;
var originalDeclaration = declaration;
var statements = AsStatementBody(propertySymbol.GetMethod, declaration.ExpressionBody.Expression);
var getter = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration, statements);
var accessorList = SyntaxFactory.AccessorList(SyntaxFactory.SingletonList(getter));
declaration = declaration.WithAccessorList(accessorList);
declaration = declaration.WithExpressionBody(null).WithSemicolonToken(default(SyntaxToken));
return declaration.EnsureLineCount(originalDeclaration);
}
示例4: VisitPropertyDeclaration
/// <summary>
/// Normalizes the <paramref name="declaration" />.
/// </summary>
public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax declaration)
{
// Nothing to do here for properties with expression bodies
if (declaration.ExpressionBody != null)
return declaration;
// Nothing to do here for properties not defined in fault effects or for properties that are no overrides of some port
var propertySymbol = declaration.GetPropertySymbol(SemanticModel);
if (!propertySymbol.ContainingType.IsFaultEffect(SemanticModel) || !propertySymbol.IsOverride)
return declaration;
// Nothing to do here for required ports
if (propertySymbol.IsExtern)
return declaration;
var getter = (AccessorDeclarationSyntax)Syntax.GetAccessor(declaration, DeclarationKind.GetAccessor);
var setter = (AccessorDeclarationSyntax)Syntax.GetAccessor(declaration, DeclarationKind.SetAccessor);
// Nothing to do here for properties with accessors that have a body
if (getter == null || getter.Body != null || setter?.Body != null)
return declaration;
var fieldName = GetBackingFieldName(propertySymbol);
var fieldIdentifier = (ExpressionSyntax)Syntax.IdentifierName(fieldName);
var fieldModifiers = setter == null
? DeclarationModifiers.Unsafe | DeclarationModifiers.ReadOnly
: DeclarationModifiers.Unsafe;
var fieldDeclaration = Syntax.FieldDeclaration(
name: fieldName,
type: Syntax.TypeExpression(propertySymbol.Type),
accessibility: Accessibility.Private,
modifiers: fieldModifiers,
initializer: declaration.Initializer?.Value);
fieldDeclaration = Syntax.AddAttribute<CompilerGeneratedAttribute>(fieldDeclaration);
fieldDeclaration = Syntax.MarkAsNonDebuggerBrowsable(fieldDeclaration);
AddMembers(propertySymbol.ContainingType, (FieldDeclarationSyntax)fieldDeclaration);
var getterBody = (StatementSyntax)Syntax.ReturnStatement(fieldIdentifier).NormalizeWhitespace();
getterBody = getterBody.AppendLineDirective(-1).PrependLineDirective(-1);
var getterBlock = SyntaxFactory.Block(getterBody).EnsureIndentation(getter).PrependLineDirective(getter.GetLineNumber());
getter = getter.WithStatementBody(getterBlock);
AccessorListSyntax accessors;
if (setter == null)
accessors = declaration.AccessorList.WithAccessors(SyntaxFactory.List(new[] { getter }));
else
{
var assignment = Syntax.AssignmentStatement(fieldIdentifier, Syntax.IdentifierName("value"));
var setterBody = (StatementSyntax)Syntax.ExpressionStatement(assignment);
setterBody = setterBody.AppendLineDirective(-1).PrependLineDirective(-1);
var setterBlock = SyntaxFactory.Block(setterBody).EnsureIndentation(setter).PrependLineDirective(setter.GetLineNumber());
setter = setter.WithStatementBody(setterBlock);
accessors = declaration.AccessorList.WithAccessors(SyntaxFactory.List(new[] { getter, setter }));
}
var originalDeclaration = declaration;
declaration = declaration.WithInitializer(null).WithSemicolonToken(default(SyntaxToken));
return declaration.WithAccessorList(accessors).EnsureLineCount(originalDeclaration);
}