-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make JsValue implement IConvertible (#1713)
* allow disabling ExpandoObject conversion
- Loading branch information
Showing
5 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Native; | ||
|
||
public partial class JsValue : IConvertible | ||
{ | ||
TypeCode IConvertible.GetTypeCode() | ||
{ | ||
var type = _type & ~InternalTypes.InternalFlags; | ||
return type switch | ||
{ | ||
InternalTypes.Boolean => TypeCode.Boolean, | ||
InternalTypes.String => TypeCode.String, | ||
InternalTypes.Number => TypeCode.Double, | ||
InternalTypes.Integer => TypeCode.Int32, | ||
InternalTypes.PrivateName => TypeCode.String, | ||
InternalTypes.Undefined => TypeCode.Object, | ||
InternalTypes.Null => TypeCode.Object, | ||
InternalTypes.Object => TypeCode.Object, | ||
InternalTypes.PlainObject => TypeCode.Object, | ||
InternalTypes.Array => TypeCode.Object, | ||
_ => TypeCode.Empty | ||
}; | ||
} | ||
|
||
bool IConvertible.ToBoolean(IFormatProvider? provider) | ||
{ | ||
return this.AsBoolean(); | ||
} | ||
|
||
byte IConvertible.ToByte(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
char IConvertible.ToChar(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
DateTime IConvertible.ToDateTime(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
decimal IConvertible.ToDecimal(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
double IConvertible.ToDouble(IFormatProvider? provider) | ||
{ | ||
return this.AsNumber(); | ||
} | ||
|
||
short IConvertible.ToInt16(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
int IConvertible.ToInt32(IFormatProvider? provider) | ||
{ | ||
return this.AsInteger(); | ||
} | ||
|
||
long IConvertible.ToInt64(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
sbyte IConvertible.ToSByte(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
float IConvertible.ToSingle(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
string IConvertible.ToString(IFormatProvider? provider) | ||
{ | ||
return this.AsString(); | ||
} | ||
|
||
object IConvertible.ToType(Type conversionType, IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
ushort IConvertible.ToUInt16(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
uint IConvertible.ToUInt32(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
ulong IConvertible.ToUInt64(IFormatProvider? provider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters