public static ActionResultRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionResultContextFacade actionResult, RestControlFlags flags)
        {
            if (actionResult.HasResult)
            {
                IRepresentation result;

                if (actionResult.Result == null)
                {
                    result = null;
                }
                else if (actionResult.Specification.IsParseable)
                {
                    result = ScalarRepresentation.Create(oidStrategy, actionResult.Result, req, flags);
                }
                else if (actionResult.Specification.IsObject)
                {
                    result = ObjectRepresentation.Create(oidStrategy, actionResult.Result, req, flags);
                }
                else
                {
                    result = PagedListRepresentation.Create(oidStrategy, actionResult, req, flags);
                }

                return(CreateWithOptionals <ActionResultRepresentation>(new object[] { oidStrategy, req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) }));
            }
            return(new ActionResultRepresentation(oidStrategy, req, actionResult, flags));
        }
Beispiel #2
0
        public static ActionResultRepresentation Create(IOidStrategy oidStrategy, HttpRequest req, ActionResultContextFacade actionResult, RestControlFlags flags)
        {
            if (!actionResult.HasResult)
            {
                return(new ActionResultRepresentation(oidStrategy, req, actionResult, flags));
            }

            IRepresentation result = actionResult switch {
                _ when actionResult.Result == null => null,
                            _ when actionResult.Specification.IsParseable => ScalarRepresentation.Create(oidStrategy, actionResult.Result, req, flags),
                _ when actionResult.Specification.IsObject => ObjectRepresentation.Create(oidStrategy, actionResult.Result, req, flags),
                _ => PagedListRepresentation.Create(oidStrategy, actionResult, req, flags)
            };

            return(CreateWithOptionals <ActionResultRepresentation>(new object[] { oidStrategy, req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) }));
        }
    }