private static bool TryGetNamingStyleData(
            string namingRuleName,
            IReadOnlyDictionary <string, string> rawOptions,
            out NamingStyle namingStyle)
        {
            namingStyle = default;
            if (!TryGetNamingStyleTitle(namingRuleName, rawOptions, out var namingStyleTitle))
            {
                return(false);
            }

            var requiredPrefix = GetNamingRequiredPrefix(namingStyleTitle, rawOptions);
            var requiredSuffix = GetNamingRequiredSuffix(namingStyleTitle, rawOptions);
            var wordSeparator  = GetNamingWordSeparator(namingStyleTitle, rawOptions);

            if (!TryGetNamingCapitalization(namingStyleTitle, rawOptions, out var capitalization))
            {
                return(false);
            }

            namingStyle = new NamingStyle(
                Guid.NewGuid(),
                name: namingStyleTitle,
                prefix: requiredPrefix,
                suffix: requiredSuffix,
                wordSeparator: wordSeparator,
                capitalizationScheme: capitalization);

            return(true);
        }
Beispiel #2
0
        private static bool TryGetNamingStyleData(
            string namingRuleName,
            IReadOnlyDictionary <string, object> allRawConventions,
            out NamingStyle namingStyle)
        {
            namingStyle = null;
            if (!TryGetNamingStyleTitle(namingRuleName, allRawConventions, out string namingStyleTitle))
            {
                return(false);
            }

            var requiredPrefix = GetNamingRequiredPrefix(namingStyleTitle, allRawConventions);
            var requiredSuffix = GetNamingRequiredSuffix(namingStyleTitle, allRawConventions);
            var wordSeparator  = GetNamingWordSeparator(namingStyleTitle, allRawConventions);

            if (!TryGetNamingCapitalization(namingStyleTitle, allRawConventions, out var capitalization))
            {
                namingStyle = null;
                return(false);
            }

            namingStyle = new NamingStyle()
            {
                Name                 = namingStyleTitle,
                Prefix               = requiredPrefix,
                Suffix               = requiredSuffix,
                WordSeparator        = wordSeparator,
                CapitalizationScheme = capitalization
            };

            return(true);
        }
 private void SetNamingStyleListFromXElement(XElement namingStylesElement)
 {
     foreach (var namingStyleElement in namingStylesElement.Elements(nameof(NamingStyle)))
     {
         NamingStyles.Add(NamingStyle.FromXElement(namingStyleElement));
     }
 }
        private string MethodNamesArePascalCaseOptionString()
        {
            var symbolSpecification = new SymbolSpecification(
                Guid.NewGuid(),
                "Name",
                SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Method)).ToList(),
                SpecializedCollections.EmptyList<SymbolSpecification.AccessibilityKind>(),
                SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>());

            var namingStyle = new NamingStyle();
            namingStyle.CapitalizationScheme = Capitalization.PascalCase;
            namingStyle.Name = "Name";
            namingStyle.Prefix = "";
            namingStyle.Suffix = "";
            namingStyle.WordSeparator = "";


            var namingRule = new SerializableNamingRule();
            namingRule.SymbolSpecificationID = symbolSpecification.ID;
            namingRule.NamingStyleID = namingStyle.ID;
            namingRule.EnforcementLevel = DiagnosticSeverity.Error;

            var info = new SerializableNamingStylePreferencesInfo();
            info.SymbolSpecifications.Add(symbolSpecification);
            info.NamingStyles.Add(namingStyle);
            info.NamingRules.Add(namingRule);

            return info.CreateXElement().ToString();
        }
Beispiel #5
0
 public static NamingStylePreferences ReadFrom(ObjectReader reader)
 {
     return(new NamingStylePreferences(
                reader.ReadArray(r => SymbolSpecification.ReadFrom(r)),
                reader.ReadArray(r => NamingStyle.ReadFrom(r)),
                reader.ReadArray(r => SerializableNamingRule.ReadFrom(r))));
 }
