BuildTypeDescription() public method

Builds the type description.
public BuildTypeDescription ( ) : IClass
return IClass
示例#1
0
        /// <inheritdoc />
        public IClass BuildTypeDescription(DescriptionContext context, out bool requiresRdf)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.ContainsType(context.Type))
            {
                return(context.BuildTypeDescription(out requiresRdf));
            }

            if (System.Reflection.TypeExtensions.IsEnumerable(context.Type))
            {
                if (context.Type.IsList())
                {
                    return(CreateListDefinition(context, out requiresRdf, context.Type.IsGenericList()));
                }

                return(CreateCollectionDefinition(context, out requiresRdf, context.Type.IsGenericEnumerable()));
            }

            requiresRdf = false;
            Type itemType = context.Type.GetItemType();

            if (TypeDescriptions.ContainsKey(itemType))
            {
                return(BuildDatatypeDescription(context, TypeDescriptions[itemType]));
            }

            var classUri = itemType.MakeUri();

            if (typeof(IEntity).IsAssignableFrom(itemType))
            {
                classUri    = context.ApiDocumentation.Context.Mappings.MappingFor(itemType).Classes.Select(item => item.Uri).FirstOrDefault() ?? classUri;
                requiresRdf = true;
            }

            IClass result = context.ApiDocumentation.Context.Create <IClass>(classUri);

            result.Label       = itemType.MakeTypeName(false, true);
            result.Description = _xmlDocProvider.GetDescription(itemType);
            if (typeof(EntityId).IsAssignableFrom(itemType))
            {
                context.Describe(result, requiresRdf);
                return(result);
            }

            context.Prescribe(result, requiresRdf);
            SetupProperties(context.ForType(itemType), result);
            context.Describe(result, requiresRdf);
            return(result);
        }
        /// <inheritdoc />
        public IClass BuildTypeDescription(DescriptionContext context, out bool requiresRdf)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.ContainsType(context.Type))
            {
                return context.BuildTypeDescription(out requiresRdf);
            }

            if (System.Reflection.TypeExtensions.IsEnumerable(context.Type))
            {
                if (context.Type.IsList())
                {
                    return CreateListDefinition(context, out requiresRdf, context.Type.IsGenericList());
                }

                return CreateCollectionDefinition(context, out requiresRdf, context.Type.IsGenericEnumerable());
            }

            requiresRdf = false;
            Type itemType = context.Type.GetItemType();
            if (TypeDescriptions.ContainsKey(itemType))
            {
                return BuildDatatypeDescription(context, TypeDescriptions[itemType]);
            }

            var classUri = itemType.MakeUri();
            if (typeof(IEntity).IsAssignableFrom(itemType))
            {
                classUri = context.ApiDocumentation.Context.Mappings.MappingFor(itemType).Classes.Select(item => item.Uri).FirstOrDefault() ?? classUri;
                requiresRdf = true;
            }

            IClass result = context.ApiDocumentation.Context.Create<IClass>(classUri);
            result.Label = itemType.MakeTypeName(false, true);
            result.Description = _xmlDocProvider.GetDescription(itemType);
            if (typeof(EntityId).IsAssignableFrom(itemType))
            {
                context.Describe(result, requiresRdf);
                return result;
            }

            context.Prescribe(result, requiresRdf);
            SetupProperties(context.ForType(itemType), result);
            context.Describe(result, requiresRdf);
            return result;
        }
示例#3
0
        private static Rdfs.IProperty GetMappingProperty(DescriptionContext context, ParameterInfo parameter)
        {
            IClass description = context[context.Type];
            Rdfs.IProperty resultCandidate = null;
            IResource parameterType = null;
            foreach (var supportedProperty in description.SupportedProperties)
            {
                if (StringComparer.OrdinalIgnoreCase.Equals(supportedProperty.Property.Label, parameter.Name))
                {
                    return supportedProperty.Property;
                }

                if (parameterType == null)
                {
                    parameterType = (context.ContainsType(parameter.ParameterType) ? context[parameter.ParameterType] : context.BuildTypeDescription());
                }

                if (supportedProperty.Property.Range.Any(range => (range.Id == parameterType.Id) ||
                    ((range is IClass) && (((IClass)range).SubClassOf.Any(subClass => subClass.Id == parameterType.Id)))))
                {
                    resultCandidate = supportedProperty.Property;
                }
            }

            return resultCandidate;
        }
示例#4
0
        private static Rdfs.IProperty GetMappingProperty(DescriptionContext context, ParameterInfo parameter)
        {
            IClass description = context[context.Type];

            Rdfs.IProperty resultCandidate = null;
            IResource      parameterType   = null;

            foreach (var supportedProperty in description.SupportedProperties)
            {
                if (StringComparer.OrdinalIgnoreCase.Equals(supportedProperty.Property.Label, parameter.Name))
                {
                    return(supportedProperty.Property);
                }

                if (parameterType == null)
                {
                    parameterType = (context.ContainsType(parameter.ParameterType) ? context[parameter.ParameterType] : context.BuildTypeDescription());
                }

                if (supportedProperty.Property.Range.Any(range => (range.Id == parameterType.Id) ||
                                                         ((range is IClass) && (((IClass)range).SubClassOf.Any(subClass => subClass.Id == parameterType.Id)))))
                {
                    resultCandidate = supportedProperty.Property;
                }
            }

            return(resultCandidate);
        }