本文整理匯總了C#中BasePropertyDeclarationSyntax類的典型用法代碼示例。如果您正苦於以下問題:C# BasePropertyDeclarationSyntax類的具體用法?C# BasePropertyDeclarationSyntax怎麽用?C# BasePropertyDeclarationSyntax使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasePropertyDeclarationSyntax類屬於命名空間,在下文中一共展示了BasePropertyDeclarationSyntax類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CheckForFormat
public static void CheckForFormat(NeosSdiMef neosSdiMef, CodingRule rule, BasePropertyDeclarationSyntax _property, string text, string textFull, int spanStart, int spanEnd)
{
switch (rule.RuleCase)
{
case CodingRuleCaseEnum.UpperCamelCase:
string upperText = rule.RuleFirstLetter + text.UpperCamelCase();
if (text != upperText)
{
neosSdiMef.AddDecorationError(_property, textFull, "Replace " + text + " by " + upperText, () =>
{
var span = Span.FromBounds(spanStart, spanEnd);
neosSdiMef._textView.TextBuffer.Replace(span, upperText);
});
}
break;
case CodingRuleCaseEnum.LowerCamelCase:
string lowerText = rule.RuleFirstLetter + text.LowerCamelCase();
if (text != lowerText)
{
neosSdiMef.AddDecorationError(_property, textFull, "Replace " + text + " by " + lowerText, () =>
{
var span = Span.FromBounds(spanStart, spanEnd);
neosSdiMef._textView.TextBuffer.Replace(span, lowerText);
});
}
break;
default:
break;
}
}
示例2: ApplyFix
private static async Task<Document> ApplyFix(
Document document
, BaseTypeSyntax derivingClass
, BasePropertyDeclarationSyntax viewModelProperty
, CancellationToken cancellationToken)
{
var genericClassDeclaration = SyntaxFactory.SimpleBaseType(
SyntaxFactory.GenericName(
SyntaxFactory.Identifier(
derivingClass.Type.ToString()
)
)
.WithTypeArgumentList(
SyntaxFactory.TypeArgumentList(
SyntaxFactory.SingletonSeparatedList(viewModelProperty.Type)
)
)
).WithAdditionalAnnotations(Formatter.Annotation);
var editor = await DocumentEditor.CreateAsync(document, cancellationToken);
editor.RemoveNode(viewModelProperty);
editor.ReplaceNode(derivingClass, genericClassDeclaration);
return editor.GetChangedDocument();
}
示例3: AddDecorationError
public void AddDecorationError(BasePropertyDeclarationSyntax _property, string textFull, string toolTipText, FixErrorCallback errorCallback)
{
var lineSpan = tree.GetLineSpan(_property.Span, usePreprocessorDirectives: false);
int lineNumber = lineSpan.StartLinePosition.Line;
var line = _textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
var textViewLine = _textView.GetTextViewLineContainingBufferPosition(line.Start);
int startSpace = textFull.Length - textFull.TrimStart().Length;
int endSpace = textFull.Length - textFull.TrimEnd().Length;
SnapshotSpan span = new SnapshotSpan(_textView.TextSnapshot, Span.FromBounds(line.Start.Position + startSpace, line.End.Position - endSpace));
Geometry g = _textView.TextViewLines.GetMarkerGeometry(span);
if (g != null)
{
rects.Add(g.Bounds);
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//image.Visibility = Visibility.Hidden;
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, (t, ui) =>
{
rects.Remove(g.Bounds);
});
DrawIcon(span, g.Bounds.Left - 30, g.Bounds.Top, toolTipText, errorCallback);
}
}
示例4: HasBothAccessors
private static bool HasBothAccessors(BasePropertyDeclarationSyntax property)
{
var accessors = property.AccessorList.Accessors;
var getter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration);
var setter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.SetAccessorDeclaration);
return getter?.Body?.Statements.Count == 1 && setter?.Body?.Statements.Count == 1;
}
示例5: BasePropertyDeclarationTranslation
public BasePropertyDeclarationTranslation(BasePropertyDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Type = syntax.Type.Get<TypeTranslation>(this);
AccessorList = syntax.AccessorList.Get<AccessorListTranslation>(this);
Modifiers = syntax.Modifiers.Get(this);
AccessorList.SetModifier(Modifiers);
}
示例6: HasBothAccessors
/// <summary>
/// Returns true if both get and set accessors exist on the given property; otherwise false.
/// </summary>
private static bool HasBothAccessors(BasePropertyDeclarationSyntax property)
{
var accessors = property.AccessorList.Accessors;
var getter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration);
var setter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.SetAccessorDeclaration);
if (getter != null && setter != null)
{
// The getter and setter should have a body.
return getter.Body != null && setter.Body != null;
}
return false;
}
示例7: ConvertToExpressionBodiedMemberAsync
private static async Task<Document> ConvertToExpressionBodiedMemberAsync(Document document, BasePropertyDeclarationSyntax declaration, CancellationToken cancellationToken)
{
var accessors = declaration.AccessorList.Accessors;
var body = accessors[0].Body;
var returnStatement = body.Statements[0] as ReturnStatementSyntax;
var arrowExpression = SyntaxFactory.ArrowExpressionClause(
returnStatement.Expression);
var newDeclaration = declaration;
newDeclaration = ((dynamic)declaration)
.WithAccessorList(null)
.WithExpressionBody(arrowExpression)
.WithSemicolon(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
newDeclaration = newDeclaration.WithAdditionalAnnotations(Formatter.Annotation);
return await ReplaceNodeAsync(document, declaration, newDeclaration, cancellationToken);
}
示例8: AnalyzeProperty
private static void AnalyzeProperty(SyntaxNodeAnalysisContext context, BasePropertyDeclarationSyntax propertyDeclaration)
{
if (propertyDeclaration?.AccessorList == null)
{
return;
}
var accessors = propertyDeclaration.AccessorList.Accessors;
if (propertyDeclaration.AccessorList.IsMissing ||
accessors.Count != 2)
{
return;
}
if (accessors[0].Kind() == SyntaxKind.SetAccessorDeclaration &&
accessors[1].Kind() == SyntaxKind.GetAccessorDeclaration)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, accessors[0].GetLocation()));
}
}
示例9: GetDeclaredSymbol
public override ISymbol GetDeclaredSymbol(BasePropertyDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
// Can't define property inside member.
return null;
}
示例10: GetEndPoint
private VirtualTreePoint GetEndPoint(SourceText text, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
{
int endPosition;
switch (part)
{
case EnvDTE.vsCMPart.vsCMPartName:
case EnvDTE.vsCMPart.vsCMPartAttributes:
case EnvDTE.vsCMPart.vsCMPartHeader:
case EnvDTE.vsCMPart.vsCMPartWhole:
case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
throw Exceptions.ThrowENotImpl();
case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
if (node.AttributeLists.Count == 0)
{
throw Exceptions.ThrowEFail();
}
endPosition = node.AttributeLists.Last().Span.End;
break;
case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
endPosition = node.Span.End;
break;
case EnvDTE.vsCMPart.vsCMPartNavigate:
var firstAccessorNode = FindFirstAccessorNode(node);
if (firstAccessorNode != null)
{
if (firstAccessorNode.Body != null)
{
return GetBodyEndPoint(text, firstAccessorNode.Body.CloseBraceToken);
}
else
{
// This is total weirdness from the old C# code model with auto props.
// If there isn't a body, the semi-colon is used
return GetBodyEndPoint(text, firstAccessorNode.SemicolonToken);
}
}
throw Exceptions.ThrowEFail();
case EnvDTE.vsCMPart.vsCMPartBody:
if (node.AccessorList != null && !node.AccessorList.CloseBraceToken.IsMissing)
{
return GetBodyEndPoint(text, node.AccessorList.CloseBraceToken);
}
throw Exceptions.ThrowEFail();
default:
throw Exceptions.ThrowEInvalidArg();
}
return new VirtualTreePoint(node.SyntaxTree, text, endPosition);
}
示例11: IsNotPublicModifier
private static bool IsNotPublicModifier(BasePropertyDeclarationSyntax property, string modifier)
{
return property.Modifiers.Any(x => string.Compare(x.Text, modifier, StringComparison.InvariantCultureIgnoreCase) == 0);
}
示例12: RegisterPropertyLikeDeclarationCodeFix
private SyntaxNode RegisterPropertyLikeDeclarationCodeFix(SyntaxNode syntaxRoot, BasePropertyDeclarationSyntax node, IndentationOptions indentationOptions)
{
return this.ReformatElement(syntaxRoot, node, node.AccessorList.OpenBraceToken, node.AccessorList.CloseBraceToken, indentationOptions);
}
示例13: SourcePropertySymbol
// CONSIDER: if the parameters were computed lazily, ParameterCount could be overridden to fall back on the syntax (as in SourceMemberMethodSymbol).
private SourcePropertySymbol(
SourceMemberContainerTypeSymbol containingType,
Binder bodyBinder,
BasePropertyDeclarationSyntax syntax,
string name,
Location location,
DiagnosticBag diagnostics)
{
// This has the value that IsIndexer will ultimately have, once we've populated the fields of this object.
bool isIndexer = syntax.Kind() == SyntaxKind.IndexerDeclaration;
var interfaceSpecifier = GetExplicitInterfaceSpecifier(syntax);
bool isExplicitInterfaceImplementation = (interfaceSpecifier != null);
_location = location;
_containingType = containingType;
_syntaxRef = syntax.GetReference();
SyntaxTokenList modifiers = syntax.Modifiers;
bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers);
bodyBinder = bodyBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.SuppressConstraintChecks, this);
bool modifierErrors;
_modifiers = MakeModifiers(modifiers, isExplicitInterfaceImplementation, isIndexer, location, diagnostics, out modifierErrors);
this.CheckAccessibility(location, diagnostics);
this.CheckModifiers(location, isIndexer, diagnostics);
if (isIndexer && !isExplicitInterfaceImplementation)
{
// Evaluate the attributes immediately in case the IndexerNameAttribute has been applied.
// NOTE: we want IsExplicitInterfaceImplementation, IsOverride, Locations, and the syntax reference
// to be initialized before we pass this symbol to LoadCustomAttributes.
// CONSIDER: none of the information from this early binding pass is cached. Everything will
// be re-bound when someone calls GetAttributes. If this gets to be a problem, we could
// always use the real attribute bag of this symbol and modify LoadAndValidateAttributes to
// handle partially filled bags.
CustomAttributesBag<CSharpAttributeData> temp = null;
LoadAndValidateAttributes(OneOrMany.Create(this.CSharpSyntaxNode.AttributeLists), ref temp, earlyDecodingOnly: true);
if (temp != null)
{
Debug.Assert(temp.IsEarlyDecodedWellKnownAttributeDataComputed);
var propertyData = (PropertyEarlyWellKnownAttributeData)temp.EarlyDecodedWellKnownAttributeData;
if (propertyData != null)
{
_sourceName = propertyData.IndexerName;
}
}
}
string aliasQualifierOpt;
string memberName = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(bodyBinder, interfaceSpecifier, name, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt);
_sourceName = _sourceName ?? memberName; //sourceName may have been set while loading attributes
_name = isIndexer ? ExplicitInterfaceHelpers.GetMemberName(WellKnownMemberNames.Indexer, _explicitInterfaceType, aliasQualifierOpt) : _sourceName;
_isExpressionBodied = false;
bool hasAccessorList = syntax.AccessorList != null;
var propertySyntax = syntax as PropertyDeclarationSyntax;
var arrowExpression = propertySyntax != null
? propertySyntax.ExpressionBody
: ((IndexerDeclarationSyntax)syntax).ExpressionBody;
bool hasExpressionBody = arrowExpression != null;
bool hasInitializer = !isIndexer && propertySyntax.Initializer != null;
bool notRegularProperty = (!IsAbstract && !IsExtern && !isIndexer && hasAccessorList);
AccessorDeclarationSyntax getSyntax = null;
AccessorDeclarationSyntax setSyntax = null;
if (hasAccessorList)
{
foreach (var accessor in syntax.AccessorList.Accessors)
{
if (accessor.Kind() == SyntaxKind.GetAccessorDeclaration &&
(getSyntax == null || getSyntax.Keyword.Span.IsEmpty))
{
getSyntax = accessor;
}
else if (accessor.Kind() == SyntaxKind.SetAccessorDeclaration &&
(setSyntax == null || setSyntax.Keyword.Span.IsEmpty))
{
setSyntax = accessor;
}
else
{
continue;
}
if (accessor.Body != null)
{
notRegularProperty = false;
}
}
}
else
{
notRegularProperty = false;
}
if (hasInitializer)
//.........這裏部分代碼省略.........
示例14: GetExplicitInterfaceSpecifier
private static ExplicitInterfaceSpecifierSyntax GetExplicitInterfaceSpecifier(BasePropertyDeclarationSyntax syntax)
{
switch (syntax.Kind())
{
case SyntaxKind.PropertyDeclaration:
return ((PropertyDeclarationSyntax)syntax).ExplicitInterfaceSpecifier;
case SyntaxKind.IndexerDeclaration:
return ((IndexerDeclarationSyntax)syntax).ExplicitInterfaceSpecifier;
default:
throw ExceptionUtilities.UnexpectedValue(syntax.Kind());
}
}
示例15: ComputeType
private TypeSymbol ComputeType(Binder binder, BasePropertyDeclarationSyntax syntax, DiagnosticBag diagnostics)
{
var type = binder.BindType(syntax.Type, diagnostics);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (!this.IsNoMoreVisibleThan(type, ref useSiteDiagnostics))
{
// "Inconsistent accessibility: indexer return type '{1}' is less accessible than indexer '{0}'"
// "Inconsistent accessibility: property type '{1}' is less accessible than property '{0}'"
diagnostics.Add((this.IsIndexer ? ErrorCode.ERR_BadVisIndexerReturn : ErrorCode.ERR_BadVisPropertyType), _location, this, type);
}
diagnostics.Add(_location, useSiteDiagnostics);
if (type.SpecialType == SpecialType.System_Void)
{
ErrorCode errorCode = this.IsIndexer ? ErrorCode.ERR_IndexerCantHaveVoidType : ErrorCode.ERR_PropertyCantHaveVoidType;
diagnostics.Add(errorCode, _location, this);
}
return type;
}