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


C# IFieldSymbol类代码示例

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


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

示例1: 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 && fieldSymbol.IsReadOnly) || fieldSymbol.IsConst)
                {
                    return ToUppercaseWords(name);
                }

                return "_" + name;
            }
开发者ID:jimdeselms,项目名称:codeformatter,代码行数:25,代码来源:PrivateFieldNamingRule.cs

示例2: ContainingTypeImplementsIDisposableAndCallsItOnTheField

 private static bool ContainingTypeImplementsIDisposableAndCallsItOnTheField(SymbolAnalysisContext context, IFieldSymbol fieldSymbol)
 {
     var containingType = fieldSymbol.ContainingType;
     if (containingType == null) return false;
     var iDisposableInterface = containingType.AllInterfaces.FirstOrDefault(i => i.ToString() == "System.IDisposable");
     if (iDisposableInterface == null) return false;
     var disposableMethod = iDisposableInterface.GetMembers("Dispose").OfType<IMethodSymbol>().First(d => d.Arity == 0);
     var disposeMethodSymbol = containingType.FindImplementationForInterfaceMember(disposableMethod) as IMethodSymbol;
     if (disposeMethodSymbol == null) return false;
     if (disposeMethodSymbol.IsAbstract) return true;
     foreach (MethodDeclarationSyntax disposeMethod in disposeMethodSymbol.DeclaringSyntaxReferences.Select(sr => sr.GetSyntax()))
     {
         if (disposeMethod == null) return false;
         var semanticModel = context.Compilation.GetSemanticModel(disposeMethod.SyntaxTree);
         if (CallsDisposeOnField(fieldSymbol, disposeMethod, semanticModel)) return true;
         var invocations = disposeMethod.DescendantNodes().OfKind<InvocationExpressionSyntax>(SyntaxKind.InvocationExpression);
         foreach (var invocation in invocations)
         {
             var invocationExpressionSymbol = semanticModel.GetSymbolInfo(invocation.Expression).Symbol;
             if (invocationExpressionSymbol == null
                 || invocationExpressionSymbol.Kind != SymbolKind.Method
                 || invocationExpressionSymbol.Locations.Any(l => l.Kind != LocationKind.SourceFile)
                 || !invocationExpressionSymbol.ContainingType.Equals(containingType)) continue;
             foreach (MethodDeclarationSyntax method in invocationExpressionSymbol.DeclaringSyntaxReferences.Select(sr => sr.GetSyntax()))
                 if (CallsDisposeOnField(fieldSymbol, method, semanticModel)) return true;
         }
     }
     return false;
 }
开发者ID:jhancock93,项目名称:code-cracker,代码行数:29,代码来源:DisposableFieldNotDisposedAnalyzer.cs

示例3: FieldIsRelevant

 protected static bool FieldIsRelevant(IFieldSymbol fieldSymbol)
 {
     return fieldSymbol != null &&
            !fieldSymbol.IsStatic &&
            !fieldSymbol.IsConst &&
            fieldSymbol.DeclaredAccessibility == Accessibility.Public;
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:7,代码来源:FieldShouldNotBePublicBase.cs

示例4: GetParsedField

        private SDField GetParsedField(IFieldSymbol field)
        {
            var syntaxReference = field.DeclaringSyntaxReferences.Any() ? field.DeclaringSyntaxReferences.Single() : null;
            var sdField = new SDField(field.GetIdentifier())
            {
                Name = field.Name,
                DeclaringType = _typeRefParser.GetParsedTypeReference(field.ContainingType),
                Accessibility = field.DeclaredAccessibility.ToString().ToLower(),
                ReturnType = _typeRefParser.GetParsedTypeReference(field.Type),
                ConstantValue = field.ConstantValue != null ? field.ConstantValue.ToString() : string.Empty,
                IsConst = field.IsConst,
                IsReadonly = field.IsReadOnly,
                Documentations = DocumentationParser.ParseDocumentation(field),
                Region = syntaxReference != null ? new SDRegion
                {
                    Start = syntaxReference.Span.Start,
                    End = syntaxReference.Span.End,
                    StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1,
                    EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1,
                    FilePath = syntaxReference.SyntaxTree.FilePath,
                    Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath)
                } : null
            };

            ParserOptions.SDRepository.AddMember(sdField);
            return sdField;
        }
开发者ID:Geaz,项目名称:sharpDox,代码行数:27,代码来源:FieldParser.cs

示例5: 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

示例6: AddEnumMemberTo

        internal static EnumDeclarationSyntax AddEnumMemberTo(EnumDeclarationSyntax destination, IFieldSymbol enumMember, CodeGenerationOptions options)
        {
            var members = new List<SyntaxNodeOrToken>();
            members.AddRange(destination.Members.GetWithSeparators());

            var member = GenerateEnumMemberDeclaration(enumMember, destination, options);

            if (members.Count == 0)
            {
                members.Add(member);
            }
            else if (members.LastOrDefault().CSharpKind() == SyntaxKind.CommaToken)
            {
                members.Add(member);
                members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken));
            }
            else
            {
                var lastMember = members.Last();
                var trailingTrivia = lastMember.GetTrailingTrivia();
                members[members.Count - 1] = lastMember.WithTrailingTrivia();
                members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(trailingTrivia));
                members.Add(member);
            }

            return destination.EnsureOpenAndCloseBraceTokens()
                .WithMembers(SyntaxFactory.SeparatedList<EnumMemberDeclarationSyntax>(members));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:EnumMemberGenerator.cs