Beispiel #6
0
 public NamingRule(string title, ImmutableArray <NamingRule> children, SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
 {
     Title               = title;
     Children            = children;
     SymbolSpecification = symbolSpecification;
     NamingStyle         = namingStyle;
     EnforcementLevel    = enforcementLevel;
 }
Beispiel #7
0
 public NamingRule(string title, ImmutableArray<NamingRule> children, SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
 {
     Title = title;
     Children = children;
     SymbolSpecification = symbolSpecification;
     NamingStyle = namingStyle;
     EnforcementLevel = enforcementLevel;
 }
Beispiel #8
0
 public NamingRule(
     SymbolSpecification symbolSpecification,
     NamingStyle namingStyle,
     ReportDiagnostic enforcementLevel
     )
 {
     SymbolSpecification = symbolSpecification;
     NamingStyle         = namingStyle;
     EnforcementLevel    = enforcementLevel;
 }
        public void AddItem()
        {
            var style = new NamingStyle();
            var viewModel = new NamingStyleViewModel(style, canBeDeleted: true, notificationService: _notificationService);
            var dialog = new NamingStyleDialog(viewModel);

            if (dialog.ShowDialog().Value == true)
            {
                Items.Add(viewModel);
            }
        }
Beispiel #10
0
        internal static NamingStyle FromXElement(XElement namingStyleElement)
        {
            var result = new NamingStyle();

            result.ID                   = Guid.Parse(namingStyleElement.Attribute(nameof(ID)).Value);
            result.Name                 = namingStyleElement.Attribute(nameof(Name)).Value;
            result.Prefix               = namingStyleElement.Attribute(nameof(Prefix)).Value;
            result.Suffix               = namingStyleElement.Attribute(nameof(Suffix)).Value;
            result.WordSeparator        = namingStyleElement.Attribute(nameof(WordSeparator)).Value;
            result.CapitalizationScheme = (Capitalization)Enum.Parse(typeof(Capitalization), namingStyleElement.Attribute(nameof(CapitalizationScheme)).Value);
            return(result);
        }
        public NamingStyleViewModel(NamingStyle style, bool canBeDeleted, INotificationService notificationService)
        {
            _notificationService = notificationService;
            _style = style;
            this.ID = style.ID;
            this.RequiredPrefix = style.Prefix;
            this.RequiredSuffix = style.Suffix;
            this.WordSeparator = style.WordSeparator;
            this.ItemName = style.Name;
            this.CanBeDeleted = canBeDeleted;

            CapitalizationSchemes = new List<CapitalizationDisplay>
                {
                    new CapitalizationDisplay(Capitalization.PascalCase, ServicesVSResources.Pascal_Case_Name),
                    new CapitalizationDisplay(Capitalization.CamelCase, ServicesVSResources.camel_Case_Name),
                    new CapitalizationDisplay(Capitalization.FirstUpper, ServicesVSResources.First_word_upper),
                    new CapitalizationDisplay(Capitalization.AllUpper, ServicesVSResources.ALL_UPPER),
                    new CapitalizationDisplay(Capitalization.AllLower, ServicesVSResources.all_lower)
                };

            CapitalizationSchemeIndex = CapitalizationSchemes.IndexOf(CapitalizationSchemes.Single(s => s.Capitalization == style.CapitalizationScheme));
        }
        private static bool TryGetSerializableNamingRule(
            string namingRuleTitle,
            SymbolSpecification symbolSpec,
            NamingStyle namingStyle,
            IReadOnlyDictionary <string, string> conventionsDictionary,
            out SerializableNamingRule serializableNamingRule)
        {
            if (!TryGetRuleSeverity(namingRuleTitle, conventionsDictionary, out var severity))
            {
                serializableNamingRule = null;
                return(false);
            }

            serializableNamingRule = new SerializableNamingRule()
            {
                EnforcementLevel      = severity,
                NamingStyleID         = namingStyle.ID,
                SymbolSpecificationID = symbolSpec.ID
            };

            return(true);
        }
Beispiel #13
0
        public NamingStyleViewModel(NamingStyle style, INotificationService notificationService)
        {
            _notificationService = notificationService;
            _style = style;
            this.ID = style.ID;
            this.RequiredPrefix = style.Prefix;
            this.RequiredSuffix = style.Suffix;
            this.WordSeparator = style.WordSeparator;
            this.FirstWordGroupCapitalization = (int)style.CapitalizationScheme;
            this.NamingConventionName = style.Name;

            CapitalizationSchemes = new List<CapitalizationDisplay>
                {
                    new CapitalizationDisplay(Capitalization.PascalCase, ServicesVSResources.CapitalizationStyleExample_PascalCase),
                    new CapitalizationDisplay(Capitalization.CamelCase, ServicesVSResources.CapitalizationStyleExample_CamelCase),
                    new CapitalizationDisplay(Capitalization.FirstUpper, ServicesVSResources.CapitalizationStyleExample_FirstWordUpper),
                    new CapitalizationDisplay(Capitalization.AllUpper, ServicesVSResources.CapitalizationStyleExample_AllUpper),
                    new CapitalizationDisplay(Capitalization.AllLower, ServicesVSResources.CapitalizationStyleExample_AllLower)
                };

            CapitalizationSchemeIndex = CapitalizationSchemes.IndexOf(CapitalizationSchemes.Single(s => s.Capitalization == style.CapitalizationScheme));
        }
Beispiel #14
0
 internal static NamingStyle FromXElement(XElement namingStyleElement)
 {
     var result = new NamingStyle();
     result.ID = Guid.Parse(namingStyleElement.Attribute(nameof(ID)).Value);
     result.Name = namingStyleElement.Attribute(nameof(Name)).Value;
     result.Prefix = namingStyleElement.Attribute(nameof(Prefix)).Value;
     result.Suffix = namingStyleElement.Attribute(nameof(Suffix)).Value;
     result.WordSeparator = namingStyleElement.Attribute(nameof(WordSeparator)).Value;
     result.CapitalizationScheme = (Capitalization)Enum.Parse(typeof(Capitalization), namingStyleElement.Attribute(nameof(CapitalizationScheme)).Value);
     return result;
 }
Beispiel #15
0
 public NamingRule(SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
 {
     SymbolSpecification = symbolSpecification;
     NamingStyle = namingStyle;
     EnforcementLevel = enforcementLevel;
 }