/// <summary> /// Get the string value when saving or exporting the given object. /// </summary> /// <param name="obj">The given object.</param> /// <returns>Returns the string value for saving or exporting the object.</returns> public static string RetrieveExportValue(object obj, object parent = null, string paramName = null) { string str = "\"\""; if (obj != null) { Type type = obj.GetType(); // ISerializableData type if (obj is ISerializableData) { str = ((ISerializableData)obj).GetExportValue(); } // Array type else if (Plugin.IsArrayType(type)) { str = DesignerArray.RetrieveExportValue(obj); } // Struct type else if (Plugin.IsCustomClassType(type)) { str = DesignerStruct.RetrieveExportValue(obj, parent, paramName, true); } // Other types else { str = obj.ToString(); if (Plugin.IsStringType(type)) { str = string.Format("\"{0}\"", str); } else if (Plugin.IsBooleanType(type)) { str = str.ToLowerInvariant(); } } } return(str); }
public static string RetrieveExportValue(object obj, object parent, string paramName, bool bSave, int indexInArray = -1) { string str = ""; Debug.Check(obj != null); Type type = obj.GetType(); if (Plugin.IsRefType(type)) { return("null"); } bool bStructAsBasic = Plugin.IsRegisteredTypeName(type.Name); //struct as basic type, like Tag::Vector3, etc. //these types are exported as (W=0 X=0 Y=0 Z=0) if (!bSave && bStructAsBasic) { str = "("; } else { str = "{"; } if (Plugin.IsCustomClassType(type)) { MethodDef method = parent as MethodDef; bool bFirst = true; IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { if (!bSave && bStructAsBasic && !bFirst) { str += " "; } bFirst = false; if (!bSave) { if (bStructAsBasic) { str += property.Property.Name + "="; } } else { str += property.Property.Name + "="; } object member = property.GetValue(obj); Type memberType = null; if (member != null) { memberType = member.GetType(); } else { memberType = property.GetTypeFallback(); } if (Plugin.IsArrayType(memberType)) { str += DesignerArray.RetrieveExportValue(member); } else { if (property.Attribute is DesignerStruct) { str += RetrieveExportValue(member, parent, paramName, bSave); } else { bool bStructProperty = false; if (method != null) { MethodDef.Param param = method.GetParam(paramName, property, indexInArray); if (param != null) { bStructProperty = true; string s = param.GetExportValue(null); if (Plugin.IsStringType(param.Value.GetType())) { str += string.Format("\"{0}\"", s); } else { str += s; } } } if (!bStructProperty) { string s = property.GetExportValue(obj); if (Plugin.IsStringType(property.Property.PropertyType)) { str += string.Format("\"{0}\"", s); } else { str += s; } } } } if (!bSave && bStructAsBasic) { } else { str += ";"; } } } } else { } if (!bSave && bStructAsBasic) { str += ")"; } else { str += "}"; } return(str); }