Пример #1
0
        public static GenObject GetContext(GenObject genObject, string className)
        {
            if (genObject == null || genObject.ClassNameIs(className))
            {
                return(genObject);
            }
            var ancestorContext = GetAncestorContext(genObject, className);

            if (ancestorContext != null && ancestorContext.ClassNameIs(className))
            {
                return(ancestorContext);
            }
            var descendentContext = GetDescendentContext(genObject, className);

            if (descendentContext != null &&
                descendentContext.ClassNameIs(className))
            {
                return(descendentContext);
            }
            if (descendentContext != null && descendentContext.Definition.IsInherited &&
                descendentContext.Definition.Parent.ClassNameIs(className))
            {
                return(descendentContext);
            }
            return(null);
        }
Пример #2
0
        private static GenObject GetDescendentContext(GenObject genObject, string className, ISubClassBase exclude = null)
        {
            var subClass = genObject.GetSubClass(className);

            if (subClass != null)
            {
                if (subClass.Definition.SubClass.IsInheritor(className))
                {
                    return(subClass.Count == 0 ? null : subClass[0]);
                }
                return(null);
            }

            foreach (var s in genObject.SubClass)
            {
                var sc = genObject.GetSubClass(s.ClassId);
                if (sc == exclude)
                {
                    continue;
                }
                if (sc.Definition.SubClass.IsInheritor(className))
                {
                    return(sc.Count == 0 ? null : sc[0]);
                }
                var descendentContext = sc.Count == 0 ? null : GetDescendentContext(sc[0], className);
                if (descendentContext != null &&
                    descendentContext.ClassName.Equals(className, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(descendentContext);
                }
            }
            return(genObject);
        }
Пример #3
0
        public GenObject(GenObject parent, ISubClassBase parentSubClass, int classId)
        {
            Parent         = parent;
            RefParent      = null;
            ParentSubClass = parentSubClass;
            ClassId        = classId;
            Attributes     = new TextList();

            if (Parent == null)
            {
                return;
            }
            GenDataBase = Parent.GenDataBase;
            if (Definition != null && Definition.IsInherited)
            {
                Contract.Assert(Definition.Parent.Inheritors.Contains(Definition),
                                "The new object is inherited, but not from its parent");
                Contract.Assert(!Definition.Parent.IsInherited && parentSubClass.ClassId == Definition.Parent.ClassId ||
                                Definition.Parent.IsInherited && parentSubClass.ClassId == Definition.Parent.Parent.ClassId,
                                "The new object is being added to the incorrect subclass");
            }
            else
            {
                Contract.Assert(parentSubClass.Definition == null || parentSubClass.Definition.SubClass.ClassId == ClassId,
                                "The new object is being assigned to the wrong subclass");
            }
        }
Пример #4
0
        public GenSubClasses(GenObject parent)
        {
            Parent = parent;
            var parentDef = Parent.Definition;

            AddInheritedSubClasses(parentDef, parent.GenDataBase);
            AddSubClasses(parentDef, parent.GenDataBase);
        }
Пример #5
0
 private GenDataBase(GenDataDef genDataDef, Dictionary <string, GenDataBase> cache)
 {
     Cache      = cache ?? new Dictionary <string, GenDataBase>();
     GenDataDef = genDataDef;
     IgnorePropertyValidation = true;
     Root = new GenObject(null, null, 0)
     {
         GenDataBase = this
     };
 }
Пример #6
0
 private static GenObject GetAncestorContext(GenObject genObject, string className)
 {
     while (true)
     {
         if (genObject.Parent == null)
         {
             return(genObject);
         }
         if (genObject.Parent.ClassName.Equals(className, StringComparison.InvariantCultureIgnoreCase))
         {
             return(genObject.Parent);
         }
         var descendentContext = GetDescendentContext(genObject.Parent, className, genObject.ParentSubClass);
         if (descendentContext != null &&
             descendentContext.ClassName.Equals(className, StringComparison.InvariantCultureIgnoreCase))
         {
             return(descendentContext);
         }
         genObject = genObject.RefParent ?? genObject.Parent;
     }
 }
Пример #7
0
        private void Navigate(GenObject c, GenDataDef f)
        {
            if (c.ClassId != _nClass)
            {
                foreach (var sc in c.SubClass)
                {
                    foreach (var s in sc)
                    {
                        Navigate(s, f);
                    }
                }
            }
            else
            {
                var sc = c.ParentSubClass;
                foreach (var pc in sc)
                {
                    var className = pc.Attributes[_xClassName];
                    if (!f.Classes.Contains(className))
                    {
                        if (f.Classes.Count <= 1)
                        {
                            f.AddSubClass("", className);
                        }
                        else
                        {
                            f.AddClass(className);
                        }
                    }
                }

                foreach (var pc in sc)
                {
                    var className = pc.Attributes[_xClassName];
                    for (var j = 0; j < pc.SubClass[_xSubClass].Count; j++)
                    {
                        var subClassName = pc.SubClass[_xSubClass][j].Attributes[_xSubClassName];
                        var relationship = _xSubClassRelationship != -1
                            ? pc.SubClass[_xSubClass][j].Attributes[_xSubClassRelationship]
                            : "";
                        var reference = _xSubClassReference != -1
                            ? pc.SubClass[_xSubClass][j].Attributes[_xSubClassReference]
                            : "";
                        if (relationship.Equals("Extends", StringComparison.InvariantCultureIgnoreCase))
                        {
                            f.AddInheritor(className, subClassName);
                        }
                        else
                        {
                            f.AddSubClass(className, subClassName, reference);
                        }
                    }
                }

                foreach (var pc in sc)
                {
                    var className = pc.Attributes[_xClassName];
                    var iClass    = f.GetClassId(className);
                    var @class    = f.GetClassDef(iClass);
                    for (var j = 0; j < pc.SubClass[_xProperty].Count; j++)
                    {
                        var name = pc.SubClass[_xProperty][j].Attributes[_xPropertyName];
                        if ([email protected] || [email protected](name))
                        {
                            @class.AddInstanceProperty(name);
                            @class.Properties.Add(name);
                        }
                    }
                }
            }
        }
Пример #8
0
 private static GenObject CreateDefinitionSubClass(string name, GenObject c)
 {
     return(DefinitionCreator.CreateDefinitionSubClass(c, name, "", ""));
 }