示例#1
0
        private static ImmutableHashSet <TEnum> GetNonFlagsEnumOptionValue <TEnum>(
            this AnalyzerOptions options,
            string optionName,
            DiagnosticDescriptor rule,
            ImmutableHashSet <TEnum> defaultValue,
            CancellationToken cancellationToken)
            where TEnum : struct
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue(optionName, rule, TryParseValue, defaultValue));

            bool TryParseValue(string value, out ImmutableHashSet <TEnum> result)
            {
                var builder = ImmutableHashSet.CreateBuilder <TEnum>();

                foreach (var kindStr in value.Split(','))
                {
                    if (Enum.TryParse(kindStr, ignoreCase: true, result: out TEnum kind))
                    {
                        builder.Add(kind);
                    }
                }

                result = builder.ToImmutable();
                return(builder.Count > 0);
            }
        }
        private static SymbolNamesOption GetSymbolNamesOption(
            this AnalyzerOptions options,
            string optionName,
            string namePrefixOpt,
            DiagnosticDescriptor rule,
            Compilation compilation,
            CancellationToken cancellationToken)
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue(optionName, rule, TryParse, defaultValue: SymbolNamesOption.Empty));

            // Local functions.
            bool TryParse(string s, out SymbolNamesOption option)
            {
                if (string.IsNullOrEmpty(s))
                {
                    option = SymbolNamesOption.Empty;
                    return(false);
                }

                var names = s.Split('|').ToImmutableArray();

                option = SymbolNamesOption.Create(names, compilation, namePrefixOpt);
                return(true);
            }
        }
        private static ImmutableHashSet <TEnum> GetNonFlagsEnumOptionValue <TEnum>(
            this AnalyzerOptions options,
            string optionName,
            DiagnosticDescriptor rule,
            ImmutableHashSet <TEnum> defaultValue,
            CancellationToken cancellationToken)
            where TEnum : struct
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue(optionName, rule, TryParseValue, defaultValue));
示例#4
0
        public static bool GetBoolOptionValue(
            this AnalyzerOptions options,
            string optionName,
            DiagnosticDescriptor rule,
            bool defaultValue,
            CancellationToken cancellationToken)
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue(optionName, rule, bool.TryParse, defaultValue));
        }
        private static TEnum GetFlagsEnumOptionValue <TEnum>(
            this AnalyzerOptions options,
            string optionName,
            DiagnosticDescriptor rule,
            TEnum defaultValue,
            CancellationToken cancellationToken)
            where TEnum : struct
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue(
                       optionName, rule,
                       tryParseValue: (string value, out TEnum result) => Enum.TryParse(value, ignoreCase: true, result: out result),
                       defaultValue: defaultValue));
        }
示例#6
0
        public static ImmutableArray <string> GetSeparatedStringOptionValue(
            this AnalyzerOptions options,
            string optionName,
            DiagnosticDescriptor rule,
            CancellationToken cancellationToken)
        {
            var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(cancellationToken);

            return(analyzerConfigOptions.GetOptionValue <ImmutableArray <string> >(optionName, rule, TryParse, defaultValue: ImmutableArray <string> .Empty));

            // Local functions.
            bool TryParse(string s, out ImmutableArray <string> parts)
            {
                if (string.IsNullOrEmpty(s))
                {
                    parts = ImmutableArray <string> .Empty;
                    return(false);
                }

                parts = s.Split('~').ToImmutableArray();
                return(true);
            }
        }