public string GetComponentData() { Dictionary <string, object> properties = new Dictionary <string, object>(); Component.Serialize(properties); return(ComponentDataString.ConvertToString(properties)); }
public static string SerializeToString(this Component component) { Dictionary <string, object> properties = new Dictionary <string, object>(); component.Serialize(properties); return(ComponentDataString.ConvertToString(properties)); }
/// <summary> /// Serializes the specified component. /// </summary> /// <param name="component"></param> public void AddComponent(Component component) { Dictionary <string, object> properties = new Dictionary <string, object>(); component.Serialize(properties); string serialized = ComponentDataString.ConvertToString(properties, ","); m_builder.AppendLine(serialized); }
public static Component Create(string data) { // Load data data = data.Replace(",", "\r\n"); Dictionary <string, object> properties = ComponentDataString.ConvertToDictionary(data); // Find component description ComponentDescription description; if (properties.ContainsKey("@rid")) { description = ComponentHelper.FindDescriptionByRuntimeID(int.Parse(properties["@rid"].ToString())); } else if (properties.ContainsKey("@guid")) { description = ComponentHelper.FindDescription(new Guid(properties["@guid"].ToString())); } else { description = ComponentHelper.FindDescription(properties["@type"].ToString()); } Component newComponent = new Component(description); // Apply configuration if (properties.ContainsKey("@config")) { ComponentConfiguration configuration = description.Metadata.Configurations.FirstOrDefault(item => item.Name == properties["@config"].ToString()); if (configuration != null) { foreach (var setter in configuration.Setters) { if (!properties.ContainsKey(setter.Key)) { properties.Add(setter.Key, setter.Value); } else { properties[setter.Key] = setter.Value; } } } } // Load other properties newComponent.Deserialize(properties); newComponent.ResetConnections(); if (newComponent.Editor != null) { newComponent.Editor.Update(); } return(newComponent); }