Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 internal GeneratedSymbol(JObject jObject)
 {
     Binding             = jObject.ToString(nameof(Binding));
     Replaces            = jObject.ToString(nameof(Replaces));
     FileRename          = jObject.ToString(nameof(FileRename));
     Type                = jObject.ToString(nameof(Type));
     ReplacementContexts = SymbolModelConverter.ReadReplacementContexts(jObject);
     DataType            = jObject.ToString(nameof(DataType));
     Generator           = jObject.ToString(nameof(Generator));
     Parameters          = jObject.ToJTokenDictionary(StringComparer.Ordinal, nameof(Parameters));
 }
Exemplo n.º 3
0
        public static GeneratedSymbol FromJObject(JObject jObject)
        {
            GeneratedSymbol sym = new GeneratedSymbol
            {
                Binding             = jObject.ToString(nameof(Binding)),
                Generator           = jObject.ToString(nameof(Generator)),
                DataType            = jObject.ToString(nameof(DataType)),
                Parameters          = jObject.ToJTokenDictionary(StringComparer.Ordinal, nameof(Parameters)),
                Type                = jObject.ToString(nameof(Type)),
                Replaces            = jObject.ToString(nameof(Replaces)),
                FileRename          = jObject.ToString(nameof(FileRename)),
                ReplacementContexts = SymbolModelConverter.ReadReplacementContexts(jObject)
            };

            return(sym);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes this instance with given JSON data.
        /// </summary>
        /// <param name="jObject"></param>
        /// <param name="defaultOverride"></param>
        protected BaseValueSymbol(JObject jObject, string defaultOverride)
        {
            Binding = jObject.ToString(nameof(Binding));
            DefaultValue = defaultOverride ?? jObject.ToString(nameof(DefaultValue));
            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(Forms), StringComparison.OrdinalIgnoreCase, out JToken formsToken) || !(formsToken is JObject formsObject))
            {
                // no value forms explicitly defined, use the default ("identity")
                Forms = SymbolValueFormsModel.Default;
            }
            else
            {
                // the config defines forms for the symbol. Use them.
                Forms = SymbolValueFormsModel.FromJObject(formsObject);
            }
        }