public static ElementLookup CreateLookup(Type type, Func <Type, Func <OpenXmlElement> > activatorFactory)
        {
            List <ElementChild> lookup = null;

            foreach (var child in GetChildTypes(type))
            {
                if (lookup == null)
                {
                    lookup = new List <ElementChild>();
                }

                var key = new ElementChild(child, activatorFactory(child));

                lookup.Add(key);
            }

            if (lookup == null)
            {
                return(Empty);
            }

            lookup.Sort(ElementChildNameComparer.Instance);

            return(new ElementLookup(lookup));
        }
Ejemplo n.º 2
0
        public static IElement CreateElementFromDescriptor(ElementDescriptor elementDescriptor)
        {
            IElement element;

            if (elementDescriptor is ElementDescriptorChild)
            {
                element = new ElementChild();
            }
            else if (elementDescriptor is ElementDescriptorInput)
            {
                element = new ElementInput();
            }
            else if (elementDescriptor is ElementDescriptorButton)
            {
                element = new ElementButton();
            }
            else if (elementDescriptor is ElementDescriptorOutput)
            {
                element = new ElementOutput();
            }
            else if (elementDescriptor is ElementDescriptorInfo)
            {
                element = new ElementInfo();
            }
            else if (elementDescriptor is ElementDescriptorMap)
            {
                element = new ElementMap();
            }
            else if (elementDescriptor is ElementDescriptorBrowser)
            {
                element = new ElementBrowser();
            }
            else
            {
                throw new Exception("Invalid descriptor");
            }

            SetSharedAttributes(element, elementDescriptor);
            element.ElementDescriptor = elementDescriptor;

            return(element);
        }