Ejemplo n.º 1
0
 public static UserDefinedClassProxy FromUserDefinedClass(UserDefinedClass userDefinedClass)
 {
     return(new UserDefinedClassProxy
     {
         DomPath = string.Format("{0}:{1}", userDefinedClass.DomPath.FullPath, userDefinedClass.DomPath.TypeNameDepth),
         Properties = userDefinedClass.Properties.Select(PropertyProxy.FromProperty).ToList(),
         CustomName = userDefinedClass.CustomName
     });
 }
 public static UserDefinedClassProxy FromUserDefinedClass(UserDefinedClass userDefinedClass)
 {
     return new UserDefinedClassProxy
     {
         DomPath = string.Format("{0}:{1}", userDefinedClass.DomPath.FullPath, userDefinedClass.DomPath.TypeNameDepth),
         Properties = userDefinedClass.Properties.Select(PropertyProxy.FromProperty).ToList(),
         CustomName = userDefinedClass.CustomName
     };
 }
Ejemplo n.º 3
0
        private void Visit(IDomElement element, UserDefinedClass currentClass, bool isNew, bool isRoot, bool metaExists)
        {
            if (element.HasElements) // if element has child elements
            {
                if (!isRoot) // if this is not the root element
                {
                    var property = element.CreateProperty(_repository);
                    currentClass.AddProperty(property, isNew, metaExists);
                }

                currentClass = _repository.GetOrAdd(element.GetDomPath(_factory), out isNew);
                isRoot = element.ActsAsRootElement;

                foreach (var childElement in element.Elements)
                {
                    Visit(childElement, currentClass, isNew, isRoot, metaExists);
                }

                foreach (var orphanedProperty in
                        currentClass.Properties.Where(
                            property => metaExists && !element.ActsAsRootElement && element.Elements.All(childElement => !property.DomPath.Equals(childElement.GetDomPath(_factory)))))
                {
                    // If there's a property that exists, but isn't present in our element's children, it should be nullable.
                    orphanedProperty.MakeNullable();
                }
            }
            else // if element has no child elements
            {
                if (isRoot) // if this is the root element
                {
                    // Make sure a class exists for the root element, no matter what.
                    _repository.GetOrAdd(element.GetDomPath(_factory));
                }
                else
                {
                    var property = element.CreateProperty(_repository);
                    currentClass.AddProperty(property, isNew, metaExists);
                }

                if (metaExists)
                {
                    // If we're refining, and this element has no children, there is a
                    // possibility that it had previous contained children. Make those
                    // children nullable.
                    currentClass = _repository.GetOrAdd(element.GetDomPath(_factory));
                    foreach (var property in currentClass.Properties)
                    {
                        property.MakeNullable();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void Visit(IDomElement element, UserDefinedClass currentClass, bool isNew, bool isRoot, bool metaExists)
        {
            if (element.HasElements) // if element has child elements
            {
                if (!isRoot)         // if this is not the root element
                {
                    var property = element.CreateProperty(_repository);
                    currentClass.AddProperty(property, isNew, metaExists);
                }

                currentClass = _repository.GetOrAdd(element.GetDomPath(_factory), out isNew);
                isRoot       = element.ActsAsRootElement;

                foreach (var childElement in element.Elements)
                {
                    Visit(childElement, currentClass, isNew, isRoot, metaExists);
                }

                foreach (var orphanedProperty in
                         currentClass.Properties.Where(
                             property => metaExists && !element.ActsAsRootElement && element.Elements.All(childElement => !property.DomPath.Equals(childElement.GetDomPath(_factory)))))
                {
                    // If there's a property that exists, but isn't present in our element's children, it should be nullable.
                    orphanedProperty.MakeNullable();
                }
            }
            else // if element has no child elements
            {
                if (isRoot) // if this is the root element
                {
                    // Make sure a class exists for the root element, no matter what.
                    _repository.GetOrAdd(element.GetDomPath(_factory));
                }
                else
                {
                    var property = element.CreateProperty(_repository);
                    currentClass.AddProperty(property, isNew, metaExists);
                }

                if (metaExists)
                {
                    // If we're refining, and this element has no children, there is a
                    // possibility that it had previous contained children. Make those
                    // children nullable.
                    currentClass = _repository.GetOrAdd(element.GetDomPath(_factory));
                    foreach (var property in currentClass.Properties)
                    {
                        property.MakeNullable();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static IEnumerable <UserDefinedClass> GetUserDefinedClassesImpl(UserDefinedClass @class)
        {
            yield return(@class);

            foreach (var childClass in @class.Properties
                     .Select(x => x.SelectedPropertyDefinition)
                     .Where(x => x != null && x.Class.IsUserDefinedClass())
                     .Select(x => x.Class.AsUserDefinedClass()))
            {
                foreach (var grandchildClass in GetUserDefinedClassesImpl(childClass))
                {
                    yield return(grandchildClass);
                }
            }
        }
Ejemplo n.º 6
0
 public static IEnumerable <UserDefinedClass> GetUsedClasses(this UserDefinedClass rootClass)
 {
     return(GetUserDefinedClassesImpl(rootClass).Distinct());
 }