當前位置: 首頁>>代碼示例>>C#>>正文


C# AttributeData類代碼示例

本文整理匯總了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);
        }
開發者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


注:本文中的AttributeData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。