コード例 #1
0
        public ConverterInterceptorFactory(Thing thing, JsonSerializerOptions options)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));

            var thingType = thing.GetType();

            _builder = Factory.CreateTypeBuilder($"{thingType.Name}Converter", thingType.Name,
                                                 typeof(IThingConverter), TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.Public);

            var methodBuilder = _builder.DefineMethod(nameof(IThingConverter.Write),
                                                      MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual,
                                                      typeof(void),
                                                      new[] { typeof(Utf8JsonWriter), typeof(Thing), typeof(JsonSerializerOptions) });

            _il = methodBuilder.GetILGenerator();
            _jsonWriterIlGenerator = new Utf8JsonWriterILGenerator(_il, _options);
        }
コード例 #2
0
 public ConvertEventIntercept(Utf8JsonWriterILGenerator jsonWriter, JsonSerializerOptions options)
 {
     _jsonWriter = jsonWriter ?? throw new ArgumentNullException(nameof(jsonWriter));
     _options    = options ?? throw new ArgumentNullException(nameof(options));
 }
コード例 #3
0
 public ConverterThingIntercept(Utf8JsonWriterILGenerator jsonWriter)
 {
     _jsonWriter = jsonWriter ?? throw new ArgumentNullException(nameof(jsonWriter));
 }