示例7: FieldIsRelevant

 private static bool FieldIsRelevant(IFieldSymbol fieldSymbol)
 {
     return fieldSymbol != null &&
            fieldSymbol.IsStatic &&
            !fieldSymbol.IsConst &&
            !fieldSymbol.IsReadOnly &&
            fieldSymbol.DeclaredAccessibility != Accessibility.Private;
 }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:8,代码来源:StaticFieldVisible.cs

示例8: Attach

 public static void Attach(
     IFieldSymbol field,
     bool isUnsafe,
     bool isWithEvents,
     SyntaxNode initializer)
 {
     var info = new CodeGenerationFieldInfo(isUnsafe, isWithEvents, initializer);
     fieldToInfoMap.Add(field, info);
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:9,代码来源:CodeGenerationFieldInfo.cs

示例9: FieldDeclaration

 /// <summary>
 /// Creates a field declaration matching an existing field symbol.
 /// </summary>
 public SyntaxNode FieldDeclaration(IFieldSymbol field, SyntaxNode initializer = null)
 {
     return FieldDeclaration(
         field.Name,
         TypeExpression(field.Type),
         field.DeclaredAccessibility,
         SymbolModifiers.From(field),
         initializer);
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:12,代码来源:SyntaxGenerator.cs

示例10: GetExplicitlyAssignedField

        private SyntaxNode GetExplicitlyAssignedField(IFieldSymbol originalField, SyntaxNode declaration, SyntaxGenerator generator)
        {
            SyntaxNode originalInitializer = generator.GetExpression(declaration);
            if (originalInitializer != null || !originalField.HasConstantValue)
            {
                return declaration;
            }

            return generator.WithExpression(declaration, generator.LiteralExpression(originalField.ConstantValue));
        }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:10,代码来源:EnumsShouldHaveZeroValue.Fixer.cs

示例11: IsParentAClass

        private bool IsParentAClass(IFieldSymbol fieldDeclarationSyntax)
        {
            if (fieldDeclarationSyntax.ContainingSymbol != null &&
                fieldDeclarationSyntax.ContainingSymbol.Kind == SymbolKind.NamedType)
            {
                return ((ITypeSymbol)fieldDeclarationSyntax.ContainingSymbol).TypeKind == TypeKind.Class;
            }

            return false;
        }
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:10,代码来源:SA1401FieldsMustBePrivate.cs

示例12: EncapsulateOneField

        private IEnumerable<EncapsulateFieldCodeAction> EncapsulateOneField(Document document, TextSpan span, IFieldSymbol field, int index)
        {
            var action1Text = string.Format(FeaturesResources.EncapsulateFieldUsages, field.Name);
            var action2Text = string.Format(FeaturesResources.EncapsulateField, field.Name);

            return new[]
            {
                new EncapsulateFieldCodeAction(new EncapsulateFieldResult(c => SingleEncapsulateFieldResultAsync(document, span, index, true, c)), action1Text),
                new EncapsulateFieldCodeAction(new EncapsulateFieldResult(c => SingleEncapsulateFieldResultAsync(document, span, index, false, c)), action2Text)
            };
        }
开发者ID:rgani,项目名称:roslyn,代码行数:11,代码来源:AbstractEncapsulateFieldService.cs

示例13: GetFieldInitializer

        internal override SyntaxNode GetFieldInitializer(IFieldSymbol field)
        {
            if (field.DeclaringSyntaxReferences.Length == 0)
            {
                return null;
            }

            var syntax = field.DeclaringSyntaxReferences.First().GetSyntax();
            var enumMemberSyntax = syntax as EnumMemberDeclarationSyntax;
            return enumMemberSyntax == null ? null : enumMemberSyntax.EqualsValue;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:CA1008CSharpCodeFixProvider.cs

示例14: CheckForDiagnostics

    private static void CheckForDiagnostics(SyntaxNodeAnalysisContext context, FieldDeclarationSyntax fieldNode, IFieldSymbol fieldSymbol)
    {
      var isStatic = fieldSymbol.IsStatic;
      var isPublic = fieldSymbol.DeclaredAccessibility.HasFlag(Accessibility.Public);
      var isReadOnly = fieldSymbol.IsReadOnly;

      if (!isStatic || !isPublic || !isReadOnly)
      {
        context.ReportDiagnostic(Diagnostic.Create(
          EvaluateManagedBackingFieldsAnalayzer.mustBePublicStaticAndReadonlyRule,
          fieldNode.GetLocation()));
      }
    }
开发者ID:ronnymgm,项目名称:csla-light,代码行数:13,代码来源:EvaluateManagedBackingFieldsAnalayzer.cs

示例15: AddFieldTo

        internal static CompilationUnitSyntax AddFieldTo(
            CompilationUnitSyntax destination,
            IFieldSymbol field,
            CodeGenerationOptions options,
            IList<bool> availableIndices)
        {
            var declaration = GenerateFieldDeclaration(field, CodeGenerationDestination.CompilationUnit, options);

            // Place the field after the last field or const, or at the start of the type
            // declaration.
            var members = Insert(destination.Members, declaration, options, availableIndices,
                after: m => LastField(m, declaration), before: FirstMember);
            return destination.WithMembers(members.ToSyntaxList());
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:14,代码来源:FieldGenerator.cs


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