本文整理汇总了C#中VariableDeclaratorSyntax类的典型用法代码示例。如果您正苦于以下问题:C# VariableDeclaratorSyntax类的具体用法?C# VariableDeclaratorSyntax怎么用?C# VariableDeclaratorSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariableDeclaratorSyntax类属于命名空间,在下文中一共展示了VariableDeclaratorSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SourceMemberFieldSymbol
internal SourceMemberFieldSymbol(
SourceMemberContainerTypeSymbol containingType,
VariableDeclaratorSyntax declarator,
DeclarationModifiers modifiers,
bool modifierErrors,
DiagnosticBag diagnostics)
: base(containingType, declarator.Identifier.ValueText, declarator.GetReference(), declarator.Identifier.GetLocation())
{
this.modifiers = modifiers;
this.CheckAccessibility(diagnostics);
var location = Location;
if (modifierErrors)
{
// skip the following checks
}
else if (containingType.IsSealed && (DeclaredAccessibility == Accessibility.Protected || DeclaredAccessibility == Accessibility.ProtectedOrInternal))
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(containingType), location, this);
}
else if (IsVolatile && IsReadOnly)
{
diagnostics.Add(ErrorCode.ERR_VolatileAndReadonly, location, this);
}
else if (containingType.IsStatic && !IsStatic)
{
diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, this);
}
// TODO: Consider checking presence of core type System.Runtime.CompilerServices.IsVolatile
// if there is a volatile modifier. Perhaps an appropriate error should be reported if the
// type isn’t available.
}
开发者ID:riversky,项目名称:roslyn,代码行数:34,代码来源:SourceMemberFieldSymbol.cs
示例2: AddDisposeDeclarationToDisposeMethod
private static TypeDeclarationSyntax AddDisposeDeclarationToDisposeMethod(VariableDeclaratorSyntax variableDeclarator, TypeDeclarationSyntax type, INamedTypeSymbol typeSymbol)
{
var disposableMethod = typeSymbol.GetMembers("Dispose").OfType<IMethodSymbol>().FirstOrDefault(d => d.Arity == 0);
var disposeStatement = SyntaxFactory.ParseStatement($"{variableDeclarator.Identifier.ToString()}.Dispose();");
TypeDeclarationSyntax newType;
if (disposableMethod == null)
{
var disposeMethod = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "Dispose")
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
.WithBody(SyntaxFactory.Block(disposeStatement))
.WithAdditionalAnnotations(Formatter.Annotation);
newType = ((dynamic)type).AddMembers(disposeMethod);
}
else
{
var existingDisposeMethod = (MethodDeclarationSyntax)disposableMethod.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax();
if (type.Members.Contains(existingDisposeMethod))
{
var newDisposeMethod = existingDisposeMethod.AddBodyStatements(disposeStatement)
.WithAdditionalAnnotations(Formatter.Annotation);
newType = type.ReplaceNode(existingDisposeMethod, newDisposeMethod);
}
else
{
//we will simply anotate the code for now, but ideally we would change another document
//for this to work we have to be able to fix more than one doc
var fieldDeclaration = variableDeclarator.Parent.Parent;
var newFieldDeclaration = fieldDeclaration.WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia($"//add {disposeStatement.ToString()} to the Dispose method on another file.").AddRange(fieldDeclaration.GetTrailingTrivia()))
.WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia());
newType = type.ReplaceNode(fieldDeclaration, newFieldDeclaration);
}
}
return newType;
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:34,代码来源:DisposableFieldNotDisposedCodeFixProvider.cs
示例3: VisitVariableDeclarator
/// <summary>
/// Normalizes the <paramref name="declaration" />.
/// </summary>
public override SyntaxNode VisitVariableDeclarator(VariableDeclaratorSyntax declaration)
{
var objectCreation = declaration?.Initializer?.Value as ObjectCreationExpressionSyntax;
if (objectCreation == null)
return declaration;
var symbol = SemanticModel.GetDeclaredSymbol(declaration);
if (symbol == null)
return declaration;
ITypeSymbol type;
string name;
switch (symbol.Kind)
{
case SymbolKind.Field:
var fieldSymbol = ((IFieldSymbol)symbol);
type = fieldSymbol.Type;
name = fieldSymbol.Name;
break;
case SymbolKind.Local:
var localSymbol = ((ILocalSymbol)symbol);
type = localSymbol.Type;
name = localSymbol.Name;
break;
default:
return declaration;
}
var fault = SemanticModel.GetTypeSymbol<Fault>();
if (!type.Equals(fault) && !type.IsDerivedFrom(fault))
return declaration;
return declaration.WithInitializer(declaration.Initializer.WithValue(AddNameInitializer(fault, objectCreation, name)));
}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:38,代码来源:FaultNameNormalizer.cs
示例4: VisitVariableDeclarator
public override SyntaxNode VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
if (node.Identifier.ToString() == renameFrom.ToString())
node = node.WithIdentifier(renameTo);
return base.VisitVariableDeclarator(node);
}
开发者ID:x335,项目名称:WootzJs,代码行数:7,代码来源:IdentifierRenamer.cs
示例5: UseDeclarationExpression
private async Task<Document> UseDeclarationExpression(Document document, ArgumentSyntax argument, VariableDeclaratorSyntax declarator,
CancellationToken cancellationToken)
{
// get variable declaration
var declaration = declarator.Parent;
// get statement which contains both local declaration statement and method call with out argument
var statement = DiagnosticAnalyzer.GetContainingStatement(declaration.Parent);
// remove entire local declaration statement or just single variable declaration
// depending on how many variables are declared within single local declaration statement
var nodeToRemove = declaration.ChildNodes().OfType<VariableDeclaratorSyntax>().Count() > 1 ? declarator : declaration.Parent;
var newStatement = statement.RemoveNode(nodeToRemove, SyntaxRemoveOptions.KeepEndOfLine);
// get variable type
var type = declaration.ChildNodes().First() as TypeSyntax;
// create new Declaration Expression using variable type and declarator
var newDeclarationExpression = SyntaxFactory.DeclarationExpression(type, declarator);
// fix the trivia aroung Declaration Expression
var firstToken = newDeclarationExpression.GetFirstToken();
var leadingTrivia = firstToken.LeadingTrivia;
var trimmedDeclarationExpression = newDeclarationExpression.ReplaceToken(firstToken, firstToken.WithLeadingTrivia(SyntaxTriviaList.Empty));
// get ArgumentSyntax from newStatement which is equivalent to argument from original syntax tree
var newArgument = newStatement.DescendantNodes()
.FirstOrDefault(n => n.IsEquivalentTo(argument));
// replace argument with new version, containing Declaration Expression
newStatement = newStatement.ReplaceNode(newArgument.ChildNodes().First(), trimmedDeclarationExpression);
// get root for current document and replace statement with new version
var root = await document.GetSyntaxRootAsync(cancellationToken);
var newRoot = root.ReplaceNode(statement, newStatement);
// return document with modified syntax
return document.WithSyntaxRoot(newRoot);
}
开发者ID:JorisR,项目名称:RoslynCodeFixDemo,代码行数:35,代码来源:CodeFixProvider.cs
示例6: FieldMemberBuilder
internal FieldMemberBuilder(NamedTypeSymbol owner, Binder enclosing, FieldDeclarationSyntax declaration, TypeSymbol type, VariableDeclaratorSyntax declarator)
: base(enclosing.Location(declarator) as SourceLocation, owner, enclosing)
{
this.owner = owner;
this.declaration = declaration;
this.declarator = declarator;
this.Type = type;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:8,代码来源:FieldMemberBuilder.cs
示例7: CompileDefaultInitialization
protected override void CompileDefaultInitialization(VariableDeclaratorSyntax declarator, TypeSyntax type)
{
Write("=");
Write(Space);
Write("(");
CompileExpression(type);
Write(")0");
}
开发者ID:JohnFNovak,项目名称:FragSharp,代码行数:8,代码来源:HlslWriter.cs
示例8: VisitVariableDeclarator
public override SyntaxNode VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
var substitution = result.Find(node);
return substitution != null
? substitution.Substitute()
: base.VisitVariableDeclarator(node);
}
开发者ID:jthelin,项目名称:Nake,代码行数:8,代码来源:Rewriter.cs
示例9: FlowsIntoTarget
/// <summary>
/// Returns true if the given expression flows in the target.
/// </summary>
/// <param name="variable">Variable</param>
/// <param name="target">Target</param>
/// <param name="syntaxNode">SyntaxNode</param>
/// <param name="cfgNode">ControlFlowGraphNode</param>
/// <param name="targetSyntaxNode">Target syntaxNode</param>
/// <param name="targetCfgNode">Target controlFlowGraphNode</param>
/// <param name="model">SemanticModel</param>
/// <returns>Boolean</returns>
internal static bool FlowsIntoTarget(VariableDeclaratorSyntax variable, ISymbol target,
SyntaxNode syntaxNode, ControlFlowGraphNode cfgNode, SyntaxNode targetSyntaxNode,
ControlFlowGraphNode targetCfgNode, SemanticModel model)
{
ISymbol reference = model.GetDeclaredSymbol(variable);
return DataFlowAnalysis.FlowsIntoTarget(reference, target, syntaxNode,
cfgNode, targetSyntaxNode, targetCfgNode);
}
开发者ID:huangpf,项目名称:PSharp,代码行数:19,代码来源:DataFlowAnalysis.cs
示例10: TypeChecks
private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax, VariableDeclaratorSyntax declarator, DiagnosticBag diagnostics)
{
if (type.IsStatic)
{
// Cannot declare a variable of static type '{0}'
diagnostics.Add(ErrorCode.ERR_VarDeclIsStaticClass, this.Location, type);
}
else if (type.SpecialType == SpecialType.System_Void)
{
diagnostics.Add(ErrorCode.ERR_FieldCantHaveVoidType, fieldSyntax.Declaration.Type.Location);
}
else if (type.IsRestrictedType())
{
diagnostics.Add(ErrorCode.ERR_FieldCantBeRefAny, fieldSyntax.Declaration.Type.Location, type);
}
else if (IsConst && !type.CanBeConst())
{
SyntaxToken constToken = default(SyntaxToken);
foreach (var modifier in fieldSyntax.Modifiers)
{
if (modifier.CSharpKind() == SyntaxKind.ConstKeyword)
{
constToken = modifier;
break;
}
}
Debug.Assert(constToken.CSharpKind() == SyntaxKind.ConstKeyword);
diagnostics.Add(ErrorCode.ERR_BadConstType, constToken.GetLocation(), type);
}
else
{
if (ContainingType.TypeKind == TypeKind.Struct && !IsStatic && !IsConst)
{
var initializerOpt = declarator.Initializer;
if (initializerOpt != null)
{
// '{0}': cannot have instance field initializers in structs
diagnostics.Add(ErrorCode.ERR_FieldInitializerInStruct, this.Location, this);
}
}
if (IsVolatile && !type.IsValidVolatileFieldType())
{
// '{0}': a volatile field cannot be of the type '{1}'
diagnostics.Add(ErrorCode.ERR_VolatileStruct, this.Location, this, type);
}
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (!this.IsNoMoreVisibleThan(type, ref useSiteDiagnostics))
{
// Inconsistent accessibility: field type '{1}' is less accessible than field '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisFieldType, this.Location, this, type);
}
diagnostics.Add(this.Location, useSiteDiagnostics);
}
开发者ID:riversky,项目名称:roslyn,代码行数:58,代码来源:SourceMemberFieldSymbol.cs
示例11: AddSequencePoint
internal static BoundStatement AddSequencePoint(VariableDeclaratorSyntax declaratorSyntax, BoundStatement rewrittenStatement)
{
SyntaxNode node;
TextSpan? part;
GetBreakpointSpan(declaratorSyntax, out node, out part);
var result = BoundSequencePoint.Create(declaratorSyntax, part, rewrittenStatement);
result.WasCompilerGenerated = rewrittenStatement.WasCompilerGenerated;
return result;
}
开发者ID:riversky,项目名称:roslyn,代码行数:9,代码来源:LocalRewriter_SequencePoints.cs
示例12: GetDescription
public static string GetDescription(this VariableDeclarationSyntax declaration, VariableDeclaratorSyntax declarator)
{
var result = new StringBuilder();
result.Append(declaration.Type.ToStringIgnoringMacroReferences());
result.Append(" ");
result.Append(declarator.Identifier.GetFullyQualifiedName());
return result.ToString().Replace(Environment.NewLine, string.Empty);
}
开发者ID:pminiszewski,项目名称:HlslTools,代码行数:10,代码来源:SyntaxExtensions.cs
示例13: GetSimpleProperty
private static PropertyDeclarationSyntax GetSimpleProperty(PropertyDeclarationSyntax property, VariableDeclaratorSyntax variableDeclarator)
{
var simpleGetSetPropetie = property.WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List(new[] {
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
})));
return variableDeclarator.Initializer == null ?
simpleGetSetPropetie :
simpleGetSetPropetie.WithInitializer(variableDeclarator.Initializer)
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:SwitchToAutoPropCodeFixProvider.cs
示例14: VisitVariableDeclarator
public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
if (node.Ancestors().Any(x => x is FunctionDefinitionSyntax))
CreateTag(node.Identifier, _classificationService.LocalVariableIdentifier);
else if (node.Ancestors().Any(x => x is TypeDefinitionSyntax))
CreateTag(node.Identifier, _classificationService.FieldIdentifier);
else
CreateTag(node.Identifier, _classificationService.GlobalVariableIdentifier);
base.VisitVariableDeclarator(node);
}
开发者ID:pminiszewski,项目名称:HlslTools,代码行数:11,代码来源:SemanticTaggerVisitor.cs
示例15: MakeParameterAsync
private async Task<Document> MakeParameterAsync(Document document, VariableDeclaratorSyntax typeDecl, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken);
string varKeyword = string.Empty, varName = string.Empty;
//Predefined variable type (string, int, etc...)
var preDefType = typeDecl.Parent.ChildNodes().OfType<PredefinedTypeSyntax>().FirstOrDefault();
if (preDefType != null)
{
varKeyword = preDefType.Keyword.ToString();
var varDecl = typeDecl.Parent.ChildNodes().OfType<VariableDeclaratorSyntax>().FirstOrDefault();
varName = varDecl?.Identifier.ToString();
}
else //var
{
var identName = typeDecl.Parent.ChildNodes().OfType<IdentifierNameSyntax>().FirstOrDefault();
//Access the semantic model to determine actual type
var model = document.GetSemanticModelAsync().Result;
var type = model.GetTypeInfo(identName).Type;
varKeyword = type.ToMinimalDisplayString(model, typeDecl.SpanStart);
var varDecl = typeDecl.Parent.ChildNodes().OfType<VariableDeclaratorSyntax>().FirstOrDefault();
varName = varDecl?.Identifier.ToString();
}
MethodDeclarationSyntax mds = typeDecl.Ancestors().OfType<MethodDeclarationSyntax>().FirstOrDefault();
//Add the existing and new parameters
ParameterSyntax ps = SyntaxFactory.Parameter(SyntaxFactory.Identifier(string.Concat(varKeyword, " ", varName)));
var newList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList<ParameterSyntax>().AddRange(
mds.ParameterList.ChildNodes().OfType<ParameterSyntax>()).Add(ps));
var methodNode = typeDecl.Ancestors().OfType<MethodDeclarationSyntax>().FirstOrDefault();
var variableNode = typeDecl.Parent.Parent;
var variableParentNode = typeDecl.Parent.Parent.Parent;
//Track the nodes we'll be using
var newRoot = root.TrackNodes(methodNode, variableNode, variableParentNode);
//Remode/replace the variable declaration
var trackedVariableParentNode = newRoot.GetCurrentNode(variableParentNode);
var trackedVariableNode = newRoot.GetCurrentNode(variableNode);
var newVariableParentNode = trackedVariableParentNode.RemoveNode(trackedVariableNode, SyntaxRemoveOptions.KeepNoTrivia);
newRoot = newRoot.ReplaceNode(trackedVariableParentNode, newVariableParentNode);
//Replace the method parameters
var trackedMethodNode = newRoot.GetCurrentNode(methodNode);
var newMethodNode = trackedMethodNode.ReplaceNode(trackedMethodNode.ParameterList, newList);
newRoot = newRoot.ReplaceNode(trackedMethodNode, newMethodNode);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:modulexcite,项目名称:GoingBeyondReSharperWithRoslyn_Demo,代码行数:53,代码来源:CodeRefactoringProvider.cs
示例16: SourceFixedFieldSymbol
internal SourceFixedFieldSymbol(
SourceMemberContainerTypeSymbol containingType,
VariableDeclaratorSyntax declarator,
DeclarationModifiers modifiers,
bool modifierErrors,
DiagnosticBag diagnostics)
: base(containingType, declarator, modifiers, modifierErrors, diagnostics)
{
// Checked in parser: a fixed field declaration requires a length in square brackets
Debug.Assert(this.IsFixed);
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:12,代码来源:SourceFixedFieldSymbol.cs
示例17: ReferenceRewriter
private ReferenceRewriter(
SemanticModel semanticModel,
VariableDeclaratorSyntax variableDeclarator,
ExpressionSyntax expressionToInline,
CancellationToken cancellationToken)
{
_semanticModel = semanticModel;
_localSymbol = (ILocalSymbol)semanticModel.GetDeclaredSymbol(variableDeclarator, cancellationToken);
_variableDeclarator = variableDeclarator;
_expressionToInline = expressionToInline;
_cancellationToken = cancellationToken;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:12,代码来源:InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs
示例18: VisitVariableDeclarator
public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
if (node.ArgumentList != null)
{
foreach (var arg in node.ArgumentList.Arguments)
{
Visit(arg.Expression);
}
}
VisitNodeToBind(node.Initializer);
}
开发者ID:natidea,项目名称:roslyn,代码行数:12,代码来源:ExpressionVariableFinder.cs
示例19: MakeMultipleFieldsReadonly
private static SyntaxNode MakeMultipleFieldsReadonly(SyntaxNode root, FieldDeclarationSyntax fieldDeclaration, VariableDeclaratorSyntax variableToMakeReadonly)
{
var newDeclaration = fieldDeclaration.Declaration.RemoveNode(variableToMakeReadonly, SyntaxRemoveOptions.KeepEndOfLine);
var newFieldDeclaration = fieldDeclaration.WithDeclaration(newDeclaration);
var newReadonlyFieldDeclaration = fieldDeclaration.WithDeclaration(SyntaxFactory.VariableDeclaration(fieldDeclaration.Declaration.Type, SyntaxFactory.SeparatedList(new[] { variableToMakeReadonly })))
.WithoutLeadingTrivia()
.WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia("\n"))
.AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword))
.WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(fieldDeclaration, new[] { newFieldDeclaration, newReadonlyFieldDeclaration });
return newRoot;
}
开发者ID:nagyistoce,项目名称:code-cracker,代码行数:12,代码来源:ReadonlyFieldCodeFixProvider.cs
示例20: VisitVariableDeclarator
public override SyntaxNode VisitVariableDeclarator(VariableDeclaratorSyntax variable)
{
// Retrieve the symbol for the variable declarator
var field = variable.Parent.Parent as FieldDeclarationSyntax;
if (field != null && field.Declaration.Variables.Count == 1)
{
if (object.Equals(semanticModel.GetDeclaredSymbol(variable), backingField))
{
return null;
}
}
return variable;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:14,代码来源:PropertyRewriter.cs
注:本文中的VariableDeclaratorSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论