Пример #1
0
        public static PredefinedType?SpecToPredefinedType(INakedObjectSpecificationSurface spec)
        {
            if (spec.IsFileAttachment() || spec.IsImage())
            {
                return(PredefinedType.Blob);
            }

            if (spec.IsParseable() || spec.IsCollection() || spec.IsVoid())
            {
                Type underlyingType = spec.GetUnderlyingType();
                return(TypeToPredefinedType(underlyingType));
            }
            return(null);
        }
Пример #2
0
        public static MapRepresentation GetExtensions(string friendlyname,
                                                      string description,
                                                      string pluralName,
                                                      string domainType,
                                                      bool? isService,
                                                      bool? hasParams,
                                                      bool? optional,
                                                      int? maxLength,
                                                      string pattern,
                                                      int? memberOrder,
                                                      IDictionary<string, object> customExtensions,
                                                      INakedObjectSpecificationSurface returnType) {
            var exts = new Dictionary<string, object> {
                {JsonPropertyNames.FriendlyName, friendlyname},
                {JsonPropertyNames.Description, description}
            };

            if (pluralName != null) {
                exts.Add(JsonPropertyNames.PluralName, pluralName);
            }

            if (domainType != null) {
                exts.Add(JsonPropertyNames.DomainType, domainType);
            }

            if (hasParams != null) {
                exts.Add(JsonPropertyNames.HasParams, hasParams);
            }

            if (isService != null) {
                exts.Add(JsonPropertyNames.IsService, isService);
            }

            if (optional != null) {
                exts.Add(JsonPropertyNames.Optional, optional);
            }

            if (memberOrder != null) {
                exts.Add(JsonPropertyNames.MemberOrder, memberOrder);
            }

            if (returnType != null && !returnType.IsVoid()) {
                Tuple<string, string> jsonDataType = SpecToTypeAndFormatString(returnType);
                exts.Add(JsonPropertyNames.ReturnType, jsonDataType.Item1);

                // blob and clobs are arrays so do this check first so they are not caught be the collection test after. 
                if (jsonDataType.Item1 == PredefinedType.Number.ToRoString()) {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                }
                else if (jsonDataType.Item1 == PredefinedType.String.ToRoString()) {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                    exts.Add(JsonPropertyNames.MaxLength, maxLength ?? 0);
                    exts.Add(JsonPropertyNames.Pattern, pattern ?? "");
                }
                else if (returnType.IsCollection()) {
                    exts.Add(JsonPropertyNames.ElementType, SpecToTypeAndFormatString(returnType.ElementType).Item1);
                    exts.Add(JsonPropertyNames.PluralName, returnType.ElementType.PluralName());
                }
            }

            if (customExtensions != null) {
                foreach (var kvp in customExtensions) {
                    exts.Add(kvp.Key, kvp.Value);
                }
            }

            return CreateMap(exts);
        }
Пример #3
0
        public static PredefinedType? SpecToPredefinedType(INakedObjectSpecificationSurface spec) {
            if (spec.IsFileAttachment() || spec.IsImage()) {
                return PredefinedType.Blob;
            }

            if (spec.IsParseable() || spec.IsCollection() || spec.IsVoid()) {
                Type underlyingType = spec.GetUnderlyingType();
                return TypeToPredefinedType(underlyingType);
            }
            return null;
        }
Пример #4
0
        public static MapRepresentation GetExtensions(string friendlyname,
                                                      string description,
                                                      string pluralName,
                                                      string domainType,
                                                      bool?isService,
                                                      bool?hasParams,
                                                      bool?optional,
                                                      int?maxLength,
                                                      string pattern,
                                                      int?memberOrder,
                                                      IDictionary <string, object> customExtensions,
                                                      INakedObjectSpecificationSurface returnType,
                                                      INakedObjectSpecificationSurface elementType)
        {
            var exts = new Dictionary <string, object> {
                { JsonPropertyNames.FriendlyName, friendlyname },
                { JsonPropertyNames.Description, description }
            };

            if (pluralName != null)
            {
                exts.Add(JsonPropertyNames.PluralName, pluralName);
            }

            if (domainType != null)
            {
                exts.Add(JsonPropertyNames.DomainType, domainType);
            }

            if (hasParams != null)
            {
                exts.Add(JsonPropertyNames.HasParams, hasParams);
            }

            if (isService != null)
            {
                exts.Add(JsonPropertyNames.IsService, isService);
            }

            if (optional != null)
            {
                exts.Add(JsonPropertyNames.Optional, optional);
            }

            if (memberOrder != null)
            {
                exts.Add(JsonPropertyNames.MemberOrder, memberOrder);
            }

            if (returnType != null && !returnType.IsVoid())
            {
                Tuple <string, string> jsonDataType = SpecToTypeAndFormatString(returnType);
                exts.Add(JsonPropertyNames.ReturnType, jsonDataType.Item1);

                // blob and clobs are arrays so do this check first so they are not caught be the collection test after.
                if (jsonDataType.Item1 == PredefinedType.Number.ToRoString())
                {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                }
                else if (jsonDataType.Item1 == PredefinedType.String.ToRoString())
                {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                    exts.Add(JsonPropertyNames.MaxLength, maxLength ?? 0);
                    exts.Add(JsonPropertyNames.Pattern, pattern ?? "");
                }
                else if (returnType.IsCollection())
                {
                    exts.Add(JsonPropertyNames.ElementType, SpecToTypeAndFormatString(elementType).Item1);
                    exts.Add(JsonPropertyNames.PluralName, elementType.PluralName());
                }
            }

            if (customExtensions != null)
            {
                foreach (var kvp in customExtensions)
                {
                    exts.Add(kvp.Key, kvp.Value);
                }
            }

            return(CreateMap(exts));
        }