public override void Resolve()
        {
            ObjectGeneration baseObj;

            if (!string.IsNullOrWhiteSpace(this.BaseClassStr))
            {
                if (!this.ProtoGen.ObjectGenerationsByName.TryGetValue(this.BaseClassStr, out baseObj) ||
                    !(baseObj is ClassGeneration))
                {
                    throw new ArgumentException("Could not resolve base class object: " + this.BaseClassStr);
                }
                else
                {
                    ClassGeneration baseClass = baseObj as ClassGeneration;
                    this.BaseClass = baseClass;
                    baseClass.DerivativeClasses.Add(this);
                }
            }
        }
Esempio n. 2
0
        public void LoadInitialObjects(IEnumerable <System.Tuple <XDocument, FileInfo> > xmlDocs)
        {
            List <ObjectGeneration> unassignedObjects = new List <ObjectGeneration>();

            // Parse IDs
            foreach (var xmlDocTuple in xmlDocs)
            {
                var      xmlDoc  = xmlDocTuple.Item1;
                XElement objNode = xmlDoc.Element(XName.Get("Noggolloquy", NoggolloquyGenerator.Namespace));

                string   namespaceStr  = this.Gen.DefaultNamespace;
                XElement namespaceNode = objNode.Element(XName.Get("Namespace", NoggolloquyGenerator.Namespace));
                if (namespaceNode != null)
                {
                    namespaceStr = namespaceNode.Value;
                }

                foreach (var obj in objNode.Elements(XName.Get("Object", NoggolloquyGenerator.Namespace))
                         .And(objNode.Elements(XName.Get("Struct", NoggolloquyGenerator.Namespace))))
                {
                    ObjectGeneration objGen;
                    if (obj.Name.LocalName.Equals("Object"))
                    {
                        objGen = new ClassGeneration(Gen, this, xmlDocTuple.Item2);
                    }
                    else
                    {
                        objGen = new StructGeneration(Gen, this, xmlDocTuple.Item2);
                    }
                    objGen.Node = obj;
                    if (!string.IsNullOrWhiteSpace(namespaceStr))
                    {
                        objGen.Namespace = namespaceStr;
                    }

                    var guid = obj.GetAttribute("GUID");
                    if (string.IsNullOrWhiteSpace(guid))
                    {
                        objGen.GUID = Guid.NewGuid();
                    }
                    else
                    {
                        objGen.GUID = new Guid(guid);
                    }

                    if (obj.TryGetAttribute <ushort>("ID", out ushort id))
                    {
                        objGen.ID = id;
                    }

                    if (this.ObjectGenerationsByID.ContainsKey(objGen.GUID))
                    {
                        throw new ArgumentException("Two objects in the same protocol cannot have the same ID: " + objGen.GUID);
                    }
                    this.ObjectGenerationsByID.Add(objGen.GUID, objGen);

                    var nameNode = obj.Attribute("name");
                    if (nameNode == null)
                    {
                        throw new ArgumentException("Object must have a name");
                    }

                    string name = nameNode.Value;
                    if (this.ObjectGenerationsByName.ContainsKey(name))
                    {
                        throw new ArgumentException("Two objects in the same protocol cannot have the same name: " + name);
                    }
                    objGen.Name = name;

                    foreach (var interf in Gen.GenerationInterfaces)
                    {
                        if (obj.GetAttribute(interf.KeyString, false))
                        {
                            objGen.GenerationInterfaces.Add(interf);
                        }
                    }

                    this.ObjectGenerationsByName.Add(name, objGen);
                    this.Gen.ObjectGenerationsByDir.TryCreateValue(objGen.TargetDir.FullName).Add(objGen);
                }
            }
        }