本文整理汇总了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;
}
示例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;
}
示例3: FieldIsRelevant
protected static bool FieldIsRelevant(IFieldSymbol fieldSymbol)
{
return fieldSymbol != null &&
!fieldSymbol.IsStatic &&
!fieldSymbol.IsConst &&
fieldSymbol.DeclaredAccessibility == Accessibility.Public;
}
示例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;
}
示例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));
}
示例7: FieldIsRelevant
private static bool FieldIsRelevant(IFieldSymbol fieldSymbol)
{
return fieldSymbol != null &&
fieldSymbol.IsStatic &&
!fieldSymbol.IsConst &&
!fieldSymbol.IsReadOnly &&
fieldSymbol.DeclaredAccessibility != Accessibility.Private;
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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)
};
}
示例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;
}
示例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()));
}
}
示例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());
}