本文整理汇总了C#中IFieldSymbol类的典型用法代码示例。如果您正苦于以下问题:C# IFieldSymbol类的具体用法?C# IFieldSymbol怎么用?C# IFieldSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IFieldSymbol类属于命名空间,在下文中一共展示了IFieldSymbol类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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
示例17: CallsDisposeOnField
private static bool CallsDisposeOnField(IFieldSymbol fieldSymbol, MethodDeclarationSyntax disposeMethod, SemanticModel semanticModel)
{
var hasDisposeCall = disposeMethod.Body.Statements.OfType<ExpressionStatementSyntax>()
.Any(exp =>
{
var invocation = exp.Expression as InvocationExpressionSyntax;
if (!invocation?.Expression?.IsKind(SyntaxKind.SimpleMemberAccessExpression) ?? true) return false;
var memberAccess = (MemberAccessExpressionSyntax)invocation.Expression;
if (memberAccess.Name.Identifier.ToString() != "Dispose" || memberAccess.Name.Arity != 0) return false;
var memberAccessIdentificer = memberAccess.Expression as IdentifierNameSyntax;
if (memberAccessIdentificer == null) return false;
return fieldSymbol.Equals(semanticModel.GetSymbolInfo(memberAccessIdentificer).Symbol);
});
return hasDisposeCall;
}
开发者ID:Cadums01,项目名称:code-cracker,代码行数:15,代码来源:DisposableFieldNotDisposedAnalyzer.cs
示例18: AddVariableThatWasSkippedBeforeBecauseItLackedAInitializer
private static void AddVariableThatWasSkippedBeforeBecauseItLackedAInitializer(Dictionary<IFieldSymbol, VariableDeclaratorSyntax> variablesToMakeReadonly, IFieldSymbol fieldSymbol, AssignmentExpressionSyntax assignment)
{
var parent = assignment.Parent;
while (parent != null)
{
if (parent is AnonymousFunctionExpressionSyntax)
return;
if (parent is ConstructorDeclarationSyntax)
break;
parent = parent.Parent;
}
if (!fieldSymbol.IsReadOnly && !variablesToMakeReadonly.Keys.Contains(fieldSymbol))
foreach (var variable in fieldSymbol.DeclaringSyntaxReferences)
variablesToMakeReadonly.Add(fieldSymbol, (VariableDeclaratorSyntax)variable.GetSyntax());
}
开发者ID:Cadums01,项目名称:code-cracker,代码行数:16,代码来源:ReadonlyFieldAnalyzer.cs
示例19: GetParsedField
private SDField GetParsedField(IFieldSymbol field)
{
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)
};
ParserOptions.SDRepository.AddMember(sdField);
return sdField;
}
开发者ID:Geaz,项目名称:sharpDox,代码行数:17,代码来源:FieldParser.cs
示例20: 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
注:本文中的IFieldSymbol类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论