public override string ToString() { switch (this.Type) { case PropertyType.Bool: return(this.AsBool().ToString().ToLower()); case PropertyType.Byte: case PropertyType.Enum: try { EnumDescs enumDescs = new EnumDescs(); return(enumDescs.GetStringFromEnum(this.Id, this.AsEnum())); } catch (Exception) { return(this.AsEnum().ToString()); } case PropertyType.Int32: return(this.AsInt().ToString()); case PropertyType.Int64: case PropertyType.TimeSpan: return(this.AsLong().ToString()); case PropertyType.Reference: return(String.Format("0x{0:x16}", this.AsReference())); //return this.AsLong().ToString("x16"); // return this.AsLong().ToString(); case PropertyType.Float: return(this.AsFloat().ToString(new System.Globalization.CultureInfo("en-US", false).NumberFormat)); case PropertyType.String: return(this.AsString()); case PropertyType.DateTime: return(this.AsDateTime().ToShortTimeString() + " | " + this.AsDateTime().ToShortDateString()); case PropertyType.ReferenceVector: if (this.AsLongs().Count > 0) { StringBuilder sb = new StringBuilder(100); for (int j = 0; j < this.AsLongs().Count; j++) { sb.Append(String.Format("0x{0:x16}", this.AsLongs()[j])).Append(", "); } return(sb.ToString(0, sb.Length - 2)); } else { return(String.Format("empty long/reference vector")); } default: return(null); } }
public void ExportToXml(XmlTextWriter xmlWriter) { StringBuilder sb; xmlWriter.WriteStartElement("ResourceDescription"); xmlWriter.WriteStartElement("id"); xmlWriter.WriteStartAttribute("gid"); xmlWriter.WriteValue(String.Format("0x{0:x16}", this.Id)); xmlWriter.WriteStartAttribute("type"); xmlWriter.WriteValue(((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(this.Id)).ToString()); xmlWriter.WriteEndElement(); // id xmlWriter.WriteStartElement("Properties"); for (int i = 0; i < this.Properties.Count; i++) { xmlWriter.WriteStartElement("Property"); xmlWriter.WriteStartAttribute("id"); xmlWriter.WriteValue(this.Properties[i].Id.ToString()); xmlWriter.WriteStartAttribute("value"); switch (Properties[i].Type) { case PropertyType.Float: xmlWriter.WriteValue(this.Properties[i].AsFloat()); break; case PropertyType.Bool: case PropertyType.Byte: case PropertyType.Int32: case PropertyType.Int64: case PropertyType.TimeSpan: case PropertyType.DateTime: if (this.Properties[i].Id == ModelCode.IDOBJ_GID) { xmlWriter.WriteValue(String.Format("0x{0:x16}", this.Properties[i].AsLong())); } else { xmlWriter.WriteValue(this.Properties[i].AsLong()); } break; case PropertyType.Enum: try { EnumDescs enumDescs = new EnumDescs(); xmlWriter.WriteValue(enumDescs.GetStringFromEnum(this.Properties[i].Id, this.Properties[i].AsEnum())); } catch (Exception) { xmlWriter.WriteValue(this.Properties[i].AsEnum()); } break; case PropertyType.Reference: xmlWriter.WriteValue(String.Format("0x{0:x16}", this.Properties[i].AsReference())); break; case PropertyType.String: if (this.Properties[i].PropertyValue.StringValue == null) { this.Properties[i].PropertyValue.StringValue = String.Empty; } xmlWriter.WriteValue(this.Properties[i].AsString()); break; case PropertyType.Int64Vector: case PropertyType.ReferenceVector: if (this.Properties[i].AsLongs().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsLongs().Count; j++) { sb.Append(String.Format("0x{0:x16}", this.Properties[i].AsLongs()[j])).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty long/reference vector"); } break; case PropertyType.TimeSpanVector: if (this.Properties[i].AsLongs().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsLongs().Count; j++) { sb.Append(String.Format("0x{0:x16}", this.Properties[i].AsTimeSpans()[j])).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty long/reference vector"); } break; case PropertyType.Int32Vector: if (this.Properties[i].AsInts().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsInts().Count; j++) { sb.Append(String.Format("{0}", this.Properties[i].AsInts()[j])).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty int vector"); } break; case PropertyType.DateTimeVector: if (this.Properties[i].AsDateTimes().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsDateTimes().Count; j++) { sb.Append(String.Format("{0}", this.Properties[i].AsDateTimes()[j])).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty DateTime vector"); } break; case PropertyType.BoolVector: if (this.Properties[i].AsBools().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsBools().Count; j++) { sb.Append(String.Format("{0}", this.Properties[i].AsBools()[j])).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty int vector"); } break; case PropertyType.FloatVector: if (this.Properties[i].AsFloats().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsFloats().Count; j++) { sb.Append(this.Properties[i].AsFloats()[j]).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty float vector"); } break; case PropertyType.StringVector: if (this.Properties[i].AsStrings().Count > 0) { sb = new StringBuilder(100); for (int j = 0; j < this.Properties[i].AsStrings().Count; j++) { sb.Append(this.Properties[i].AsStrings()[j]).Append(", "); } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty string vector"); } break; case PropertyType.EnumVector: if (this.Properties[i].AsEnums().Count > 0) { sb = new StringBuilder(100); EnumDescs enumDescs = new EnumDescs(); for (int j = 0; j < this.Properties[i].AsEnums().Count; j++) { try { sb.Append(String.Format("{0}", enumDescs.GetStringFromEnum(this.Properties[i].Id, this.Properties[i].AsEnums()[j]))).Append(", "); } catch (Exception) { sb.Append(String.Format("{0}", this.Properties[i].AsEnums()[j])).Append(", "); } } xmlWriter.WriteValue(sb.ToString(0, sb.Length - 2)); } else { xmlWriter.WriteValue("empty enum vector"); } break; default: throw new Exception("Failed to export Resource Description as XML. Invalid property type."); } xmlWriter.WriteEndElement(); // Property } xmlWriter.WriteEndElement(); // Properties xmlWriter.WriteEndElement(); // ResourceDescription }