Пример #1
0
 // The factory method is JsonSerializationCodeGen.CreateTypeInfo.
 internal JsonTypeInfo(NullableTypeTree t, int number, string name, IReadOnlyList <string>?previousNames, JsonCodeGenHandler?writeHandler)
 {
     Debug.Assert(number >= 0 && t.IsNormalNull);
     Type = t;
     // We cannot use the oblivious type (that may have computed for the writeHandler) here because
     // value tuple must use their generic form (not the parentheses) in switch case.
     GenCSharpName = t.Type.ToCSharpName(useValueTupleParentheses: false);
     Number        = number;
     NumberName    = number.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
     TypeSpecOrder = -1.0f;
     // By default, the ECMAScriptStandardJsonName is the JsonName.
     NonNullableJsonName = name;
     NonNullableECMAScriptStandardJsonName = new ECMAScriptStandardJsonName(name, false);
     NonNullablePreviousJsonNames          = previousNames ?? Array.Empty <string>();
     if (t.Type.IsValueType)
     {
         NonNullHandler = new HandlerForValueType(this);
     }
     else
     {
         var n = new HandlerForReferenceType(this);
         NonNullHandler = n.ToNonNullHandler();
     }
     GenericWriteHandler = writeHandler ?? NonNullHandler;
 }
Пример #2
0
        // Untyped singleton object.
        JsonTypeInfo()
        {
            Type                = typeof(object).GetNullableTypeTree();
            GenCSharpName       = "object";
            NonNullableJsonName = "Object";
            NonNullableECMAScriptStandardJsonName = new ECMAScriptStandardJsonName("Object", true);
            NonNullablePreviousJsonNames          = Array.Empty <string>();
            Number           = -1;
            TypeSpecOrder    = -1.0f;
            NumberName       = String.Empty;
            _specializations = EmptySpecializations;
            var n = new HandlerForReferenceType(this);

            NonNullHandler      = n.ToNonNullHandler();
            GenericWriteHandler = NonNullHandler;
        }
 public HandlerForNonNullableReferenceType(HandlerForReferenceType nullHandler)
 {
     _nullHandler = nullHandler;
 }