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); }
/// <summary> /// Creates a clone of the given <see cref="ParameterSymbol"/>. /// </summary> /// <param name="cloneFrom">The symbol to copy the values from.</param> /// <param name="bindingFallback">The value to be used for <see cref="BaseValueSymbol.Binding"/> in the case /// that the <paramref name="cloneFrom"/> does not specify a value for <see cref="BaseValueSymbol.Binding"/>.</param> /// <param name="formsFallback">The value to be used for <see cref="BaseValueSymbol.Forms"/> in the case /// that the <paramref name="cloneFrom"/> does not specify a value for <see cref="BaseValueSymbol.Forms"/>.</param> public ParameterSymbol(ParameterSymbol cloneFrom, string bindingFallback, SymbolValueFormsModel formsFallback) { DefaultValue = cloneFrom.DefaultValue; Description = cloneFrom.Description; IsRequired = cloneFrom.IsRequired; Type = cloneFrom.Type; Replaces = cloneFrom.Replaces; DataType = cloneFrom.DataType; FileRename = cloneFrom.FileRename; IsTag = cloneFrom.IsTag; TagName = cloneFrom.TagName; Choices = cloneFrom.Choices; ReplacementContexts = cloneFrom.ReplacementContexts; Binding = string.IsNullOrEmpty(cloneFrom.Binding) ? bindingFallback : cloneFrom.Binding; Forms = cloneFrom.Forms.GlobalForms.Count != 0 ? cloneFrom.Forms : formsFallback; AllowMultipleValues = cloneFrom.AllowMultipleValues; EnableQuotelessLiterals = cloneFrom.EnableQuotelessLiterals; }
/// <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); } }