/// <summary>Set the field description. </summary> /// <param name="description">Field description. </param> /// <returns> A <see cref="Field{T}"/>. </returns> public Field <T> SetFieldDescription(string description) { _description = new DescribeAttribute(description); return(this); }
/// <summary> Adds a description for a value. </summary> /// <param name="value"> The value. </param> /// <param name="description"> Description of the value. </param> /// <returns> A <see cref="Field{T}"/>. </returns> public Field <T> AddDescription(object value, string description) { _valueDescriptions[value] = new DescribeAttribute(description); return(this); }
protected void ProcessEnum(JObject schema) { if (schema["enum"] != null) { var enums = (from val in (JArray)schema["enum"] select(string) val); var toDescription = new Dictionary <string, DescribeAttribute>(); var toTerms = new Dictionary <string, string[]>(); var toMaxPhrase = new Dictionary <string, int>(); JToken values; if (schema.TryGetValue("Values", out values)) { foreach (JProperty prop in values.Children()) { var key = prop.Name; if (!enums.Contains(key)) { throw new ArgumentException($"{key} is not in enumeration."); } var desc = (JObject)prop.Value; JToken description; if (desc.TryGetValue("Describe", out description)) { toDescription.Add(key, ProcessDescription(desc, Language.CamelCase(key))); } JToken terms; if (desc.TryGetValue("Terms", out terms)) { toTerms.Add(key, terms.ToObject <string[]>()); } JToken maxPhrase; if (desc.TryGetValue("MaxPhrase", out maxPhrase)) { toMaxPhrase.Add(key, (int)maxPhrase); } } } foreach (var key in enums) { DescribeAttribute description; if (!toDescription.TryGetValue(key, out description)) { description = new DescribeAttribute(Language.CamelCase(key)); } AddDescription(key, description); string[] terms; int maxPhrase; if (!toTerms.TryGetValue(key, out terms)) { terms = Language.GenerateTerms(description.Description, 3); } else if (toMaxPhrase.TryGetValue(key, out maxPhrase)) { terms = (from seed in terms from gen in Language.GenerateTerms(seed, maxPhrase) select gen).ToArray <string>(); } AddTerms(key, terms); } } }
public void LookupDictionary(string prefix, IDictionary<object, DescribeAttribute> dictionary) { foreach (var key in dictionary.Keys.ToArray()) { string skey; if (key.GetType().IsEnum) { skey = key.GetType().Name + "." + key; } else { skey = prefix + SEPARATOR + key; } string value; if (_translations.TryGetValue(skey, out value)) { DescribeAttribute old; DescribeAttribute newDesc = new DescribeAttribute(value); if (dictionary.TryGetValue(key, out old)) { newDesc.Image = old.Image; } dictionary[key] = newDesc; } } }
/// <summary> Adds a full description for a value. </summary> /// <param name="value"> The value. </param> /// <param name="description"> Description of the value. </param> /// <returns> A <see cref="Field{T}"/>. </returns> public Field <T> AddDescription(object value, DescribeAttribute description) { _valueDescriptions[value] = description; return(this); }
/// <summary> Adds a description for a value. </summary> /// <param name="value"> The value. </param> /// <param name="description"> Description of the value. </param> /// <param name="image">Image to use for value as button.</param> /// <param name="message">Message to return when button is pressed.</param> /// <returns> A <see cref="Field{T}"/>. </returns> public Field <T> AddDescription(object value, string description, string image = null, string message = null) { _valueDescriptions[value] = new DescribeAttribute(description, image, message); return(this); }
/// <summary> /// Set the full field description. /// </summary> /// <param name="description">The field description.</param> /// <returns>A <see cref="Field{T}"/>. </returns> public Field <T> SetFieldDescription(DescribeAttribute description) { _description = description; return(this); }