本文整理汇总了C#中AttributeData类的典型用法代码示例。如果您正苦于以下问题:C# AttributeData类的具体用法?C# AttributeData怎么用?C# AttributeData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeData类属于命名空间,在下文中一共展示了AttributeData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoslynAttributeMetadata
private RoslynAttributeMetadata(AttributeData a)
{
var declaration = a.ToString();
var index = declaration.IndexOf("(", StringComparison.Ordinal);
this.symbol = a.AttributeClass;
this.name = symbol.Name;
if (index > -1)
{
this.value = declaration.Substring(index + 1, declaration.Length - index - 2);
// Trim {} from params
if (this.value.EndsWith("\"}"))
{
this.value = this.value.Remove(this.value.LastIndexOf("{\"", StringComparison.Ordinal), 1);
this.value = this.value.TrimEnd('}');
}
else if (this.value.EndsWith("}"))
{
this.value = this.value.Remove(this.value.LastIndexOf("{", StringComparison.Ordinal), 1);
this.value = this.value.TrimEnd('}');
}
}
if (name.EndsWith("Attribute"))
name = name.Substring(0, name.Length - 9);
}
示例2: ConvertToMessage
public string ConvertToMessage(AttributeData attributeData)
{
var stringBuilder = new StringBuilder();
var message = attributeData.Message;
if (message != null)
{
message = message.Trim();
message = message.Trim('.');
stringBuilder.AppendFormat("{0}. ", message);
}
if (attributeData.Replacement != null)
{
stringBuilder.AppendFormat(ReplacementFormat, attributeData.Replacement);
}
if (assemblyVersion < attributeData.TreatAsErrorFromVersion)
{
stringBuilder.AppendFormat(TreatAsErrorFormat, attributeData.TreatAsErrorFromVersion.ToSemVer());
}
if (attributeData.ThrowsNotImplemented)
{
stringBuilder.Append(ThrowsNotImplementedText);
}
stringBuilder.AppendFormat(RemoveInVersionFormat, attributeData.RemoveInVersion.ToSemVer());
return stringBuilder.ToString().Trim();
}
示例3: CodeGenerator
public CodeGenerator(AttributeData attributeData)
{
Requires.NotNull(attributeData, nameof(attributeData));
this.attributeData = attributeData;
this.data = this.attributeData.NamedArguments.ToImmutableDictionary(kv => kv.Key, kv => kv.Value);
}
示例4: Create
public static AttributeRemoveAction Create(
AttributeData attribute,
Project project,
Diagnostic diagnostic,
AbstractSuppressionCodeFixProvider fixer)
{
return new AttributeRemoveAction(attribute, project, diagnostic, fixer);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Attribute.cs
示例5: LockInfo
public LockInfo(
FieldDeclarationSyntax declaration,
FieldSymbol symbol,
AttributeData associatedAttribute,
SemanticModel semanticModel)
: base(declaration, symbol, associatedAttribute, semanticModel)
{
}
示例6: GuardedFieldInfo
public GuardedFieldInfo(
FieldDeclarationSyntax declaration,
FieldSymbol symbol,
AttributeData associatedAttribute,
SemanticModel semanticModel)
: base(declaration, symbol, associatedAttribute, semanticModel)
{
_declaredLockHierarchy = LockHierarchy.FromStringList(Attribute.ConstructorArguments.SelectMany(arg => arg.Values.Select(argVal => argVal.Value.ToString())).ToList());
}
示例7: GenerateAttributeDeclaration
private static AttributeListSyntax GenerateAttributeDeclaration(
AttributeData attribute, SyntaxToken? target, CodeGenerationOptions options)
{
var attributeSyntax = GenerateAttribute(attribute, options);
return attributeSyntax == null
? null
: SyntaxFactory.AttributeList(
target.HasValue ? SyntaxFactory.AttributeTargetSpecifier(target.Value) : null,
SyntaxFactory.SingletonSeparatedList(attributeSyntax));
}
示例8: GetIsError
bool GetIsError(AttributeData attributeData)
{
if (attributeData.TreatAsErrorFromVersion != null)
{
if (assemblyVersion >= attributeData.TreatAsErrorFromVersion)
{
return true;
}
}
return false;
}
示例9: AttributeRemoveAction
private AttributeRemoveAction(
AttributeData attribute,
Project project,
Diagnostic diagnostic,
AbstractSuppressionCodeFixProvider fixer,
bool forFixMultipleContext = false)
: base(diagnostic, fixer, forFixMultipleContext)
{
_project = project;
_attribute = attribute;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:11,代码来源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Attribute.cs
示例10: EmitGuard
public override StatementSyntax EmitGuard(AttributeData attribute, TypeSymbol parameterType, string parameterName)
{
StatementSyntax guardStatement = Syntax.IfStatement(
Syntax.BinaryExpression(
SyntaxKind.EqualsExpression,
Syntax.IdentifierName(parameterName),
Syntax.IdentifierName("null")),
Syntax.Block(
SimpleSyntaxWriter.GenerateThrowStatement(typeof(ArgumentNullException), parameterName)));
return guardStatement;
}
示例11: EmitGuard
public override StatementSyntax EmitGuard(AttributeData attribute, TypeSymbol parameterType, string parameterName)
{
//TODO: Consider how to properly handle type conversions
StatementSyntax guardStatement = Syntax.IfStatement(
SimpleSyntaxWriter.InvokeStaticMethod(
()=>string.IsNullOrWhiteSpace(Fake.String),
SimpleSyntaxWriter.ArgumentFromIdentifier(parameterName)),
Syntax.Block(
SimpleSyntaxWriter.GenerateThrowStatement(typeof(ArgumentException), parameterName, string.Format(@"""{0} cannot be null, empty or whitespace""", parameterName))));
return guardStatement;
}
示例12: AttributeData_Ctor
public void AttributeData_Ctor()
{
AttributeData data;
Console.WriteLine("Test with optional value and no default value.");
data = new AttributeData("test", new XmlNameInfo("name"), true);
Assert.IsNotNull(data.InheritanceList, "InheritanceList is not null.");
Assert.AreEqual(0, data.InheritanceList.Count, "InheritanceList count is incorrect.");
Assert.IsNull(data.ConverterTypeName, "ConverterTypeName is not null.");
Assert.IsFalse(data.HasValue, "HasValue is incorrect.");
Assert.IsFalse(data.InheritValue, "InheritValue is incorrect.");
Assert.IsFalse(data.IsDefaultValue, "IsDefaultValue is incorrect.");
Assert.IsTrue(data.IsOptional, "IsOptional is incorrect.");
Assert.IsNull(data.Value, "Value is incorrect.");
Assert.AreEqual("name", data.LocalName, "XmlName is incorrect.");
Console.WriteLine("Test with required value and no default value.");
data = new AttributeData("test", new XmlNameInfo("name"), false);
Assert.IsNotNull(data.InheritanceList, "InheritanceList is not null.");
Assert.AreEqual(0, data.InheritanceList.Count, "InheritanceList count is incorrect.");
Assert.IsNull(data.ConverterTypeName, "ConverterTypeName is not null.");
Assert.IsFalse(data.HasValue, "HasValue is incorrect.");
Assert.IsFalse(data.InheritValue, "InheritValue is incorrect.");
Assert.IsFalse(data.IsDefaultValue, "IsDefaultValue is incorrect.");
Assert.IsFalse(data.IsOptional, "IsOptional is incorrect.");
Assert.IsNull(data.Value, "Value is incorrect.");
Assert.AreEqual("name", data.LocalName, "XmlName is incorrect.");
Console.WriteLine("Test with optional value and default value.");
data = new AttributeData("test", new XmlNameInfo("name"), true, 1);
Assert.IsNotNull(data.InheritanceList, "InheritanceList is not null.");
Assert.AreEqual(0, data.InheritanceList.Count, "InheritanceList count is incorrect.");
Assert.IsNull(data.ConverterTypeName, "ConverterTypeName is not null.");
Assert.IsFalse(data.HasValue, "HasValue is incorrect.");
Assert.IsFalse(data.InheritValue, "InheritValue is incorrect.");
Assert.IsTrue(data.IsDefaultValue, "IsDefaultValue is incorrect.");
Assert.IsTrue(data.IsOptional, "IsOptional is incorrect.");
Assert.AreEqual(1, data.Value, "Value is incorrect.");
Assert.AreEqual("name", data.LocalName, "XmlName is incorrect.");
Console.WriteLine("Test with required value and default value.");
data = new AttributeData("test", new XmlNameInfo("name"), false, 1);
Assert.IsNotNull(data.InheritanceList, "InheritanceList is not null.");
Assert.AreEqual(0, data.InheritanceList.Count, "InheritanceList count is incorrect.");
Assert.IsNull(data.ConverterTypeName, "ConverterTypeName is not null.");
Assert.IsTrue(data.HasValue, "HasValue is incorrect.");
Assert.IsFalse(data.InheritValue, "InheritValue is incorrect.");
Assert.IsTrue(data.IsDefaultValue, "IsDefaultValue is incorrect.");
Assert.IsFalse(data.IsOptional, "IsOptional is incorrect.");
Assert.AreEqual(1, data.Value, "Value is incorrect.");
Assert.AreEqual("name", data.LocalName, "XmlName is incorrect.");
}
示例13: EmitGuard
public override StatementSyntax EmitGuard(AttributeData attribute, TypeSymbol parameterType, string parameterName)
{
//TODO: Modify to try cast to IList first, then try cast to IEnumerable
StatementSyntax guardStatement = Syntax.IfStatement(
Syntax.BinaryExpression(
SyntaxKind.LessThanOrEqualExpression,
SimpleSyntaxWriter.AccessMemberWithCast((IList x)=>x.Count, parameterName),
Syntax.IdentifierName("0")),
Syntax.Block(
SimpleSyntaxWriter.GenerateThrowStatement(typeof(ArgumentException), parameterName, string.Format(@"""{0} cannot be empty""", parameterName))));
return guardStatement;
}
示例14: All
public void All()
{
var attributeData = new AttributeData
{
Message = "Custom Message.",
TreatAsErrorFromVersion = "2",
RemoveInVersion = "4",
Replacement = "NewMember"
};
SemanticVersion assemblyVersion = "1";
var dataFormatter = new ModuleWeaver {assemblyVersion = assemblyVersion};
var message = dataFormatter.ConvertToMessage(attributeData);
Assert.AreEqual("Custom Message. Use `NewMember` instead. Will be treated as an error from version 2.0.0. Will be removed in version 4.0.0.", message);
}
示例15: RoslynAttributeMetadata
private RoslynAttributeMetadata(AttributeData a)
{
var declaration = a.ToString();
var index = declaration.IndexOf("(", StringComparison.Ordinal);
this.symbol = a.AttributeClass;
this.name = symbol.Name;
if (index > -1)
this.value = declaration.Substring(index + 1, declaration.Length - index - 2);
if (name.EndsWith("Attribute"))
name = name.Substring(0, name.Length - 9);
}