当前位置: 首页>>代码示例>>C#>>正文


C# IFieldSymbol.GetAttributes方法代码示例

本文整理汇总了C#中IFieldSymbol.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IFieldSymbol.GetAttributes方法的具体用法?C# IFieldSymbol.GetAttributes怎么用?C# IFieldSymbol.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFieldSymbol的用法示例。


在下文中一共展示了IFieldSymbol.GetAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExplicitlyAssignedField

        private IFieldSymbol GetExplicitlyAssignedField(IFieldSymbol originalField, SyntaxGenerator syntaxFactoryService)
        {
            var originalInitializer = GetFieldInitializer(originalField);
            if (originalInitializer != null || !originalField.HasConstantValue)
            {
                return originalField;
            }

            var constantValueExpression = syntaxFactoryService.LiteralExpression(originalField.ConstantValue);
            var newInitializer = CreateConstantValueInitializer(constantValueExpression);

            return CodeGenerationSymbolFactory.CreateFieldSymbol(originalField.GetAttributes(), originalField.DeclaredAccessibility, originalField.GetSymbolModifiers(),
                originalField.Type, originalField.Name, originalField.HasConstantValue, originalField.ConstantValue, newInitializer);
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:14,代码来源:CA1008CodeFixProviderBase.cs

示例2: GetWidgetFieldName

		public static string GetWidgetFieldName (IFieldSymbol field)
		{
			foreach (AttributeData att in field.GetAttributes ())	{
				var type = att.AttributeClass;
				if (type.Name == "Widget" ||  type.Name == "WidgetAttribute") {
					var pArgs = att.ConstructorArguments;
					if (pArgs != null && pArgs.Length > 0) {
						var exp = pArgs[0].Value;
						if (exp != null)
							return exp.ToString ();
					} else {
						return field.Name;
					}
				}
			}
			return field.Name;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:17,代码来源:ClassUtils.cs

示例3: GenerateFieldDeclaration

        public static FieldDeclarationSyntax GenerateFieldDeclaration(
            IFieldSymbol field, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var reusableSyntax = GetReuseableSyntaxNodeForSymbol<VariableDeclaratorSyntax>(field, options);
            if (reusableSyntax != null)
            {
                var variableDeclaration = reusableSyntax.Parent as VariableDeclarationSyntax;
                if (variableDeclaration != null)
                {
                    var newVariableDeclaratorsList = new SeparatedSyntaxList<VariableDeclaratorSyntax>().Add(reusableSyntax);
                    var newVariableDeclaration = variableDeclaration.WithVariables(newVariableDeclaratorsList);
                    var fieldDecl = variableDeclaration.Parent as FieldDeclarationSyntax;
                    if (fieldDecl != null)
                    {
                        return fieldDecl.WithDeclaration(newVariableDeclaration);
                    }
                }
            }

            var initializerNode = CodeGenerationFieldInfo.GetInitializer(field) as ExpressionSyntax;

            var initializer = initializerNode != null
                ? SyntaxFactory.EqualsValueClause(initializerNode)
                : GenerateEqualsValue(field);

            var fieldDeclaration = SyntaxFactory.FieldDeclaration(
                AttributeGenerator.GenerateAttributeLists(field.GetAttributes(), options),
                GenerateModifiers(field, options),
                SyntaxFactory.VariableDeclaration(
                    field.Type.GenerateTypeSyntax(),
                    SyntaxFactory.SingletonSeparatedList(
                        AddAnnotationsTo(field, SyntaxFactory.VariableDeclarator(field.Name.ToIdentifierToken(), null, initializer)))));

            return AddCleanupAnnotationsTo(
                ConditionallyAddDocumentationCommentTo(fieldDeclaration, field, options));
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:36,代码来源:FieldGenerator.cs

示例4: IsFieldSerializableByAttributes

            private bool IsFieldSerializableByAttributes(IFieldSymbol field)
            {
                if (field.GetAttributes()
                    .Any(attr => s_serializingFieldAttributes.Contains(NameHelper.GetFullName(attr.AttributeClass))))
                {
                    return true;
                }

                return false;
            }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:10,代码来源:MarkReadonlyFieldsRule.cs

示例5: IsValidField

 internal static bool IsValidField(IFieldSymbol field, TypeDeclarationSyntax type)
 {
     if (field == null || field.GetAttributes().Count() > 0)
         return false;
     foreach (var m in type.Members.OfType<FieldDeclarationSyntax>())
     {
         foreach (var i in m.Declaration.Variables)
         {
             if (i.SpanStart == field.Locations.First().SourceSpan.Start)
             {
                 if (i.Initializer != null)
                     return false;
                 break;
             }
         }
     }
     return true;
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:18,代码来源:ReplacePropertyWithBackingFieldWithAutoPropertyCodeRefactoringProvider.cs

示例6: GetNewFieldName

            private static string GetNewFieldName(IFieldSymbol fieldSymbol)
            {
                var name = fieldSymbol.Name.Trim('_');
                if (name.Length > 2 && char.IsLetter(name[0]) && name[1] == '_')
                {
                    name = name.Substring(2);
                }

                if (name.Length == 0)
                {
                    return fieldSymbol.Name;
                }

                if (name.Length > 2 && char.IsUpper(name[0]) && char.IsLower(name[1]))
                {
                    name = char.ToLower(name[0]) + name.Substring(1);
                }

                if (fieldSymbol.IsStatic)
                {
                    // Check for ThreadStatic private fields.
                    if (fieldSymbol.GetAttributes().Any(a => a.AttributeClass.Name.Equals("ThreadStaticAttribute", StringComparison.Ordinal)))
                    {
                        return "t_" + name;
                    }
                    else
                    {
                        return "s_" + name;
                    }
                }

                return "_" + name;
            }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:33,代码来源:PrivateFieldNamingRule.cs


注:本文中的IFieldSymbol.GetAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。