Exemple #1
0
        public static ReadOnlyArray <AttributeTag> GetAttributes(PackageCache cache, Type type)
        {
            return(type.GetRuntimeProperties()
                   .Select(property =>
            {
                var schema = property.GetCustomAttribute <SchemaAttrAttribute>();

                if (schema is null)
                {
                    return default;
                }

                var indexAttribute = property.GetCustomAttribute <SchemaIndexAttribute>();

                if (indexAttribute is null)
                {
                    throw new InvalidOperationException();
                }

                return new AttributeTag(
                    schema.NamespaceId,
                    schema.Tag,
                    indexAttribute.Index,
                    new OpenXmlElementPropertyAccessor(cache, property));
            })
                   .Where(tag => tag.IsValid)
                   .OrderBy(tag => tag.Order)
                   .ToArray());
        }
Exemple #2
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));
        }
        public static ReadOnlyArray <ElementProperty <OpenXmlElement> > GetElements(PackageCache cache, Type type)
        {
            SchemaIndex GetSchema(PropertyInfo property)
            {
                var index  = property.GetCustomAttribute <IndexAttribute>();
                var schema = cache.GetElementTypeInfo(property.PropertyType).Schema;

                return(new SchemaIndex(schema, index));
            }

            return(ElementPropertyCollection <OpenXmlElement> .GetProperties(cache, type, GetSchema));
        }
Exemple #4
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());
        }
Exemple #5
0
        public OpenXmlSimpleType Create()
        {
            if (_activator is null)
            {
                lock (this)
                {
                    if (_activator is null)
                    {
                        _activator = _cache.GetSimpleTypeFactory(_property.PropertyType);
                        _cache     = null;
                        CleanUp();
                    }
                }
            }

            return(_activator());
        }
        public static ReadOnlyArray <ElementProperty <T> > GetProperties(PackageCache cache, Type type, Func <PropertyInfo, SchemaIndex> getSchema)
        {
            return(type.GetRuntimeProperties()
                   .Where(property => typeof(T).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo()))
                   .Select(property =>
            {
                var schema = getSchema(property);

                if (!schema.IsValid)
                {
                    return default;
                }

                return new ElementProperty <T>(
                    schema.NamespaceId,
                    schema.Tag,
                    schema.Index,
                    new ElementPropertyAccessor <T>(cache, property));
            })
                   .Where(tag => tag.IsValid)
                   .OrderBy(tag => tag.Order)
                   .ToArray());
        }
        public static ReadOnlyArray <ElementProperty <T> > GetProperties(PackageCache cache, Type type)
        {
            return(type.GetRuntimeProperties()
                   .Where(property => typeof(T).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo()))
                   .Select(property =>
            {
                var schema = property.GetCustomAttribute <SchemaAttrAttribute>();

                if (schema is null)
                {
                    return default;
                }

                return new ElementProperty <T>(
                    schema.NamespaceId,
                    schema.Tag,
                    schema.Index,
                    new ElementPropertyAccessor <T>(cache, property));
            })
                   .Where(tag => tag.IsValid)
                   .OrderBy(tag => tag.Order)
                   .ToArray());
        }
Exemple #8
0
 public ElementPropertyAccessor(PackageCache cache, PropertyInfo property)
 {
     _property = property;
     _cache    = cache;
 }