本文整理汇总了C#中AttributeArgumentSyntax类的典型用法代码示例。如果您正苦于以下问题:C# AttributeArgumentSyntax类的具体用法?C# AttributeArgumentSyntax怎么用?C# AttributeArgumentSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeArgumentSyntax类属于命名空间,在下文中一共展示了AttributeArgumentSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttributeArgument
public static string AttributeArgument(AttributeArgumentSyntax arg)
{
var output = SyntaxNode(arg.Expression);
if (arg.NameColon != null)
{
output = SyntaxNode(arg.NameColon.Name) + ": " + output;
}
return output;
}
示例2: Delete
private Document Delete(Document document, AttributeArgumentSyntax node)
{
var argumentList = node.FirstAncestorOrSelf<AttributeArgumentListSyntax>();
var newArgumentList = argumentList.RemoveNode(node, SyntaxRemoveOptions.KeepNoTrivia);
return document.ReplaceNodeAsync(argumentList, newArgumentList, CancellationToken.None)
.WaitAndGetResult_CodeModel(CancellationToken.None);
}
示例3: AttributeArgument
/// <summary>
/// Initializes a new instance of the <see cref="AttributeArgument"/> class.
/// </summary>
/// <param name="syntaxNode"></param>
/// <param name="kind"></param>
/// <remarks>
/// When providing the semantic model, some properites will be devised from that.
/// </remarks>
public AttributeArgument(AttributeArgumentSyntax syntaxNode, SemanticModel semanticModel)
: base(syntaxNode, semanticModel)
{
}
示例4: GetEndPoint
private VirtualTreePoint GetEndPoint(SourceText text, AttributeArgumentSyntax 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:
case EnvDTE.vsCMPart.vsCMPartBody:
case EnvDTE.vsCMPart.vsCMPartNavigate:
throw Exceptions.ThrowEFail();
case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
endPosition = node.Span.End;
break;
default:
throw Exceptions.ThrowEInvalidArg();
}
return new VirtualTreePoint(node.SyntaxTree, text, endPosition);
}
示例5: InferTypeInAttributeArgument
private IEnumerable<ITypeSymbol> InferTypeInAttributeArgument(
int index,
IEnumerable<ImmutableArray<IParameterSymbol>> parameterizedSymbols,
AttributeArgumentSyntax argumentOpt = null)
{
if (argumentOpt != null && argumentOpt.NameEquals != null)
{
// [MyAttribute(Prop = ...
return InferTypeInNameEquals(argumentOpt.NameEquals, argumentOpt.NameEquals.EqualsToken);
}
var name = argumentOpt != null && argumentOpt.NameColon != null ? argumentOpt.NameColon.Name.Identifier.ValueText : null;
return InferTypeInArgument(index, parameterizedSymbols, name);
}
示例6: VisitAttributeArgument
/// <summary>
///
/// </summary>
/// <param name="node"></param>
public override sealed void VisitAttributeArgument(AttributeArgumentSyntax node)
{
this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
base.VisitAttributeArgument(node);
}
示例7: BindNamedAttributeArgumentType
private TypeSymbol BindNamedAttributeArgumentType(AttributeArgumentSyntax namedArgument, Symbol namedArgumentNameSymbol, NamedTypeSymbol attributeType, DiagnosticBag diagnostics)
{
if (namedArgumentNameSymbol.Kind == SymbolKind.ErrorType)
{
return (TypeSymbol)namedArgumentNameSymbol;
}
// SPEC: For each named-argument Arg in named-argument-list N:
// SPEC: Let Name be the identifier of the named-argument Arg.
// SPEC: Name must identify a non-static read-write public field or property on
// SPEC: attribute class T. If T has no such field or property, then a compile-time error occurs.
bool invalidNamedArgument = false;
TypeSymbol namedArgumentType = null;
invalidNamedArgument |= (namedArgumentNameSymbol.DeclaredAccessibility != Accessibility.Public);
invalidNamedArgument |= namedArgumentNameSymbol.IsStatic;
if (!invalidNamedArgument)
{
switch (namedArgumentNameSymbol.Kind)
{
case SymbolKind.Field:
var fieldSymbol = (FieldSymbol)namedArgumentNameSymbol;
namedArgumentType = fieldSymbol.Type;
invalidNamedArgument |= fieldSymbol.IsReadOnly;
invalidNamedArgument |= fieldSymbol.IsConst;
break;
case SymbolKind.Property:
var propertySymbol = ((PropertySymbol)namedArgumentNameSymbol).GetLeastOverriddenProperty(this.ContainingType);
namedArgumentType = propertySymbol.Type;
invalidNamedArgument |= propertySymbol.IsReadOnly;
var getMethod = propertySymbol.GetMethod;
var setMethod = propertySymbol.SetMethod;
invalidNamedArgument = invalidNamedArgument || (object)getMethod == null || (object)setMethod == null;
if (!invalidNamedArgument)
{
invalidNamedArgument =
getMethod.DeclaredAccessibility != Accessibility.Public ||
setMethod.DeclaredAccessibility != Accessibility.Public;
}
break;
default:
invalidNamedArgument = true;
break;
}
}
if (invalidNamedArgument)
{
return new ExtendedErrorTypeSymbol(attributeType,
namedArgumentNameSymbol,
LookupResultKind.NotAVariable,
diagnostics.Add(ErrorCode.ERR_BadNamedAttributeArgument,
namedArgument.NameEquals.Name.Location,
namedArgumentNameSymbol.Name));
}
if (!namedArgumentType.IsValidAttributeParameterType(Compilation))
{
return new ExtendedErrorTypeSymbol(attributeType,
namedArgumentNameSymbol,
LookupResultKind.NotAVariable,
diagnostics.Add(ErrorCode.ERR_BadNamedAttributeArgumentType,
namedArgument.NameEquals.Name.Location,
namedArgumentNameSymbol.Name));
}
return namedArgumentType;
}
示例8: Create
public static IUnifiedArgumentSyntax Create(AttributeArgumentSyntax argument)
{
return new UnifiedArgumentSyntax(argument);
}
示例9: UpdateValueOfArgumentAsync
private static Task<Document> UpdateValueOfArgumentAsync(Document document, SyntaxNode root, AttributeArgumentSyntax argument)
{
var newArgument = argument.WithExpression(GetNewAttributeValue());
return Task.FromResult(document.WithSyntaxRoot(root.ReplaceNode(argument, newArgument)));
}
示例10: VisitAttributeArgument
public override void VisitAttributeArgument(AttributeArgumentSyntax node)
{
var saveCurrentScope = currentScope;
currentScope = new DeclarationScope(saveCurrentScope);
Visit(node.Expression);
Debug.Assert(currentScope.Parent == saveCurrentScope);
currentScope = saveCurrentScope;
}
示例11: GetLiteral
private string GetLiteral(AttributeArgumentSyntax argument, SemanticModel semanticModel)
{
var literal = argument.Expression.GetLiteral(semanticModel);
// Literal would be wrapped in double quotes, removing them
return literal.Substring(1, literal.Length - 2);
}
示例12: VisitAttributeArgument
public void VisitAttributeArgument(AttributeArgumentSyntax node)
{
if (node == null)
throw new ArgumentNullException("node");
node.Validate();
if (node.NameColon != null)
node.NameColon.Accept(this);
if (node.NameEquals != null)
node.NameEquals.Accept(this);
node.Expression.Accept(this);
}
示例13: BindNamedAttributeArgument
private BoundExpression BindNamedAttributeArgument(AttributeArgumentSyntax namedArgument, NamedTypeSymbol attributeType, DiagnosticBag diagnostics)
{
bool wasError;
LookupResultKind resultKind;
Symbol namedArgumentNameSymbol = BindNamedAttributeArgumentName(namedArgument, attributeType, diagnostics, out wasError, out resultKind);
ReportDiagnosticsIfObsolete(diagnostics, namedArgumentNameSymbol, namedArgument, hasBaseReceiver: false);
Debug.Assert(resultKind == LookupResultKind.Viable || wasError);
TypeSymbol namedArgumentType;
if (wasError)
{
namedArgumentType = CreateErrorType(); // don't generate cascaded errors.
}
else
{
namedArgumentType = BindNamedAttributeArgumentType(namedArgument, namedArgumentNameSymbol, attributeType, diagnostics);
}
// BindRValue just binds the expression without doing any validation (if its a valid expression for attribute argument).
// Validation is done later by AttributeExpressionVisitor
BoundExpression namedArgumentValue = this.BindValue(namedArgument.Expression, diagnostics, BindValueKind.RValue);
namedArgumentValue = GenerateConversionForAssignment(namedArgumentType, namedArgumentValue, diagnostics);
// TODO: should we create an entry even if there are binding errors?
var fieldSymbol = namedArgumentNameSymbol as FieldSymbol;
IdentifierNameSyntax nameSyntax = namedArgument.NameEquals.Name;
BoundExpression lvalue;
if ((object)fieldSymbol != null)
{
var containingAssembly = fieldSymbol.ContainingAssembly as SourceAssemblySymbol;
// We do not want to generate any unassigned field or unreferenced field diagnostics.
containingAssembly?.NoteFieldAccess(fieldSymbol, read: true, write: true);
lvalue = new BoundFieldAccess(nameSyntax, null, fieldSymbol, ConstantValue.NotAvailable, resultKind, fieldSymbol.Type);
}
else
{
var propertySymbol = namedArgumentNameSymbol as PropertySymbol;
if ((object)propertySymbol != null)
{
lvalue = new BoundPropertyAccess(nameSyntax, null, propertySymbol, resultKind, namedArgumentType);
}
else
{
lvalue = BadExpression(nameSyntax, resultKind);
}
}
return new BoundAssignmentOperator(namedArgument, lvalue, namedArgumentValue, namedArgumentType);
}
示例14: InferTypeInAttribute
private IEnumerable<ITypeSymbol> InferTypeInAttribute(AttributeSyntax attribute, int index, AttributeArgumentSyntax argumentOpt = null)
{
var info = this.semanticModel.GetSymbolInfo(attribute, cancellationToken);
var methods = info.GetBestOrAllSymbols().OfType<IMethodSymbol>();
return InferTypeInAttributeArgument(index, methods, argumentOpt);
}
示例15: BindNamedAttributeArgumentName
private Symbol BindNamedAttributeArgumentName(AttributeArgumentSyntax namedArgument, NamedTypeSymbol attributeType, DiagnosticBag diagnostics, out bool wasError, out LookupResultKind resultKind)
{
var identifierName = namedArgument.NameEquals.Name;
var name = identifierName.Identifier.ValueText;
LookupResult result = LookupResult.GetInstance();
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
this.LookupMembersWithFallback(result, attributeType, name, 0, ref useSiteDiagnostics);
diagnostics.Add(identifierName, useSiteDiagnostics);
Symbol resultSymbol = this.ResultSymbol(result, name, 0, identifierName, diagnostics, false, out wasError);
resultKind = result.Kind;
result.Free();
return resultSymbol;
}