private static (object result, bool succeeded) ParseDictionary(
            object underlyingOption, IReadOnlyDictionary <string, object> allRawConventions, Type type)
        {
            if (type == typeof(NamingStylePreferences))
            {
                var editorconfigNamingStylePreferences = EditorConfigNamingStyleParser.GetNamingStylesFromDictionary(allRawConventions);

                if (!editorconfigNamingStylePreferences.NamingRules.Any() &&
                    !editorconfigNamingStylePreferences.NamingStyles.Any() &&
                    !editorconfigNamingStylePreferences.SymbolSpecifications.Any())
                {
                    // We were not able to parse any rules from editorconfig, tell the caller that the parse failed
                    return(result : editorconfigNamingStylePreferences, succeeded : false);
                }

                if (underlyingOption is NamingStylePreferences workspaceNamingStylePreferences)
                {
                    // We parsed naming styles from editorconfig, append them to our existing styles
                    var combinedNamingStylePreferences = workspaceNamingStylePreferences.PrependNamingStylePreferences(editorconfigNamingStylePreferences);
                    return(result : combinedNamingStylePreferences, succeeded : true);
                }

                // no existing naming styles were passed so just return the set of styles that were parsed from editorconfig
                return(result : editorconfigNamingStylePreferences, succeeded : true);
            }
            else
            {
                return(Contract.FailWithReturn <(object, bool)>(
                           $"{nameof(NamingStylePreferenceEditorConfigStorageLocation)} can only be called with {nameof(PerLanguageOption<NamingStylePreferences>)}<{nameof(NamingStylePreferences)}>."));
            }
        }
Beispiel #2
0
        private static (object result, bool succeeded) ParseDictionary(
            IReadOnlyDictionary <string, string?> allRawConventions,
            Type type
            )
        {
            if (type == typeof(NamingStylePreferences))
            {
                var editorconfigNamingStylePreferences =
                    EditorConfigNamingStyleParser.GetNamingStylesFromDictionary(allRawConventions);

                if (
                    !editorconfigNamingStylePreferences.NamingRules.Any() &&
                    !editorconfigNamingStylePreferences.NamingStyles.Any() &&
                    !editorconfigNamingStylePreferences.SymbolSpecifications.Any()
                    )
                {
                    // We were not able to parse any rules from editorconfig, tell the caller that the parse failed
                    return(result : editorconfigNamingStylePreferences, succeeded : false);
                }

                // no existing naming styles were passed so just return the set of styles that were parsed from editorconfig
                return(result : editorconfigNamingStylePreferences, succeeded : true);
            }

            throw ExceptionUtilities.UnexpectedValue(type);
        }
Beispiel #3
0
 public EditorConfigStorageLocation()
 {
     // If the user didn't pass a keyName assume we need to parse the entire dictionary
     _parseDictionary = (dictionary, type) =>
     {
         if (type == typeof(NamingStylePreferences))
         {
             return(EditorConfigNamingStyleParser.GetNamingStylesFromDictionary(dictionary));
         }
         else
         {
             throw new NotSupportedException(WorkspacesResources.Option_0_has_an_unsupported_type_to_use_with_1_You_should_specify_a_parsing_function);
         }
     };
 }