Пример #1
0
        public static object Deserialize(ref ReadOnlySpan <char> content, Type objectType)
        {
            content = ObjectParser.GetBoundaries(content);
            var tokenizer = new JsonPropertyTokenizer(ref content);

            object result = CtorStore.CreateInstance(objectType);

            while (tokenizer.HasContent)
            {
                JsonObject value = tokenizer.GetNextObject();
                value.SetOn(result);
            }

            return(result);
        }
Пример #2
0
        private static object BuildCollection(Type arrayType, out Type collectionType, out Type elementType)
        {
            if (!arrayType.IsConstructedGenericType)
            {
                throw new InvalidOperationException("The construction of non-generic collections is unsupported.");
            }

            elementType = arrayType.GetGenericArguments().Single();

            if (!arrayType.IsInterface)
            {
                collectionType = arrayType;
            }
            else
            {
                collectionType = GetCollectionType(elementType);
            }

            return(CtorStore.CreateInstance(collectionType));
        }