protected void CreateSubNodes(XmlDocument xdoc, XmlNode node, string name, IRuntimeSemanticType val) { XmlNode subnode = xdoc.CreateElement(name); node.AppendChild(subnode); Type t = val.GetType(); t.GetProperties(BindingFlags.Instance | BindingFlags.Public).ForEach(p => { object val2 = p.GetValue(val); if (val2 != null) { // If this is a collection... if (val2 is List <dynamic> ) { // Must be a collection of semantic types! CreateSubNodes(xdoc, subnode, p.Name, (List <dynamic>)val2); } else if (val2 is ICarrier) { CreateSubNodes(xdoc, subnode, p.Name, (ICarrier)val2); } else if (val2 is IRuntimeSemanticType) { CreateSubNodes(xdoc, subnode, p.Name, (IRuntimeSemanticType)val2); } else { subnode.Attributes.Append(CreateAttribute(xdoc, p.Name, val2.ToString())); } } }); }
/// <summary> /// Given a ST instance, remove it from the instances collection, including all children. /// </summary> /// <param name="instance"></param> public void Destroy(IRuntimeSemanticType instance) { GetChildInstances(instance).ForEach(child => Destroy(child)); Guid key = Instances.Single(kvp => kvp.Value.Instance == instance).Key; Instances.Remove(key); }
/// <summary> /// Create an instance of the specified type, adding it to the Instances collection. /// </summary> public IRuntimeSemanticType Create(string typeName, IRuntimeSemanticType parent = null) { Assert.That(SemanticTypes.ContainsKey(typeName), "The semantic type " + typeName + " has not been declared."); IRuntimeSemanticType t = (IRuntimeSemanticType)CompiledAssembly.CreateInstance("SemanticTypes." + typeName); t.Initialize(this); Guid guid = Guid.NewGuid(); // We create a unique key for this instance. Instances[guid] = (new SemanticTypeInstance() { Name = typeName, Instance = t, Parent = parent, Key = guid, Definition = SemanticTypes[typeName] }); NewSemanticType.Fire(this, new NewSemanticTypeEventArgs(t)); return(t); }
/// <summary> /// Return all the child ST instances of the specified ST instance. /// </summary> protected List <IRuntimeSemanticType> GetChildInstances(IRuntimeSemanticType instance) { List <IRuntimeSemanticType> children = Instances.Where(kvp => kvp.Value.Parent == instance).Select(i => i.Value.Instance).ToList(); return(children); }
public NewSemanticTypeEventArgs(IRuntimeSemanticType newType) { Type = newType; }
protected void CreateSubNodes(XmlDocument xdoc, XmlNode node, string name, IRuntimeSemanticType val) { XmlNode subnode = xdoc.CreateElement(name); node.AppendChild(subnode); Type t = val.GetType(); t.GetProperties(BindingFlags.Instance | BindingFlags.Public).ForEach(p => { object val2 = p.GetValue(val); if (val2 != null) { // If this is a collection... if (val2 is List<dynamic>) { // Must be a collection of semantic types! CreateSubNodes(xdoc, subnode, p.Name, (List<dynamic>)val2); } else if (val2 is ICarrier) { CreateSubNodes(xdoc, subnode, p.Name, (ICarrier)val2); } else if (val2 is IRuntimeSemanticType) { CreateSubNodes(xdoc, subnode, p.Name, (IRuntimeSemanticType)val2); } else { subnode.Attributes.Append(CreateAttribute(xdoc, p.Name, val2.ToString())); } } }); }
/// <summary> /// Return all the child ST instances of the specified ST instance. /// </summary> protected List<IRuntimeSemanticType> GetChildInstances(IRuntimeSemanticType instance) { List<IRuntimeSemanticType> children = Instances.Where(kvp => kvp.Value.Parent == instance).Select(i => i.Value.Instance).ToList(); return children; }
/// <summary> /// Create an instance of the specified type, adding it to the Instances collection. /// </summary> public IRuntimeSemanticType Create(string typeName, IRuntimeSemanticType parent = null) { Assert.That(SemanticTypes.ContainsKey(typeName), "The semantic type "+typeName+" has not been declared."); IRuntimeSemanticType t = (IRuntimeSemanticType)CompiledAssembly.CreateInstance("SemanticTypes." + typeName); t.Initialize(this); Guid guid = Guid.NewGuid(); // We create a unique key for this instance. Instances[guid] = (new SemanticTypeInstance() { Name = typeName, Instance = t, Parent = parent, Key = guid, Definition = SemanticTypes[typeName] }); NewSemanticType.Fire(this, new NewSemanticTypeEventArgs(t)); return t; }