Beispiel #1
0
        private void InstantiateHints(HintInstantiationInfoDictionary infoDictionary)
        {
            foreach (string key in infoDictionary.Keys)
            {
                var hints = new List <CodeGenHint>();
                foreach (HintInstantiationInfo info in infoDictionary[key])
                {
                    CodeGenHint hint = CreateHintFromInfo(info);
                    if (hint == null)
                    {
                        throw new ApplicationException(
                                  $"Cannot create a code generation hint of unrecognized kind '{info.Kind}'.");
                    }

                    hints.Add(hint);
                }

                this[key] = hints.ToArray();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HintDictionary"/> class.
        /// </summary>
        public HintDictionary(string dictionaryText, string typeNameSuffix = null)
        {
            _typeNameSuffix = string.IsNullOrWhiteSpace(typeNameSuffix)
                ? string.Empty
                : typeNameSuffix.Trim();

            _hintCreatorDictionary = ImmutableDictionary.CreateRange(
                new Dictionary <HintKind, HintCreator>
            {
                [HintKind.AttributeHint]         = CreateAttributeHint,
                [HintKind.BaseTypeHint]          = CreateBaseTypeNameHint,
                [HintKind.ClassNameHint]         = CreateClassNameHint,
                [HintKind.DictionaryHint]        = CreateDictionaryHint,
                [HintKind.EnumHint]              = CreateEnumHint,
                [HintKind.InterfaceHint]         = CreateInterfaceHint,
                [HintKind.PropertyModifiersHint] = CreatePropertyModifiersHint,
                [HintKind.PropertyNameHint]      = CreatePropertyNameHint
            });

            var infoDictionary = HintInstantiationInfoDictionary.Deserialize(dictionaryText);

            InstantiateHints(infoDictionary);
        }