/// <summary> /// Constructor /// </summary> /// <param name="value">The value that the element should wrap.</param> /// <param name="outputAttribute">The output attribute for the value.</param> public ValueElement(object value, OutputAttribute outputAttribute) { bool gotValue = false; this.RealValue = value; if (value is bool b) { Keyword keyword = b ? (outputAttribute.TrueKeyword == Keyword.Undefined ? Keyword.On : outputAttribute.TrueKeyword) : (outputAttribute.FalseKeyword == Keyword.Undefined ? Keyword.Off : outputAttribute.FalseKeyword); if (keyword == Keyword.Null) { this.active = false; return; } value = keyword; } if (outputAttribute.Rgb && value is Color color) { value = Color.ToRgb(color); } switch (value) { case Enum _: KeywordAttribute attr = value.GetType().GetField(value.ToString() !).GetCustomAttributeFast <KeywordAttribute>(); if (attr != null) { this.Value = KeywordAttribute.ToString(attr.Keyword); if (string.IsNullOrEmpty(this.Value)) { this.Value = null; } gotValue = true; } break; case IValue v: if (!v.HasValue) { this.Value = null; gotValue = true; } break; } if (!gotValue) { this.Value = value.ToString(); } }
public static string ToString(Keyword keyword) { string name; lock (Names) { if (!Names.TryGetValue(keyword, out name)) { FieldInfo field = typeof(Keyword).GetField(keyword.ToString()); KeywordAttribute attr = field.GetCustomAttributeFast <KeywordAttribute>(); name = attr.ToString(); Names.Add(keyword, name); } } return(name); }
/// <inheritdoc /> protected override string GetKeyword(ElementContext context) { return(this.active ? base.GetKeyword(context) : KeywordAttribute.ToString(context.OutputAttribute.FalseKeyword)); }
/// <summary>Gets the keyword used by this element.</summary> /// <param name="context"></param> protected virtual string GetKeyword(ElementContext context) { return(KeywordAttribute.ToString(context.OutputAttribute.Keyword)); }
public override string ToString() { return(this.Content == null ? null : string.Format("{0} {1}", KeywordAttribute.ToString(this.Keyword), this.Content)); }