本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.EqualsValueClauseSyntax类的典型用法代码示例。如果您正苦于以下问题:C# EqualsValueClauseSyntax类的具体用法?C# EqualsValueClauseSyntax怎么用?C# EqualsValueClauseSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EqualsValueClauseSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了EqualsValueClauseSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Declaration
public static LocalDeclarationStatementSyntax Declaration(string type, string variableName, EqualsValueClauseSyntax equalsValue)
{
return SyntaxFactory.LocalDeclarationStatement(
SyntaxFactory.VariableDeclaration(Identifier.Name(type))
.WithVariables(Declarator(variableName, equalsValue).AsList()))
.WithSemicolonToken(Token.SemiColon);
}
示例2: PrivateDeclation
public static FieldDeclarationSyntax PrivateDeclation(string type, string variableName, EqualsValueClauseSyntax equalsValue)
{
return SyntaxFactory.FieldDeclaration(Declaration(SyntaxFactory.ParseTypeName(type),
SyntaxFactory.VariableDeclarator(
Identifier.Token(variableName),
null,
equalsValue)))
.WithModifiers(Token.Private.AsList());
}
示例3: MakeLocal
public static SourceLocalSymbol MakeLocal(
MethodSymbol containingMethod,
Binder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
EqualsValueClauseSyntax initializer,
LocalDeclarationKind declarationKind)
{
Debug.Assert(declarationKind != LocalDeclarationKind.ForEach);
return new SourceLocalSymbol(containingMethod, binder, typeSyntax, identifierToken, initializer, null, declarationKind);
}
示例4: MakeLocalWithInitializer
public static SourceLocalSymbol MakeLocalWithInitializer(
Symbol containingSymbol,
Binder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
EqualsValueClauseSyntax initializer,
LocalDeclarationKind declarationKind)
{
Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
return new LocalWithInitializer(containingSymbol, binder, typeSyntax, identifierToken, initializer, declarationKind);
}
示例5: PropertyDeclaration
public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken)
{
return PropertyDeclaration(
attributeLists,
modifiers,
refKeyword: default(SyntaxToken),
type: type,
explicitInterfaceSpecifier: explicitInterfaceSpecifier,
identifier: identifier,
accessorList: accessorList,
expressionBody: expressionBody,
initializer: initializer,
semicolonToken: semicolonToken);
}
示例6: BindFieldOrEnumInitializer
private static BoundExpression BindFieldOrEnumInitializer(
Binder binder,
FieldSymbol fieldSymbol,
EqualsValueClauseSyntax initializer,
DiagnosticBag diagnostics)
{
var enumConstant = fieldSymbol as SourceEnumConstantSymbol;
var collisionDetector = new LocalScopeBinder(binder);
if ((object)enumConstant != null)
{
return collisionDetector.BindEnumConstantInitializer(enumConstant, initializer.Value, diagnostics);
}
else
{
return collisionDetector.BindVariableOrAutoPropInitializer(initializer, fieldSymbol.Type, diagnostics);
}
}
示例7: EvaluateFieldConstant
public static ConstantValue EvaluateFieldConstant(
SourceFieldSymbol symbol,
EqualsValueClauseSyntax equalsValueNode,
HashSet<SourceFieldSymbolWithSyntaxReference> dependencies,
bool earlyDecodingWellKnownAttributes,
DiagnosticBag diagnostics)
{
var compilation = symbol.DeclaringCompilation;
var binderFactory = compilation.GetBinderFactory((SyntaxTree)symbol.Locations[0].SourceTree);
var binder = binderFactory.GetBinder(equalsValueNode);
if (earlyDecodingWellKnownAttributes)
{
binder = new EarlyWellKnownAttributeBinder(binder);
}
var inProgressBinder = new ConstantFieldsInProgressBinder(new ConstantFieldsInProgress(symbol, dependencies), binder);
var boundValue = BindFieldOrEnumInitializer(inProgressBinder, symbol, equalsValueNode, diagnostics);
var initValueNodeLocation = equalsValueNode.Value.Location;
var value = GetAndValidateConstantValue(boundValue, symbol, symbol.Type, initValueNodeLocation, diagnostics);
Debug.Assert(value != null);
return value;
}
示例8: SourceLocalSymbol
private SourceLocalSymbol(
MethodSymbol containingMethod,
Binder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
EqualsValueClauseSyntax initializer,
ExpressionSyntax collection,
LocalDeclarationKind declarationKind)
{
Debug.Assert(identifierToken.CSharpKind() != SyntaxKind.None);
Debug.Assert(declarationKind != LocalDeclarationKind.CompilerGenerated);
this.binder = binder;
this.containingMethod = containingMethod;
this.identifierToken = identifierToken;
this.typeSyntax = typeSyntax;
this.initializer = initializer;
this.collection = collection;
this.declarationKind = declarationKind;
// create this eagerly as it will always be needed for the EnsureSingleDefinition
this.locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
}
示例9: MakeLocal
public static SourceLocalSymbol MakeLocal(
Symbol containingSymbol,
Binder binder,
RefKind refKind,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
LocalDeclarationKind declarationKind,
EqualsValueClauseSyntax initializer = null)
{
Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
if (initializer == null)
{
DeclarationExpressionSyntax declarationExpression;
if (identifierToken.IsIdentifierOfOutVariableDeclaration(out declarationExpression))
{
if (declarationExpression.Type().IsVar)
{
return new PossiblyImplicitlyTypedOutVarLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
}
}
return new SourceLocalSymbol(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind);
}
return new LocalWithInitializer(containingSymbol, binder, refKind, typeSyntax, identifierToken, initializer, declarationKind);
}
示例10: BindFieldInitializer
private static BoundFieldInitializer BindFieldInitializer(Binder binder, FieldSymbol fieldSymbol, EqualsValueClauseSyntax equalsValueClauseNode,
DiagnosticBag diagnostics)
{
Debug.Assert(!fieldSymbol.IsMetadataConstant);
var fieldsBeingBound = binder.FieldsBeingBound;
var sourceField = fieldSymbol as SourceMemberFieldSymbol;
bool isImplicitlyTypedField = (object)sourceField != null && sourceField.FieldTypeInferred(fieldsBeingBound);
// If the type is implicitly typed, the initializer diagnostics have already been reported, so ignore them here:
// CONSIDER (tomat): reusing the bound field initializers for implicitly typed fields.
DiagnosticBag initializerDiagnostics;
if (isImplicitlyTypedField)
{
initializerDiagnostics = DiagnosticBag.GetInstance();
}
else
{
initializerDiagnostics = diagnostics;
}
var collisionDetector = new LocalScopeBinder(binder);
var boundInitValue = collisionDetector.BindVariableOrAutoPropInitializer(equalsValueClauseNode, fieldSymbol.GetFieldType(fieldsBeingBound), initializerDiagnostics);
if (isImplicitlyTypedField)
{
initializerDiagnostics.Free();
}
return new BoundFieldInitializer(
equalsValueClauseNode.Value, //we want the attached sequence point to indicate the value node
fieldSymbol,
boundInitValue);
}
示例11: BindInferredVariableInitializer
// The location where the error is reported might not be the initializer.
internal BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, EqualsValueClauseSyntax initializer,
CSharpSyntaxNode errorSyntax)
{
if (initializer == null)
{
if (!errorSyntax.HasErrors)
{
Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableWithNoInitializer, errorSyntax);
}
return null;
}
if (initializer.Value.Kind() == SyntaxKind.ArrayInitializerExpression)
{
return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)initializer.Value,
diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedArrayInitializer, errorSyntax);
}
BoundExpression expression = BindValue(initializer.Value, diagnostics, BindValueKind.RValue);
// Certain expressions (null literals, method groups and anonymous functions) have no type of
// their own and therefore cannot be the initializer of an implicitly typed local.
if (!expression.HasAnyErrors && !expression.HasExpressionType())
{
MessageID id = MessageID.IDS_NULL;
if (expression.Kind == BoundKind.UnboundLambda)
{
id = ((UnboundLambda)expression).MessageID;
}
else if (expression.Kind == BoundKind.MethodGroup)
{
id = MessageID.IDS_MethodGroup;
}
else
{
Debug.Assert(expression.IsLiteralNull(), "How did we successfully bind an expression without a type?");
}
// Cannot assign {0} to an implicitly-typed local variable
Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, errorSyntax, id.Localize());
}
return expression;
}
示例12: LocateDeclaredVariableSymbol
private SourceLocalSymbol LocateDeclaredVariableSymbol(SyntaxToken identifier, TypeSyntax typeSyntax, EqualsValueClauseSyntax equalsValue)
{
SourceLocalSymbol localSymbol = this.LookupLocal(identifier);
// In error scenarios with misplaced code, it is possible we can't bind the local declaration.
// This occurs through the semantic model. In that case concoct a plausible result.
if ((object)localSymbol == null)
{
localSymbol = SourceLocalSymbol.MakeLocal(
ContainingMemberOrLambda,
this,
false, // do not allow ref
typeSyntax,
identifier,
LocalDeclarationKind.RegularVariable,
equalsValue);
}
return localSymbol;
}
示例13: EqualsValueClauseNotSuitableForVar
private static bool EqualsValueClauseNotSuitableForVar(
SyntaxToken identifier,
TypeSyntax simpleName,
EqualsValueClauseSyntax equalsValueClause,
SemanticModel semanticModel,
CancellationToken cancellationToken)
{
// var cannot be assigned null
if (equalsValueClause.IsKind(SyntaxKind.NullLiteralExpression))
{
return true;
}
var type = semanticModel.GetTypeInfo(simpleName, cancellationToken).Type;
// the variable cannot be initialized to a method group or an anonymous function
if (type != null &&
type.TypeKind == TypeKind.Delegate)
{
return true;
}
var initializerType = semanticModel.GetTypeInfo(equalsValueClause.Value, cancellationToken).Type;
if (!type.Equals(initializerType))
{
return true;
}
// The assign expression in the initializer cannot be the same symbol as the i
var possibleSameLocals = equalsValueClause.DescendantNodesAndSelf().Where(n => n.Kind() == SyntaxKind.IdentifierName && ((IdentifierNameSyntax)n).Identifier.ValueText.Equals(identifier.ValueText));
var anyUse = possibleSameLocals.Any(n =>
{
var symbol = semanticModel.GetSymbolInfo(n, cancellationToken).Symbol;
if (symbol != null && symbol.Kind == SymbolKind.Local)
{
return true;
}
return false;
});
if (anyUse)
{
return true;
}
return false;
}
示例14: BindInferredVariableInitializer
// The location where the error is reported might not be the initializer.
protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, EqualsValueClauseSyntax initializer, BindValueKind valueKind,
CSharpSyntaxNode errorSyntax)
{
if (initializer == null)
{
if (!errorSyntax.HasErrors)
{
Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableWithNoInitializer, errorSyntax);
}
return null;
}
if (initializer.Value.Kind() == SyntaxKind.ArrayInitializerExpression)
{
return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)initializer.Value,
diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedArrayInitializer, errorSyntax);
}
BoundExpression expression = BindValue(initializer.Value, diagnostics, valueKind);
// Certain expressions (null literals, method groups and anonymous functions) have no type of
// their own and therefore cannot be the initializer of an implicitly typed local.
if (!expression.HasAnyErrors && !expression.HasExpressionType())
{
// Cannot assign {0} to an implicitly-typed local variable
Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, errorSyntax, expression.Display);
}
return expression;
}
示例15: LocalWithInitializer
public LocalWithInitializer(
Symbol containingSymbol,
Binder binder,
RefKind refKind,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
EqualsValueClauseSyntax initializer,
LocalDeclarationKind declarationKind) :
base(containingSymbol, binder, refKind, typeSyntax, identifierToken, declarationKind)
{
Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
Debug.Assert(initializer != null);
_initializer = initializer;
// byval locals are always returnable
// byref locals with initializers are assumed not returnable unless proven otherwise
// NOTE: if we assumed returnable, then self-referring initializer could result in
// a randomly changing returnability when initializer is bound concurrently.
_returnable = refKind == RefKind.None;
}