本文整理汇总了C#中AttributeData类的典型用法代码示例。如果您正苦于以下问题:C# AttributeData类的具体用法?C# AttributeData怎么用?C# AttributeData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeData类属于命名空间,在下文中一共展示了AttributeData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:ChinaJason,项目名称:Typewriter,代码行数:28,代码来源:RoslynAttributeMetadata.cs
示例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();
}
开发者ID:Fody,项目名称:Obsolete,代码行数:28,代码来源:DataFormatter.cs
示例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);
}
开发者ID:zbynek001,项目名称:ImmutableObjectGraph,代码行数:7,代码来源:CodeGenerator.cs
示例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)
{
}
开发者ID:flashcurd,项目名称:ThreadSafetyAnnotations,代码行数:8,代码来源:LockInfo.cs
示例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());
}
开发者ID:flashcurd,项目名称:ThreadSafetyAnnotations,代码行数:9,代码来源:GuardedFieldInfo.cs
示例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));
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:10,代码来源:AttributeGenerator.cs
示例8: GetIsError
bool GetIsError(AttributeData attributeData)
{
if (attributeData.TreatAsErrorFromVersion != null)
{
if (assemblyVersion >= attributeData.TreatAsErrorFromVersion)
{
return true;
}
}
return false;
}
开发者ID:Fody,项目名称:Obsolete,代码行数:11,代码来源:AttributeFixer.cs
示例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;
}
开发者ID:flashcurd,项目名称:AutoGuards,代码行数:12,代码来源:NotNullEmitter.cs
示例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;
}
开发者ID:flashcurd,项目名称:AutoGuards,代码行数:12,代码来源:NotNullOrWhitespaceEmitter.cs
示例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.");
}
开发者ID:jogleasonjr,项目名称:XLIFF2-Object-Model,代码行数:52,代码来源:AttributeDataTests.cs
示例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;
}
开发者ID:flashcurd,项目名称:AutoGuards,代码行数:13,代码来源:NotEmptyEmitter.cs
示例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);
}
开发者ID:Fody,项目名称:Obsolete,代码行数:14,代码来源:AttributeDataFormatterTests.cs
示例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);
}
开发者ID:plasmaboyer,项目名称:Typewriter,代码行数:14,代码来源:RoslynAttributeMetadata.cs
示例16: AddObsoleteAttribute
void AddObsoleteAttribute(AttributeData attributeData, Collection<CustomAttribute> customAttributes)
{
var customAttribute = new CustomAttribute(ObsoleteConstructorReference);
var message = ConvertToMessage(attributeData);
var messageArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.String, message);
customAttribute.ConstructorArguments.Add(messageArgument);
var isError = GetIsError(attributeData);
var isErrorArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.Boolean, isError);
customAttribute.ConstructorArguments.Add(isErrorArgument);
customAttributes.Add(customAttribute);
}
开发者ID:Fody,项目名称:Obsolete,代码行数:14,代码来源:AttributeFixer.cs
示例17: ForSample
public void ForSample()
{
var attributeData = new AttributeData
{
Message = "Custom Message.",
TreatAsErrorFromVersion = "2",
RemoveInVersion = "4",
Replacement = "NewClass"
};
var dataFormatter1 = new ModuleWeaver { assemblyVersion = "1"};
Debug.WriteLine(dataFormatter1.ConvertToMessage(attributeData));
var dataFormatter2 = new ModuleWeaver { assemblyVersion = "3"};
Debug.WriteLine(dataFormatter2.ConvertToMessage(attributeData));
}
开发者ID:Fody,项目名称:Obsolete,代码行数:14,代码来源:AttributeDataFormatterTests.cs
示例18: GenerateAttribute
private static AttributeSyntax GenerateAttribute(AttributeData attribute, CodeGenerationOptions options)
{
if (!options.MergeAttributes)
{
var reusableSyntax = GetReuseableSyntaxNodeForAttribute<AttributeSyntax>(attribute, options);
if (reusableSyntax != null)
{
return reusableSyntax;
}
}
var attributeArguments = GenerateAttributeArgumentList(attribute);
var nameSyntax = attribute.AttributeClass.GenerateTypeSyntax() as NameSyntax;
return nameSyntax == null ? null : SyntaxFactory.Attribute(nameSyntax, attributeArguments);
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:15,代码来源:AttributeGenerator.cs
示例19: EmitGuard
public override StatementSyntax EmitGuard(AttributeData attribute, TypeSymbol parameterType, string parameterName)
{
//TODO: Consider how to properly handle type conversions
StatementSyntax guardStatement = Syntax.IfStatement(
Syntax.BinaryExpression(
SyntaxKind.EqualsExpression,
SimpleSyntaxWriter.InvokeStaticMethod(
() => Enum.IsDefined(Fake.Any<Type>(), Fake.Object),
SimpleSyntaxWriter.ArgumentFromTypeof(parameterType.Name),
SimpleSyntaxWriter.ArgumentFromLiteral(parameterName, false)
),
Syntax.IdentifierName("false")),
Syntax.Block(
SimpleSyntaxWriter.GenerateThrowStatement(typeof(ArgumentException), parameterName, string.Format(@"""{0} value is not defined for the enum type.""", parameterName))));
return guardStatement;
}
开发者ID:flashcurd,项目名称:AutoGuards,代码行数:17,代码来源:IsDefinedEmitter.cs
示例20: EmitGuard
public override StatementSyntax EmitGuard(AttributeData attribute, TypeSymbol parameterType, string parameterName)
{
string comparisonValue = attribute.ConstructorArguments.First().Value.ToString();
StatementSyntax guardStatement = Syntax.IfStatement(
Syntax.BinaryExpression(
SyntaxKind.GreaterThanOrEqualExpression,
SimpleSyntaxWriter.InvokeMethodWithCast(
(IComparable x)=>x.CompareTo(Fake.Object),
parameterName,
SimpleSyntaxWriter.ArgumentFromLiteral(comparisonValue, false)),
Syntax.IdentifierName("0")),
Syntax.Block(
SimpleSyntaxWriter.GenerateThrowStatement(typeof(ArgumentException), parameterName, string.Format(@"""{0} is not less than '" + comparisonValue + @"'.""", parameterName))));
return guardStatement;
}
开发者ID:flashcurd,项目名称:AutoGuards,代码行数:17,代码来源:LessThanEmitter.cs
注:本文中的AttributeData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论