();
+
+ public DateTime ToDateTime(IFormatProvider provider) => throw new InvalidCastException();
+ public decimal ToDecimal(IFormatProvider provider) => throw new InvalidCastException();
+
+ public object ToType(Type conversionType, IFormatProvider provider)
+ {
+ if (Converter.ToManaged(Reference, conversionType, out object? result, setError: false))
+ {
+ return result!;
+ }
+ else
+ {
+ throw new InvalidCastException();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/runtime/PythonTypes/PyString.cs b/src/runtime/PythonTypes/PyString.cs
index cdd45e2c3..d54397fcf 100644
--- a/src/runtime/PythonTypes/PyString.cs
+++ b/src/runtime/PythonTypes/PyString.cs
@@ -59,5 +59,7 @@ public static bool IsStringType(PyObject value)
{
return Runtime.PyString_Check(value.obj);
}
+
+ public override TypeCode GetTypeCode() => TypeCode.String;
}
}
diff --git a/tests/test_conversion.py b/tests/test_conversion.py
index 341b11b90..4de286b14 100644
--- a/tests/test_conversion.py
+++ b/tests/test_conversion.py
@@ -670,3 +670,10 @@ def test_int_param_resolution_required():
data = list(mri.MethodA(0x100000000, 10))
assert len(data) == 10
assert data[0] == 0
+
+def test_iconvertible_conversion():
+ change_type = System.Convert.ChangeType
+
+ assert 1024 == change_type(1024, System.Int32)
+ assert 1024 == change_type(1024, System.Int64)
+ assert 1024 == change_type(1024, System.Int16)
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy