protected static T FromJObject<T>(JObject jObject, IParameterSymbolLocalizationModel localization, string defaultOverride)
            where T: BaseValueSymbol, new()
        {
            T symbol = new T
            {
                Binding = jObject.ToString(nameof(Binding)),
                DefaultValue = defaultOverride ?? jObject.ToString(nameof(DefaultValue)),
                Description = localization?.Description ?? jObject.ToString(nameof(Description)) ?? string.Empty,
                FileRename = jObject.ToString(nameof(FileRename)),
                IsRequired = jObject.ToBool(nameof(IsRequired)),
                Type = jObject.ToString(nameof(Type)),
                Replaces = jObject.ToString(nameof(Replaces)),
                DataType = jObject.ToString(nameof(DataType)),
                ReplacementContexts = SymbolModelConverter.ReadReplacementContexts(jObject)
            };

            if (!jObject.TryGetValue(nameof(symbol.Forms), StringComparison.OrdinalIgnoreCase, out JToken formsToken) || !(formsToken is JObject formsObject))
            {
                // no value forms explicitly defined, use the default ("identity")
                symbol.Forms = SymbolValueFormsModel.Default;
            }
            else
            {
                // the config defines forms for the symbol. Use them.
                symbol.Forms = SymbolValueFormsModel.FromJObject(formsObject);
            }

            return symbol;
        }
Example #2
0
        public static GeneratedSymbol FromJObject(JObject jObject)
        {
            GeneratedSymbol sym = new GeneratedSymbol
            {
                Binding             = jObject.ToString(nameof(Binding)),
                Generator           = jObject.ToString(nameof(Generator)),
                Parameters          = jObject.ToJTokenDictionary(StringComparer.Ordinal, nameof(Parameters)),
                Type                = jObject.ToString(nameof(Type)),
                Replaces            = jObject.ToString(nameof(Replaces)),
                ReplacementContexts = SymbolModelConverter.ReadReplacementContexts(jObject)
            };

            return(sym);
        }