private string ToXMLString(string linePrefix) { string str1 = "\r\n"; if (linePrefix == null) { linePrefix = ""; } StringBuilder stringBuilder = new StringBuilder(linePrefix + "<"); if (!this.sdlNamespace.Equals("")) { stringBuilder.Append(this.sdlNamespace + ":"); } stringBuilder.Append(this.name); if (this.values.Count != 0) { int num = 0; foreach (object obj in this.values) { stringBuilder.Append(" "); stringBuilder.Append("_val" + (object)num + "=\"" + SDLUtil.Format(obj, false) + "\""); ++num; } } if (this.attributes != null && this.attributes.Count != 0) { foreach (string index in this.attributes.Keys) { stringBuilder.Append(" "); string str2 = this.attributeToNamespace[index]; if (!str2.Equals("")) { stringBuilder.Append(str2 + ":"); } stringBuilder.Append(index + "="); stringBuilder.Append("\"" + SDLUtil.Format(this.attributes[index], false) + "\""); } } if (this.children.Count != 0) { stringBuilder.Append(">" + str1); foreach (Tag tag in this.children) { stringBuilder.Append(tag.ToXMLString(linePrefix + " ") + str1); } stringBuilder.Append(linePrefix + "</"); if (!this.sdlNamespace.Equals("")) { stringBuilder.Append(this.sdlNamespace + ":"); } stringBuilder.Append(this.name + ">"); } else { stringBuilder.Append("/>"); } return(((object)stringBuilder).ToString()); }
/** * An indexer for the tag's values * @param index The <c>index</c> to get or set * @return The value at the given \cindex */ public object this[int index] { get { return(values[index]); } set { valuesDirty = true; values[index] = SDLUtil.CoerceOrFail(value); } }
public static object CoerceOrFail(object obj) { bool succeeded; object obj1 = SDLUtil.TryCoerce(obj, out succeeded); if (!succeeded) { throw new ArgumentException((string)(object)obj.GetType() + (object)" is not coercible to an SDL type."); } else { return(obj1); } }
public object this[string sdlNamespace, string key] { set { this.attributesDirty = true; this.EnsureAttributesInitialized(); this.attributes[SDLUtil.ValidateIdentifier(key)] = SDLUtil.CoerceOrFail(value); if (sdlNamespace == null) { sdlNamespace = ""; } if (sdlNamespace.Length != 0) { SDLUtil.ValidateIdentifier(sdlNamespace); } this.attributeToNamespace[key] = sdlNamespace; } }
private string ToString(string linePrefix) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(linePrefix); bool flag = false; if (this.sdlNamespace.Length == 0 && this.name.Equals("content")) { flag = true; } else { if (this.sdlNamespace.Length != 0) { stringBuilder.Append(this.sdlNamespace).Append(':'); } stringBuilder.Append(this.name); } if (this.values.Count != 0) { if (flag) { flag = false; } else { stringBuilder.Append(" "); } int count = this.values.Count; for (int index = 0; index < count; ++index) { stringBuilder.Append(SDLUtil.Format(this.values[index])); if (index < count - 1) { stringBuilder.Append(" "); } } } if (this.attributes != null && this.attributes.Count != 0) { foreach (string index in this.attributes.Keys) { stringBuilder.Append(" "); string str = this.AttributeToNamespace[index]; if (!str.Equals("")) { stringBuilder.Append(str + ":"); } stringBuilder.Append(index + "="); stringBuilder.Append(SDLUtil.Format(this.attributes[index])); } } if (this.children.Count != 0) { if (!flag) { stringBuilder.Append(" "); } stringBuilder.Append("{\r\n"); foreach (Tag tag in this.children) { stringBuilder.Append(tag.ToString(linePrefix + "\t") + "\r\n"); } stringBuilder.Append(linePrefix + "}"); } return(((object)stringBuilder).ToString()); }
public void AddValue(object value) { this.valuesDirty = true; this.values.Add(SDLUtil.CoerceOrFail(value)); }
/** * Returns a string containing an XML representation of this tag. * Values will be represented using _val0, _val1, etc. * @param linePrefix A prefix to insert before every line. * @return An XML String describing this Tag */ string ToXMLString(string linePrefix) { string newLine = "\r\n"; if (linePrefix == null) { linePrefix = ""; } StringBuilder builder = new StringBuilder(linePrefix + "<"); if (!sdlNamespace.Equals("")) { builder.Append(sdlNamespace + ":"); } builder.Append(name); // output values if (values.Count != 0) { int i = 0; foreach (object val in values) { builder.Append(" "); builder.Append("_val" + i + "=\"" + SDLUtil.Format(val, false) + "\""); i++; } } // output attributes if (attributes.Count != 0) { foreach (string key in attributes.Keys) { builder.Append(" "); string attNamespace = attributeToNamespace[key]; if (!attNamespace.Equals("")) { builder.Append(attNamespace + ":"); } builder.Append(key + "="); builder.Append("\"" + SDLUtil.Format(attributes[key], false) + "\""); } } if (children.Count != 0) { builder.Append(">" + newLine); foreach (Tag t in children) { builder.Append(t.ToXMLString(linePrefix + " ") + newLine); } builder.Append(linePrefix + "</"); if (!sdlNamespace.Equals("")) { builder.Append(sdlNamespace + ":"); } builder.Append(name + ">"); } else { builder.Append("/>"); } return(builder.ToString()); }
/** * Produces a full SDL "dump" of this tag using the given prefix before * each line. * @param linePrefix Text to be prefixed to each line * @return SDL code describing this tag */ string ToString(string linePrefix) { StringBuilder sb = new StringBuilder(); sb.Append(linePrefix); bool skipValueSpace = false; if (sdlNamespace.Length == 0 && name.Equals("content")) { skipValueSpace = true; } else { if (sdlNamespace.Length != 0) { sb.Append(sdlNamespace).Append(':'); } sb.Append(name); } // output values if (values.Count != 0) { if (skipValueSpace == true) { skipValueSpace = false; } else { sb.Append(" "); } int size = values.Count; for (int i = 0; i < size; i++) { sb.Append(SDLUtil.Format(values[i])); if (i < size - 1) { sb.Append(" "); } } } // output attributes if (attributes.Count != 0) { foreach (string key in attributes.Keys) { sb.Append(" "); string attNamespace = AttributeToNamespace[key]; if (!attNamespace.Equals("")) { sb.Append(attNamespace + ":"); } sb.Append(key + "="); sb.Append(SDLUtil.Format(attributes[key])); } } // output children if (children.Count != 0) { sb.Append(" {\r\n"); foreach (Tag t in children) { sb.Append(t.ToString(linePrefix + " ") + "\r\n"); } sb.Append(linePrefix + "}"); } return(sb.ToString()); }
public static string Format(object obj, bool addQuotes) { if (obj == null) { return("null"); } if (obj is int) { return(((int)obj).ToString((IFormatProvider)CultureInfo.InvariantCulture)); } if (obj is string) { if (addQuotes) { return("\"" + SDLUtil.Escape((string)obj) + "\""); } else { return(SDLUtil.Escape((string)obj)); } } else if (obj is char) { if (addQuotes) { return("'" + SDLUtil.Escape((char)obj) + "'"); } else { return(SDLUtil.Escape((char)obj)); } } else { if (obj is Decimal) { return(((Decimal)obj).ToString((IFormatProvider)NumberFormatInfo.InvariantInfo) + "BD"); } if (obj is float) { return(((float)obj).ToString("0.######", (IFormatProvider)NumberFormatInfo.InvariantInfo) + "F"); } if (obj is long) { return(((long)obj).ToString((IFormatProvider)NumberFormatInfo.InvariantInfo) + "L"); } if (obj is byte[]) { return("[" + Convert.ToBase64String((byte[])obj) + "]"); } if (obj is bool) { return(!obj.Equals((object)true) ? "false" : "true"); } else { if (!(obj is TimeSpan)) { return(obj.ToString()); } TimeSpan timeSpan = (TimeSpan)obj; StringBuilder stringBuilder = new StringBuilder(); if (timeSpan.Days != 0) { stringBuilder.Append(timeSpan.Days).Append("d:"); string str = string.Concat((object)Math.Abs(timeSpan.Hours)); if (str.Length == 1) { str = "0" + str; } stringBuilder.Append(str); } else { if (timeSpan.Hours < 0) { stringBuilder.Append('-'); } string str = string.Concat((object)Math.Abs(timeSpan.Hours)); if (str.Length == 1) { str = "0" + str; } stringBuilder.Append(str); } stringBuilder.Append(":"); string str1 = string.Concat((object)Math.Abs(timeSpan.Minutes)); if (str1.Length == 1) { str1 = "0" + str1; } stringBuilder.Append(str1); stringBuilder.Append(":"); string str2 = string.Concat((object)Math.Abs(timeSpan.Seconds)); if (str2.Length == 1) { str2 = "0" + str2; } stringBuilder.Append(str2); if (timeSpan.Milliseconds == 0) { return(((object)stringBuilder).ToString()); } string str3 = string.Concat((object)Math.Abs(timeSpan.Milliseconds)); if (str3.Length == 1) { str3 = "00" + str3; } else if (str3.Length == 2) { str3 = "0" + str3; } stringBuilder.Append(".").Append(str3); string str4 = ((object)stringBuilder).ToString(); int index = str4.Length - 1; while (index > -1 && (int)str4[index] == 48) { --index; } return(str4.Substring(0, index + 1)); } } }
public static string Format(object obj) { return(SDLUtil.Format(obj, true)); }