本文整理汇总了C#中ISymbol.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.GetAttributes方法的具体用法?C# ISymbol.GetAttributes怎么用?C# ISymbol.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.GetAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContainedIn
public bool ContainedIn(ISymbol symbol)
{
bool result = false;
var attributes = symbol.GetAttributes();
foreach (var attribute in attributes)
{
INamedTypeSymbol attributeClass = attribute.AttributeClass;
if (Uid != VisitorHelper.GetId(attributeClass))
{
continue;
}
// arguments need to be a total match of the config
IEnumerable<string> arguments = attribute.ConstructorArguments.Select(arg => GetLiteralString(arg));
if (!ConstructorArguments.SequenceEqual(arguments))
{
continue;
}
// namedarguments need to be a superset of the config
Dictionary<string, string> namedArguments = attribute.NamedArguments.ToDictionary(pair => pair.Key, pair => GetLiteralString(pair.Value));
if (!ConstructorNamedArguments.Except(namedArguments).Any())
{
result = true;
break;
}
}
return result;
}
示例2: ItemsToIgnoreFromAttributes
public static IEnumerable<NameAndLocation> ItemsToIgnoreFromAttributes(ISymbol symbol,
IEnumerable<Type> attributes) =>
symbol.GetAttributes()
.Where(a => attributes.TryFirst(t => MatchAttributeName(t, a.AttributeClass.Name)).HasValue)
.SelectMany(attribute =>
(attribute.ApplicationSyntaxReference.GetSyntax() as AttributeSyntax).ArgumentList
.Arguments)
.Select(argument => new NameAndLocation(argument.ToString().Trim('"'), argument.GetLocation()));
示例3: FindAttributeOfType
public static AttributeData FindAttributeOfType(ISymbol typeSymbol, Type type)
{
foreach (AttributeData attributeData in typeSymbol.GetAttributes())
{
if (attributeData.AttributeClass.ToString() ==
type.FullName)
{
return attributeData;
}
}
return null;
}
示例4: IsGeneratedSymbolWithGeneratedCodeAttribute
internal static bool IsGeneratedSymbolWithGeneratedCodeAttribute(ISymbol symbol, INamedTypeSymbol generatedCodeAttribute)
{
Debug.Assert(symbol != null);
Debug.Assert(generatedCodeAttribute != null);
// GeneratedCodeAttribute can only be applied once on a symbol.
// For partial symbols with more than one definition, we must treat them as non-generated code symbols.
if (symbol.DeclaringSyntaxReferences.Length > 1)
{
return false;
}
if (symbol.GetAttributes().Any(a => a.AttributeClass == generatedCodeAttribute))
{
return true;
}
return symbol.ContainingSymbol != null && IsGeneratedSymbolWithGeneratedCodeAttribute(symbol.ContainingSymbol, generatedCodeAttribute);
}
示例5: GetExtensions
/// <summary>
/// Creates transform instances.
/// </summary>
/// <param name="symbol">The symbol to create from.</param>
/// <returns>A collection of extensions.</returns>
public IEnumerable<IExtension> GetExtensions(ISymbol symbol)
{
if (symbol == null)
yield break;
var attributes = symbol.GetAttributes();
if (attributes == null)
yield break;
foreach (var attr in attributes)
{
// look for extension attribute
var extAttr = attr.AttributeClass.GetAttributes()
.AsEnumerable().SingleOrDefault(aa =>
aa.AttributeClass.GetFullName() == _extClassName);
if (extAttr == null)
continue;
// handler class assembly and type names come from arguments of extension attribute
var asmName = extAttr.ConstructorArguments.ElementAt(0).Value.ToString();
var typeName = extAttr.ConstructorArguments.ElementAt(1).Value.ToString();
// applied attribute arguments are passed directly to handler ctor
var args = attr.ConstructorArguments.AsEnumerable().Select(p => p.Value);
// create an instance of the handler class
var instanceWrapper = Activator.CreateInstance(asmName, typeName, false, 0, null, args.ToArray(), null, null);
var inst = instanceWrapper.Unwrap() as IExtension;
if (inst == null)
throw new InvalidOperationException("Unable to create transform extension for: " + attr.AttributeClass.GetFullName());
// support for named arguments (these bind to properties on the handler)
foreach (var prop in attr.NamedArguments.AsEnumerable())
inst.GetType().GetProperty(prop.Key).SetValue(inst, prop.Value.Value, null);
yield return inst;
}
}
示例6: GetRuleDependencyAttributes
private ImmutableArray<AttributeData> GetRuleDependencyAttributes(ISymbol symbol, IEnumerable<INamedTypeSymbol> ruleDependencyAttributeTypes)
{
return GetRuleDependencyAttributes(symbol.GetAttributes(), ruleDependencyAttributeTypes);
}
示例7: GetSymbolAttributes
private IEnumerable<SyntaxNode> GetSymbolAttributes(ISymbol symbol)
{
return symbol.GetAttributes().Select(a => Attribute(a));
}
示例8: ParseClassSymbols
private static void ParseClassSymbols(ParseResult disco, ISymbol symbol)
{
foreach (var attrData in symbol.GetAttributes())
{
var attrClassSymbol = attrData.AttributeClass;
// handle errors
if (attrClassSymbol is IErrorTypeSymbol) continue;
if (attrData.AttributeConstructor == null) continue;
var attrClassName = SymbolDisplay.ToDisplayString(attrClassSymbol);
switch (attrClassName)
{
case "Umbraco.ModelsBuilder.IgnorePropertyTypeAttribute":
var propertyAliasToIgnore = (string)attrData.ConstructorArguments[0].Value;
disco.SetIgnoredProperty(symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/, propertyAliasToIgnore);
break;
case "Umbraco.ModelsBuilder.RenamePropertyTypeAttribute":
var propertyAliasToRename = (string)attrData.ConstructorArguments[0].Value;
var propertyRenamed = (string)attrData.ConstructorArguments[1].Value;
disco.SetRenamedProperty(symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/, propertyAliasToRename, propertyRenamed);
break;
// that one causes all sorts of issues with references to Umbraco.Core in Roslyn
//case "Umbraco.Core.Models.PublishedContent.PublishedContentModelAttribute":
// var contentAliasToRename = (string)attrData.ConstructorArguments[0].Value;
// disco.SetRenamedContent(contentAliasToRename, symbol.Name /*SymbolDisplay.ToDisplayString(symbol)*/);
// break;
case "Umbraco.ModelsBuilder.ImplementContentTypeAttribute":
var contentAliasToRename = (string)attrData.ConstructorArguments[0].Value;
disco.SetRenamedContent(contentAliasToRename, symbol.Name, true /*SymbolDisplay.ToDisplayString(symbol)*/);
break;
}
}
}
示例9: AddDescriptionPartAsync
private async Task AddDescriptionPartAsync(ISymbol symbol)
{
if (symbol.GetAttributes().Any(x => x.AttributeClass.MetadataName == "ObsoleteAttribute"))
{
AddDeprecatedPrefix();
}
if (symbol is IDynamicTypeSymbol)
{
AddDescriptionForDynamicType();
}
else if (symbol is IFieldSymbol)
{
await AddDescriptionForFieldAsync((IFieldSymbol)symbol).ConfigureAwait(false);
}
else if (symbol is ILocalSymbol)
{
await AddDescriptionForLocalAsync((ILocalSymbol)symbol).ConfigureAwait(false);
}
else if (symbol is IMethodSymbol)
{
AddDescriptionForMethod((IMethodSymbol)symbol);
}
else if (symbol is ILabelSymbol)
{
AddDescriptionForLabel((ILabelSymbol)symbol);
}
else if (symbol is INamedTypeSymbol)
{
await AddDescriptionForNamedTypeAsync((INamedTypeSymbol)symbol).ConfigureAwait(false);
}
else if (symbol is INamespaceSymbol)
{
AddDescriptionForNamespace((INamespaceSymbol)symbol);
}
else if (symbol is IParameterSymbol)
{
await AddDescriptionForParameterAsync((IParameterSymbol)symbol).ConfigureAwait(false);
}
else if (symbol is IPropertySymbol)
{
AddDescriptionForProperty((IPropertySymbol)symbol);
}
else if (symbol is IRangeVariableSymbol)
{
AddDescriptionForRangeVariable((IRangeVariableSymbol)symbol);
}
else if (symbol is ITypeParameterSymbol)
{
AddDescriptionForTypeParameter((ITypeParameterSymbol)symbol);
}
else if (symbol is IAliasSymbol)
{
await AddDescriptionPartAsync(((IAliasSymbol)symbol).Target).ConfigureAwait(false);
}
else
{
AddDescriptionForArbitrarySymbol(symbol);
}
}
开发者ID:jkotas,项目名称:roslyn,代码行数:60,代码来源:AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs
示例10: DecodeGlobalSuppressMessageAttributes
private static void DecodeGlobalSuppressMessageAttributes(Compilation compilation, ISymbol symbol, ISymbol suppressMessageAttribute, GlobalSuppressions globalSuppressions)
{
Debug.Assert(symbol is IAssemblySymbol || symbol is IModuleSymbol);
var attributeInstances = symbol.GetAttributes().Where(a => a.AttributeClass == suppressMessageAttribute);
foreach (var instance in attributeInstances)
{
SuppressMessageInfo info;
if (!TryDecodeSuppressMessageAttributeData(instance, out info))
{
continue;
}
string scopeString = info.Scope != null ? info.Scope.ToLowerInvariant() : null;
TargetScope scope;
if (SuppressMessageScopeTypes.TryGetValue(scopeString, out scope))
{
if ((scope == TargetScope.Module || scope == TargetScope.None) && info.Target == null)
{
// This suppression is applies to the entire compilation
globalSuppressions.AddCompilationWideSuppression(info.Id);
continue;
}
}
else
{
// Invalid value for scope
continue;
}
// Decode Target
if (info.Target == null)
{
continue;
}
foreach (var target in ResolveTargetSymbols(compilation, info.Target, scope))
{
globalSuppressions.AddGlobalSymbolSuppression(target, info.Id);
}
}
}
示例11: DecodeGlobalSuppressMessageAttributes
private void DecodeGlobalSuppressMessageAttributes(Compilation compilation, ISymbol symbol, GlobalSuppressions globalSuppressions)
{
Debug.Assert(symbol is IAssemblySymbol || symbol is IModuleSymbol);
var attributes = symbol.GetAttributes().Where(a => a.AttributeClass == this.SuppressMessageAttribute);
DecodeGlobalSuppressMessageAttributes(compilation, symbol, globalSuppressions, attributes);
}
示例12: IsObsolete
static bool IsObsolete (ISymbol symbol)
{
return symbol.GetAttributes ().Any (attr => attr.AttributeClass.Name == "ObsoleteAttribute" && attr.AttributeClass.ContainingNamespace.GetFullName () == "System");
}
示例13: GetNewFieldName
private static string GetNewFieldName(ISymbol fieldSymbol)
{
var name = fieldSymbol.Name.Trim('_');
if (name.Length > 2 && char.IsLetter(name[0]) && name[1] == '_')
{
name = name.Substring(2);
}
// Some .NET code uses "ts_" prefix for thread static
if (name.Length > 3 && name.StartsWith("ts_", StringComparison.OrdinalIgnoreCase))
{
name = name.Substring(3);
}
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;
}
示例14: IsRemovable
public static bool IsRemovable(ISymbol symbol, Accessibility maxAccessibility)
{
return symbol != null &&
EffectiveAccessibility(symbol) <= maxAccessibility &&
!symbol.IsImplicitlyDeclared &&
!symbol.IsAbstract &&
!symbol.IsVirtual &&
!symbol.GetAttributes().Any() &&
!symbol.ContainingType.IsInterface() &&
!symbol.IsInterfaceImplementationOrMemberOverride();
}
示例15: AnalyzeSymbol
private void AnalyzeSymbol(Action<Diagnostic> reportDiagnostic, ISymbol symbol)
{
var attributes = symbol.GetAttributes();
foreach (var attribute in attributes)
{
Analyze(reportDiagnostic, attribute);
}
}