private void update() { if (_arrayProperty != null) { textBox.Text = DesignerArray.RetrieveDisplayValue(_arrayProperty.ItemList); button.Enabled = true; } else if (_structProperty != null) { //textBox.Text = "(Multiple properties)"; MethodDef method = null; Nodes.Action action = this._object as Nodes.Action; if (action != null) { method = action.Method; } textBox.Text = DesignerPropertyUtility.RetrieveDisplayValue(_structProperty.Owner, method, _structProperty.Name, _structProperty.ElmentIndexInArray); button.Enabled = true; } else { textBox.Text = "null"; //textBox.Text = DesignerPropertyUtility.RetrieveDisplayValue(_property, null, null); button.Enabled = false; } }
public override object FromStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, Type type, string str) { if (Plugin.IsCustomClassType(type)) { return(ParseStringValue(result, type, null, str, node)); } else if (Plugin.IsArrayType(type)) { return(DesignerArray.ParseStringValue(result, type, str, node)); } throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); }
/// <summary> /// Get the display string in the editor of the given object. /// </summary> /// <param name="obj">The given object.</param> /// <returns>Returns the string value for displaying the object.</returns> public static string RetrieveDisplayValue(object obj, object parent = null, string paramName = null, int indexInArray = -1) { string str = string.Empty; if (obj != null) { Type type = obj.GetType(); // ISerializableData type if (obj is ISerializableData) { str = ((ISerializableData)obj).GetDisplayValue(); } // Array type else if (Plugin.IsArrayType(type)) { str = DesignerArray.RetrieveDisplayValue(obj); } // Struct type else if (Plugin.IsCustomClassType(type)) { str = DesignerStruct.RetrieveDisplayValue(obj, parent, paramName, indexInArray); } // Enum type else if (type.IsEnum) { str = DesignerEnum.GetDisplayName(obj); } // Other types else { str = obj.ToString(); if (Plugin.IsStringType(type)) { str = string.Format("\"{0}\"", str); } else { string[] tokens = str.Split(' '); str = tokens[tokens.Length - 1]; } } } return(str); }
/// <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); }