System.Xml.Serialization.SerializationCodeGenerator.GetLiteral C# (CSharp) Method

GetLiteral() private method

private GetLiteral ( object ob ) : string
ob object
return string
		string GetLiteral (object ob)
		{
			if (ob == null) return "null";
			if (ob is string) return "\"" + ob.ToString().Replace("\"","\"\"") + "\"";
			if (ob is DateTime) return "new DateTime (" + ((DateTime) ob).Ticks + ")";
#if NET_2_0
			if (ob is DateTimeOffset) return "new DateTimeOffset (" + ((DateTimeOffset) ob).Ticks + ")";
#endif
			if (ob is TimeSpan) return "new TimeSpan (" + ((TimeSpan) ob).Ticks + ")";
			if (ob is bool) return ((bool)ob) ? "true" : "false";
			if (ob is XmlQualifiedName) {
				XmlQualifiedName qn = (XmlQualifiedName)ob;
				return "new XmlQualifiedName (" + GetLiteral(qn.Name) + "," + GetLiteral(qn.Namespace) + ")";
			}
			if (ob is Enum) {
				string typeName = ToCSharpFullName (ob.GetType ());
				StringBuilder sb = new StringBuilder ();
				string namedValue = Enum.Format (ob.GetType (), ob, "g");
				string[] names = namedValue.Split (',');
				foreach (string name in names) {
					// individual named constants can be seperated by a comma
					// combined with some additional whitespace characters
					string cleanName = name.Trim ();
					if (cleanName.Length == 0)
						continue;

					if (sb.Length > 0)
						sb.Append (" | ");

					sb.Append (typeName);
					sb.Append ('.');
					sb.Append (cleanName);
				}
				return sb.ToString ();
			}

			return (ob is IFormattable) ? ((IFormattable) ob).ToString (null, CultureInfo.InvariantCulture) : ob.ToString ();
		}
		
SerializationCodeGenerator