private static JsonTypeInfo <MyPoco> GetTypeInfo()
    {
        JsonObjectInfoValues <MyPoco> objectInfo = new()
        {
            ObjectCreator = static () => throw new NotImplementedException(),
                                  SerializeHandler = (Utf8JsonWriter writer, MyPoco value) => throw new NotImplementedException()
        };

        return(JsonMetadataServices.CreateObjectInfo <MyPoco>(new JsonSerializerOptions(), objectInfo));
    }
示例#2
0
 private static JsonTypeInfo <Queue <TValue> > CreateQueueTypeInfo <TValue>(JsonTypeInfo jsonTypeInfo)
 {
     return(JsonMetadataServices.CreateQueueInfo <Queue <TValue>, TValue>(
                options: jsonTypeInfo.Options,
                collectionInfo: new()
     {
         ObjectCreator = static () => new Queue <TValue>(),
         ElementInfo = jsonTypeInfo,
         NumberHandling = jsonTypeInfo.Options.NumberHandling
     }));
            private JsonTypeInfo <Dictionary <int, string> > CreateDictionaryConverter()
            {
                JsonTypeInfo <int>    keyInfo   = JsonMetadataServices.CreateValueInfo <int>(Options, new ConverterForInt32());
                JsonTypeInfo <string> valueInfo = JsonMetadataServices.CreateValueInfo <string>(Options, JsonMetadataServices.StringConverter);

                return(JsonMetadataServices.CreateDictionaryInfo <Dictionary <int, string>, int, string>(
                           Options,
                           createObjectFunc: () => new(),
                           keyInfo, valueInfo,
                           numberHandling: default,
            private JsonTypeInfo <Dictionary <int, string> > CreateDictionaryConverter()
            {
                JsonTypeInfo <int>    keyInfo   = JsonMetadataServices.CreateValueInfo <int>(Options, new ConverterForInt32());
                JsonTypeInfo <string> valueInfo = JsonMetadataServices.CreateValueInfo <string>(Options, JsonMetadataServices.StringConverter);
                JsonCollectionInfoValues <Dictionary <int, string> > info = new()
                {
                    ObjectCreator = () => new Dictionary <int, string>(),
                    KeyInfo       = keyInfo,
                    ElementInfo   = valueInfo,
                };

                return(JsonMetadataServices.CreateDictionaryInfo <Dictionary <int, string>, int, string>(Options, info));
            }
        private static async IAsyncEnumerable <TValue> CreateAsyncEnumerableDeserializer <TValue>(
            Stream utf8Json,
            JsonTypeInfo jsonTypeInfo,
            [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            JsonSerializerOptions          options       = jsonTypeInfo.Options;
            JsonTypeInfo <Queue <TValue> > queueTypeInfo =
                JsonMetadataServices.CreateQueueInfo <Queue <TValue>, TValue>(
                    options: options,
                    collectionInfo: new()
            {
                ObjectCreator  = () => new Queue <TValue>(),
                ElementInfo    = jsonTypeInfo,
                NumberHandling = options.NumberHandling
            });

            var       bufferState = new ReadBufferState(options.DefaultBufferSize);
            ReadStack readStack   = default;

            queueTypeInfo.EnsureConfigured();
            readStack.Initialize(queueTypeInfo, supportContinuation: true);
            var jsonReaderState = new JsonReaderState(options.GetReaderOptions());

            try
            {
                do
                {
                    bufferState = await ReadFromStreamAsync(utf8Json, bufferState, cancellationToken).ConfigureAwait(false);

                    ContinueDeserialize <Queue <TValue> >(
                        ref bufferState,
                        ref jsonReaderState,
                        ref readStack,
                        queueTypeInfo.PropertyInfoForTypeInfo.ConverterBase,
                        options);

                    if (readStack.Current.ReturnValue is Queue <TValue> queue)
                    {
                        while (queue.Count > 0)
                        {
                            yield return(queue.Dequeue());
                        }
                    }
                }while (!bufferState.IsFinalBlock);
            }
            finally
            {
                bufferState.Dispose();
            }
        }
示例#6
0
        private static JsonPropertyInfo[] PersonPropInitFunc(JsonSerializerContext context)
        {
            JsonContext           jsonContext = (JsonContext)context;
            JsonSerializerOptions options     = context.Options;

            JsonPropertyInfo[] properties = new JsonPropertyInfo[4];

            properties[0] = JsonMetadataServices.CreatePropertyInfo(
                options,
                isProperty: true,
                declaringType: typeof(Person),
                propertyTypeInfo: jsonContext.Int32,
                converter: null,
                getter: static (obj) => { return(((Person)obj).Age); },
                setter: static (obj, value) => { ((Person)obj).Age = value; },
                ignoreCondition: default,
        private static JsonPropertyInfo[] WeatherForecastWithPOCOsPropInitFunc(JsonSerializerContext context)
        {
            JsonContext           jsonContext = (JsonContext)context;
            JsonSerializerOptions options     = context.Options;

            JsonPropertyInfo[] properties = new JsonPropertyInfo[7];

            properties[0] = JsonMetadataServices.CreatePropertyInfo(
                options,
                isProperty: true,
                declaringType: typeof(WeatherForecastWithPOCOs),
                propertyTypeInfo: jsonContext.DateTimeOffset,
                converter: null,
                getter: static (obj) => { return(((WeatherForecastWithPOCOs)obj).Date); },
                setter: static (obj, value) => { ((WeatherForecastWithPOCOs)obj).Date = value; },
                ignoreCondition: default,
示例#8
0
        public void CreatePropertyInfo()
        {
            JsonSerializerOptions options = new();

            // Null options
            ArgumentNullException ane = Assert.Throws <ArgumentNullException>(() => JsonMetadataServices.CreatePropertyInfo <int>(
                                                                                  options: null,
                                                                                  isProperty: true,
                                                                                  declaringType: typeof(Point),
                                                                                  propertyTypeInfo: JsonMetadataServices.CreateValueInfo <int>(options, JsonMetadataServices.Int32Converter),
                                                                                  converter: null,
                                                                                  getter: null,
                                                                                  setter: null,
                                                                                  ignoreCondition: default,