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;
        }
Beispiel #2
0
        public static ISymbolModel FromJObject(JObject jObject, IParameterSymbolLocalizationModel localization)
        {
            ParameterSymbol symbol = new ParameterSymbol
            {
                Binding             = jObject.ToString(nameof(Binding)),
                DefaultValue        = 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 = ReadReplacementContexts(jObject),
            };

            if (!jObject.TryGetValue(nameof(symbol.Forms), StringComparison.OrdinalIgnoreCase, out JToken formsToken) || !(formsToken is JObject formsObject))
            {
                symbol.Forms = SymbolValueFormsModel.Empty;
            }
            else
            {
                symbol.Forms = SymbolValueFormsModel.FromJObject(formsObject);
            }

            Dictionary <string, string> choicesAndDescriptions = new Dictionary <string, string>();

            if (symbol.DataType == "choice")
            {
                symbol.IsTag   = jObject.ToBool(nameof(IsTag), true);
                symbol.TagName = jObject.ToString(nameof(TagName));

                foreach (JObject choiceObject in jObject.Items <JObject>(nameof(Choices)))
                {
                    string choice = choiceObject.ToString("choice");

                    if (localization == null ||
                        !localization.ChoicesAndDescriptions.TryGetValue(choice, out string choiceDescription))
                    {
                        choiceDescription = choiceObject.ToString("description");
                    }
                    choicesAndDescriptions.Add(choice, choiceDescription ?? string.Empty);
                }
            }

            symbol.Choices = choicesAndDescriptions;

            return(symbol);
        }