private static IEnumerable <string> GetSupportedLanguages(PEModule peModule, CustomAttributeHandle customAttrHandle) { // The DiagnosticAnalyzerAttribute has one constructor, which has a string parameter for the // first supported language and an array parameter for addition supported languages. // Parse the argument blob to extract the languages. BlobReader argsReader = peModule.GetMemoryReaderOrThrow(peModule.GetCustomAttributeValueOrThrow(customAttrHandle)); if (argsReader.Length > 4) { // Arguments are present--check prologue. if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string firstLanguageName; if (!PEModule.CrackStringInAttributeValue(out firstLanguageName, ref argsReader)) { return(SpecializedCollections.EmptyEnumerable <string>()); } ImmutableArray <string> additionalLanguageNames; if (PEModule.CrackStringArrayInAttributeValue(out additionalLanguageNames, ref argsReader)) { if (additionalLanguageNames.Length == 0) { return(SpecializedCollections.SingletonEnumerable(firstLanguageName)); } return(additionalLanguageNames.Insert(0, firstLanguageName)); } } } return(SpecializedCollections.EmptyEnumerable <string>()); }
private static IEnumerable <string> ReadLanguagesFromAttribute(ref BlobReader argsReader) { if (argsReader.Length > 4) { // Arguments are present--check prologue. if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string firstLanguageName; if (!PEModule.CrackStringInAttributeValue(out firstLanguageName, ref argsReader)) { return(SpecializedCollections.EmptyEnumerable <string>()); } ImmutableArray <string> additionalLanguageNames; if (PEModule.CrackStringArrayInAttributeValue(out additionalLanguageNames, ref argsReader)) { if (additionalLanguageNames.Length == 0) { return(SpecializedCollections.SingletonEnumerable(firstLanguageName)); } return(additionalLanguageNames.Insert(0, firstLanguageName)); } } } return(SpecializedCollections.EmptyEnumerable <string>()); }
private static string GetSupportedLanguage(PEModule peModule, CustomAttributeHandle customAttrHandle) { // The DiagnosticAnalyzerAttribute has two constructors: // 1. Paramterless - means that the analyzer is applicable to any language. // 2. Single string parameter specifying the language. // Parse the argument blob to extract these two cases. BlobReader argsReader = peModule.GetMemoryReaderOrThrow(peModule.GetCustomAttributeValueOrThrow(customAttrHandle)); // Single string parameter if (argsReader.Length > 4) { // check prologue if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string languageName; if (PEModule.CrackStringInAttributeValue(out languageName, ref argsReader)) { return(languageName); } } } // otherwise the attribute is applicable to all languages. else { return(string.Empty); } return(null); }