private static IAttributeInstance GetSubjectAttribute(IAttributesSet type) { return((from a in type.GetAttributeInstances(true) let h = (new[] { a.GetAttributeType() }).Concat(a.GetAttributeType().GetSuperTypes()) where h.Any(t => t.GetClrName().FullName == FullNames.SubjectAttribute) select a).FirstOrDefault()); }
private static object GetAttributeValue([NotNull] IAttributesSet attrs, [NotNull] IClrTypeName attrName) { var instance = attrs.GetAttributeInstances(attrName, false).FirstOrDefault(); var parameter = instance?.PositionParameters().FirstOrDefault(); return(parameter?.ConstantValue.Value); }
public static ImplicitNullabilityConfiguration?ParseAttributes(IAttributesSet attributes) { var assemblyMetadataValues = AssemblyMetadataAttributeValues.Parse(attributes); if (assemblyMetadataValues.AppliesTo == null) { return(null); } return(ParseFromAssemblyAttributeOptionsText(assemblyMetadataValues)); }
public static ImplicitNullabilityConfiguration?ParseAttributes(IAttributesSet attributes) { var assemblyAttributeOptionsText = GetAssemblyAttributeOptionsText(attributes); if (assemblyAttributeOptionsText == null) { return(null); } return(ParseFromAssemblyAttributeOptionsText(assemblyAttributeOptionsText)); }
public void Execute(Action <DaemonStageResult> action) { IPsiModule module = _file.GetPsiModule(); ResXSettings settings = _settingsStore.GetKey <ResXSettings>(SettingsOptimization.OptimizeDefault); IAttributesSet moduleAttributes = _file.GetSolution().GetPsiServices().Symbols.GetModuleAttributes(module); string defaultResXDic = "en-US"; IList <IAttributeInstance> attributes = moduleAttributes .GetAttributeInstances(new ClrTypeName(typeof(NeutralResourcesLanguageAttribute).FullName), false); if (attributes != null && attributes.Count > 0 && attributes[0].PositionParameter(0).ConstantValue.Value != null) { defaultResXDic = attributes[0].PositionParameter(0).ConstantValue.Value.ToString(); } #if RESHARPER20173 var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile); #else var consumer = new DefaultHighlightingConsumer(this, _settingsStore); #endif ISpellChecker checker = SpellCheckManager.GetSpellChecker(_settingsStore, _file, defaultResXDic); if (checker != null) { foreach (IXmlToken token in getStringsToCheck()) { WordLexer lexer = new WordLexer(token.GetText()); lexer.Start(); while (lexer.TokenType != null) { if (SpellCheckUtil.ShouldSpellCheck(lexer.TokenText, settings.CompiledWordsToIgnore) && !checker.TestWord(lexer.TokenText, false)) { DocumentRange docRange = token.GetDocumentRange(); TextRange textRange = new TextRange(docRange.TextRange.StartOffset + lexer.TokenStart, docRange.TextRange.StartOffset + lexer.TokenEnd); DocumentRange range = new DocumentRange(docRange.Document, textRange); ResXSpellHighlighting highlighting = new ResXSpellHighlighting(lexer.TokenText, _file, checker, range, _settingsStore); consumer.AddHighlighting(highlighting, range); } lexer.Advance(); } } } action(new DaemonStageResult(consumer.Highlightings)); }
private static IAttributeInstance GetSubjectAttribute(IAttributesSet type) { #if !RESHARPER_8 return((from a in type.GetAttributeInstances(true) let h = (new[] { a.AttributeType }).Concat(a.AttributeType.GetSuperTypes()) where h.Any(t => t.GetClrName().FullName == new SubjectAttributeFullName()) select a).FirstOrDefault()); #else return((from a in type.GetAttributeInstances(true) let h = (new[] { a.GetAttributeType() }).Concat(a.GetAttributeType().GetSuperTypes()) where h.Any(t => t.GetClrName().FullName == new SubjectAttributeFullName()) select a).FirstOrDefault()); #endif }
private static string GetAssemblyAttributeOptionsText([NotNull] IAttributesSet attributes) { var assemblyMetadataAttributes = attributes.GetAttributeInstances(AssemblyMetadataAttributeTypeName, false); var attributeWithAppliesToAttributeKey = assemblyMetadataAttributes .FirstOrDefault(x => Equals(x.PositionParameter(0).ConstantValue.Value, AppliesToAttributeKey)); if (attributeWithAppliesToAttributeKey == null) { return(null); } return(attributeWithAppliesToAttributeKey.PositionParameter(1).ConstantValue.Value as string); }
private static IEnumerable <ITypeElement> GetAttributeLinkedTypes(IAttributesSet attributesSet, string attributeName) { var attribute = attributesSet .GetAttributeInstances(inherit: true) .SingleOrDefault(x => x.GetAttributeShortName()?.StartsWith(attributeName) ?? false); if (attribute == null) { return(null); } var namedArguments = attribute.NamedParameters().Select(x => x.Second); var positionalArguments = attribute.PositionParameters(); var flattenedArguments = FlattenArguments(namedArguments.Concat(positionalArguments)); return(flattenedArguments .Where(x => x.IsType && !x.IsBadValue) .Select(x => x.TypeValue.GetTypeElement()) .WhereNotNull()); }
private IEnumerable <ITypeElement> GetTypeArguments(IAttributesSet attributeSet) { var attributeInstance = attributeSet.GetAttributeInstances(inherit: true) .Where(x => x.GetClrName().ShortName == _attributeNameLong) .FirstOrDefault(); if (attributeInstance == null) { return(EmptyList <ITypeElement> .InstanceList); } var namedArguments = attributeInstance.NamedParameters().Select(x => x.Second); var positionalArguments = attributeInstance.PositionParameters(); var flattenedArguments = FlattenArguments(namedArguments.Concat(positionalArguments)); return(flattenedArguments .Where(x => x.IsType && !x.IsBadValue) .Select(x => x.TypeValue.GetTypeElement()) .WhereNotNull()); }
public static AssemblyMetadataAttributeValues Parse(IAttributesSet attributes) { var assemblyMetadataAttributes = attributes.GetAttributeInstances(AssemblyMetadataAttributeTypeName, inherit: false); var attributeValuesDictionary = new Dictionary <string, string>(); foreach (var attributeInstance in assemblyMetadataAttributes) { if (attributeInstance.PositionParameter(0).ConstantValue.Value is string key) { attributeValuesDictionary[key] = attributeInstance.PositionParameter(1).ConstantValue.Value as string; } } return(new AssemblyMetadataAttributeValues( attributeValuesDictionary.TryGetValue(AppliesToAttributeKey), attributeValuesDictionary.TryGetValue(FieldsAttributeKey), attributeValuesDictionary.TryGetValue(PropertiesAttributeKey), attributeValuesDictionary.TryGetValue(GeneratedCodeKey))); }
private void AppendAnnotations([NotNull] IAttributesSet attributesSet, AnnotationsDisplayKind showAnnotations) { if (showAnnotations == AnnotationsDisplayKind.None) { return; } IList <IAttributeInstance> attributes = attributesSet.GetAttributeInstances(false); if (attributes.Count == 0) { return; } List <string> annotations = attributes .SelectNotNull(attr => TryGetAnnotationShortName(attr, showAnnotations)) .Distinct() .OrderBy(annotation => annotation) .ToList(); if (annotations.Count == 0) { return; } string highlighterId = _useReSharperColors ? HighlightingAttributeIds.TYPE_CLASS_ATTRIBUTE : VsHighlightingAttributeIds.Classes; AppendText("[", null); for (int i = 0; i < annotations.Count; i++) { if (i > 0) { AppendText(", ", null); } AppendText(annotations[i], highlighterId); } AppendText("] ", null); }
private static object GetAttributeValue([NotNull] IAttributesSet attrs, [NotNull] IClrTypeName attrName) => attrs.GetAttributeInstances(attrName, true).FirstOrDefault()?.PositionParameters() .FirstOrDefault()?.ConstantValue.Value;
public static IAttributeInstance GetAttributeData <T> (this IAttributesSet attributeSet) where T : Attribute { return(AttributeDataUtility.Instance.GetAttributeData <T>(attributeSet)); }
public IEnumerable <IAttributeInstance> GetAttributeDatas(IAttributesSet attributeSet, string attributeType) { return(attributeSet.GetAttributeInstances(inherit: false).Where(x => x.GetAttributeType().Implements(attributeType))); }
public IAttributeInstance GetAttributeData(IAttributesSet attributeSet, string attributeType) { return(GetAttributeDatas(attributeSet, attributeType).SingleOrDefault()); }
public static IEnumerable <IAttributeInstance> GetAttributeDatas <T> (this IAttributesSet attributeSet) where T : Attribute { return(AttributeDataUtility.Instance.GetAttributeDatas <T>(attributeSet)); }
public static IAttributeInstance GetAttributeData(this IAttributesSet attributeSet, string attributeType) { return(AttributeDataUtility.Instance.GetAttributeData(attributeSet, attributeType)); }
private static IAttributeInstance GetSubjectAttribute(IAttributesSet type) { return (from a in type.GetAttributeInstances(true) let h = (new[] { a.GetAttributeType() }).Concat(a.GetAttributeType().GetSuperTypes()) where h.Any(t => t.GetClrName().FullName == new SubjectAttributeFullName()) select a).FirstOrDefault(); }
public static IAttributeInstance GetAttributeData <T> (this IAttributesSet attributeSet) where T : Attribute { return(attributeSet.GetAttributeData(typeof(T).FullName)); }
public static IEnumerable <IAttributeInstance> GetAttributeDatas(this IAttributesSet attributeSet, string attributeType) { return(AttributeDataUtility.Instance.GetAttributeDatas(attributeSet, attributeType)); }
public static IEnumerable <IAttributeInstance> GetAttributeDatas <T> (this IAttributesSet attributeSet) where T : Attribute { return(attributeSet.GetAttributeDatas(typeof(T).FullName)); }
public IEnumerable <IAttributeInstance> GetAttributeDatas <T> (IAttributesSet attributeSet) where T : Attribute { return(attributeSet.GetAttributeInstances(true).Where(x => x.GetAttributeType().Implements(typeof(T)))); }
public IAttributeInstance GetAttributeData <T> (IAttributesSet attributeSet) where T : Attribute { return(GetAttributeDatas <T>(attributeSet).SingleOrDefault()); }