Esempio n. 1
0
        public object CreateObjectFieldResultScopes(object rawResult, int rank, RequestPath path)
        {
            if (rawResult == null)
            {
                return(null);
            }

            // check field depth against quota
            if (path.FieldDepth > _requestContext.Quota.MaxDepth)
            {
                this.ThrowFieldDepthExceededQuota();
            }

            switch (rank)
            {
            case 0:
                var typeDef = Field.FieldDef.TypeRef.TypeDef;
                // special cases - Union, Interface; extract actual value from box
                switch (typeDef.Kind)
                {
                case TypeKind.Union:
                    if (rawResult is UnionBase ub)
                    {
                        rawResult = ub.Value;
                    }
                    if (rawResult == null)
                    {
                        return(null);
                    }
                    break;

                case TypeKind.Interface:
                    if (rawResult == null)
                    {
                        return(null);
                    }
                    break;
                }
                var scope = new OutputObjectScope(this, path, rawResult);
                AllResultScopes.Add(scope);
                var newCount = Interlocked.Increment(ref _requestContext.Metrics.OutputObjectCount);
                // check total count against quota
                if (newCount > _requestContext.Quota.MaxOutputObjects)
                {
                    this.ThrowObjectCountExceededQuota();
                }
                return(scope);

            default: // rank > 0, array
                var list   = rawResult as IList;
                var scopes = new object[list.Count];
                for (int i = 0; i < list.Count; i++)
                {
                    scopes[i] = CreateObjectFieldResultScopes(list[i], rank - 1, path.Append(i));
                }
                return(scopes);
            }
        }
Esempio n. 2
0
        private IList <object> CreateObjectScopeList(object rawResult, int rank, RequestPath path)
        {
            var list   = (IEnumerable)rawResult;
            var scopes = new List <object>();
            var index  = 0;

            foreach (var item in list)
            {
                var itemScope = CreateObjectFieldResultScopes(item, rank - 1, path.Append(index++));
                scopes.Add(itemScope);
            }
            return(scopes);
        }