コード例 #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;
        }
コード例 #3
0
 /// <summary>
 /// Sets the name to use when using "ECMAScript Standard" serialization mode.
 /// A <see cref="ECMAScriptStandardReader"/> should be registered for this name.
 /// </summary>
 /// <param name="name">The name to use.</param>
 /// <param name="isCanonical">Whether this standard name is the canonical one.</param>
 /// <returns>This type info.</returns>
 public JsonTypeInfo SetECMAScriptStandardName(string name, bool isCanonical)
 {
     // This is a security check. Only these types must be the "canonical" one.
     // If other categories than Number and BigInt are defined, a similar unicity check should
     // be done somewhere.
     if (isCanonical)
     {
         if (name == "Number" && Type.Type != typeof(double))
         {
             throw new ArgumentException("The canonical 'Number' is the double.", nameof(isCanonical));
         }
         if (name == "BigInt" && Type.Type != typeof(long))
         {
             throw new ArgumentException("The canonical 'BigInt' is the long (Int64).", nameof(isCanonical));
         }
     }
     NonNullableECMAScriptStandardJsonName = new ECMAScriptStandardJsonName(name, isCanonical);
     return(this);
 }