Exemple #1
0
        public static ElementSchemaLookup CreateLookup(Type type, PackageCache cache)
        {
            List <ElementInfo> lookup = null;

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

                var schema = child.GetTypeInfo().GetCustomAttribute <SchemaAttrAttribute>();

                if (schema == null)
                {
                    throw new InvalidOperationException($"{child} does not contain schema information");
                }

                var key = new ElementInfo(schema.NamespaceId, schema.Tag, cache.GetFactory <OpenXmlElement>(child));

                lookup.Add(key);
            }

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

            lookup.Sort(ElementInfoComparer.Instance);

            return(new ElementSchemaLookup(lookup));
        }
Exemple #2
0
        public T Create()
        {
            if (_activator is null)
            {
                lock (this)
                {
                    if (_activator is null)
                    {
                        _activator = _cache.GetFactory <T>(_property.PropertyType);
                        _cache     = null;
                        CleanUp();
                    }
                }
            }

            return(_activator());
        }