Example #1
0
        private ISupportedProperty BuildSupportedProperty(DescriptionContext context, IClass @class, Type declaringType, PropertyInfo property)
        {
            var propertyId  = GetSupportedPropertyId(property, declaringType);
            var propertyUri = (!typeof(IEntity).IsAssignableFrom(context.Type) ? @class.Id.Uri.AddName(property.Name) :
                               context.ApiDocumentation.Context.Mappings.MappingFor(context.Type).PropertyFor(property.Name).Uri);
            var result = context.ApiDocumentation.Context.Create <ISupportedProperty>(propertyId);

            result.Readable  = property.CanRead;
            result.Writeable = property.CanWrite;
            result.Required  = (property.PropertyType.IsValueType) || (property.GetCustomAttribute <RequiredAttribute>() != null);
            var isKeyProperty = (property.GetCustomAttribute <KeyAttribute>() != null) ||
                                (property.ImplementsGeneric(typeof(IControlledEntity <>), "Key"));

            result.Property = (isKeyProperty ?
                               context.ApiDocumentation.Context.Create <IInverseFunctionalProperty>(propertyUri) :
                               context.ApiDocumentation.Context.Create <IProperty>(propertyUri));
            result.Property.Label       = property.Name;
            result.Property.Description = _xmlDocProvider.GetDescription(property);
            result.Property.Domain.Add(@class);
            IClass propertyType;
            var    itemPropertyType = (System.Reflection.TypeExtensions.IsEnumerable(property.PropertyType) ? property.PropertyType : property.PropertyType.GetItemType());

            if (!context.ContainsType(itemPropertyType))
            {
                bool requiresRdf;
                var  childContext = context.ForType(itemPropertyType);
                propertyType = BuildTypeDescription(childContext, out requiresRdf);
                childContext.Describe(propertyType, requiresRdf);
            }
            else
            {
                propertyType = context[itemPropertyType];
            }

            result.Property.Range.Add(propertyType);
            if ((System.Reflection.TypeExtensions.IsEnumerable(property.PropertyType)) && (property.PropertyType != typeof(byte[])))
            {
                return(result);
            }

            @class.SubClassOf.Add(@class.CreateRestriction(result.Property, 1u));
            return(result);
        }
        private ISupportedProperty BuildSupportedProperty(DescriptionContext context, IClass @class, Type declaringType, PropertyInfo property)
        {
            var propertyId = GetSupportedPropertyId(property, declaringType);
            var propertyUri = (!typeof(IEntity).IsAssignableFrom(context.Type) ? @class.Id.Uri.AddName(property.Name) :
                context.ApiDocumentation.Context.Mappings.MappingFor(context.Type).PropertyFor(property.Name).Uri);
            var result = context.ApiDocumentation.Context.Create<ISupportedProperty>(propertyId);
            result.Readable = property.CanRead;
            result.Writeable = property.CanWrite;
            result.Required = (property.PropertyType.IsValueType) || (property.GetCustomAttribute<RequiredAttribute>() != null);
            var isKeyProperty = (property.GetCustomAttribute<KeyAttribute>() != null) ||
                (property.ImplementsGeneric(typeof(IControlledEntity<>), "Key"));
            result.Property = (isKeyProperty ?
                context.ApiDocumentation.Context.Create<IInverseFunctionalProperty>(propertyUri) :
                context.ApiDocumentation.Context.Create<IProperty>(propertyUri));
            result.Property.Label = property.Name;
            result.Property.Description = _xmlDocProvider.GetDescription(property);
            result.Property.Domain.Add(@class);
            IClass propertyType;
            var itemPropertyType = (System.Reflection.TypeExtensions.IsEnumerable(property.PropertyType) ? property.PropertyType : property.PropertyType.GetItemType());
            if (!context.ContainsType(itemPropertyType))
            {
                bool requiresRdf;
                var childContext = context.ForType(itemPropertyType);
                propertyType = BuildTypeDescription(childContext, out requiresRdf);
                childContext.Describe(propertyType, requiresRdf);
            }
            else
            {
                propertyType = context[itemPropertyType];
            }

            result.Property.Range.Add(propertyType);
            if ((System.Reflection.TypeExtensions.IsEnumerable(property.PropertyType)) && (property.PropertyType != typeof(byte[])))
            {
                return result;
            }

            @class.SubClassOf.Add(@class.CreateRestriction(result.Property, 1u));
            return result;
        }