private bool ParseCellProperty(CellDef def, XmlElement elem, string comment) { var name = elem.GetAttribute("name"); var type = elem.GetAttribute("type"); if (String.IsNullOrEmpty(name)) { return(false); } if (String.IsNullOrEmpty(type)) { return(false); } var property = new CellDef.Property { Name = name, DefaultValue = elem.InnerText.Trim(), Comment = comment }; def.Properties.Add(property); property.TypeSpec = Types.Parse(type); if (property.TypeSpec == null) { return(false); } return(true); }
private Unit Normalize(Document doc) { Unit unit = new Unit { Namespace = doc.Namespace }; if (doc.References != null) { for (int i = 0; i < doc.References.Count; ++i) { var r = doc.References[i]; if (!String.IsNullOrEmpty(r.Type) && r.Type.ToLower() == "namespace") { var reference = new Reference { Target = r.Target }; unit.References.Add(reference); } } } if (doc.Definitions != null) { for (int i = 0; i < doc.Definitions.Count; ++i) { var def = doc.Definitions[i]; if (def.Class == "cell" || def.Class == "event") { bool isEvent = (def.Class == "event"); CellDef definition = (isEvent ? new EventDef() : new CellDef()); definition.Name = def.Name; definition.Base = def.Base; if (!String.IsNullOrEmpty(def.Local) && def.Local.ToLower() == "true") { definition.IsLocal = true; } if (isEvent) { ((EventDef)definition).Id = def.Id; } if (def.Properties != null) { for (int j = 0; j < def.Properties.Count; ++j) { var p = def.Properties[j]; var property = new CellDef.Property { Name = p.Name, TypeSpec = Types.Parse(p.Type), DefaultValue = p.Default }; definition.Properties.Add(property); } } unit.Definitions.Add(definition); } else if (def.Class == "consts") { var definition = new ConstsDef { Name = def.Name }; var type = def.Type; if (String.IsNullOrEmpty(type)) { type = "int32"; } definition.Type = type; if (def.Elements != null) { for (int j = 0; j < def.Elements.Count; ++j) { var e = def.Elements[j]; var constant = new ConstsDef.Constant { Name = e.Name, Value = e.Value }; definition.Constants.Add(constant); } } unit.Definitions.Add(definition); } } } return(unit); }
private Unit Normalize(Root root) { Unit unit = new Unit { Namespace = root.Namespace }; if (root.References != null) { for (int i = 0; i < root.References.Count; ++i) { var r = root.References[i]; if (r.GetType() == typeof(NamespaceRef)) { var reference = new Reference { Target = r.Target }; unit.References.Add(reference); } } } if (root.Definitions != null) { for (int i = 0; i < root.Definitions.Count; ++i) { var def = root.Definitions[i]; if (def is Cell) { bool isEvent = (def.GetType() == typeof(Event)); Cell c = (Cell)def; CellDef definition = (isEvent ? new EventDef() : new CellDef()); definition.Name = c.Name; definition.Base = c.Base; if (!String.IsNullOrEmpty(c.Local) && c.Local.ToLower() == "true") { definition.IsLocal = true; } if (isEvent) { ((EventDef)definition).Id = ((Event)c).Id; } if (c.Properties != null) { for (int j = 0; j < c.Properties.Count; ++j) { var p = c.Properties[j]; var property = new CellDef.Property { Name = p.Name, TypeSpec = Types.Parse(p.Type), DefaultValue = p.Default }; definition.Properties.Add(property); } } unit.Definitions.Add(definition); } else if (def.GetType() == typeof(Consts)) { var c = (Consts)def; var definition = new ConstsDef { Name = c.Name }; var type = c.Type; if (String.IsNullOrEmpty(type)) { type = "int32"; } definition.Type = type; if (c.Elements != null) { for (int j = 0; j < c.Elements.Count; ++j) { var e = c.Elements[j]; var constant = new ConstsDef.Constant { Name = e.Name, Value = e.Value }; definition.Constants.Add(constant); } } unit.Definitions.Add(definition); } } } return(unit); }