kwargDict,
out bool paramsArray,
diff --git a/src/runtime/pyargconverter.cs b/src/runtime/pyargconverter.cs
new file mode 100644
index 000000000..cf6be7b6d
--- /dev/null
+++ b/src/runtime/pyargconverter.cs
@@ -0,0 +1,59 @@
+namespace Python.Runtime {
+ using System;
+
+ ///
+ /// Specifies how to convert Python objects, passed to .NET functions to the expected CLR types.
+ ///
+ public interface IPyArgumentConverter
+ {
+ ///
+ /// Attempts to convert an argument passed by Python to the specified parameter type.
+ ///
+ /// Unmanaged pointer to the Python argument value
+ /// The expected type of the parameter
+ /// true if the method is overloaded
+ /// This parameter will receive the converted value, matching the specified type
+ /// This parameter will be set to true,
+ /// if the final type needs to be marshaled as an out argument.
+ /// true, if the object matches requested type,
+ /// and conversion was successful, otherwise false
+ bool TryConvertArgument(IntPtr pyarg, Type parameterType,
+ bool needsResolution, out object arg, out bool isOut);
+ }
+
+ ///
+ /// Specifies an argument converter to be used, when methods in this class/assembly are called from Python.
+ ///
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct)]
+ public class PyArgConverterAttribute : Attribute
+ {
+ static readonly Type[] EmptyArgTypeList = new Type[0];
+ static readonly object[] EmptyArgList = new object[0];
+
+ ///
+ /// Gets the instance of the converter, that will be used when calling methods
+ /// of this class/assembly from Python
+ ///
+ public IPyArgumentConverter Converter { get; }
+ ///
+ /// Gets the type of the converter, that will be used when calling methods
+ /// of this class/assembly from Python
+ ///
+ public Type ConverterType { get; }
+
+ ///
+ /// Specifies an argument converter to be used, when methods
+ /// in this class/assembly are called from Python.
+ ///
+ /// Type of the converter to use.
+ /// Must implement .
+ public PyArgConverterAttribute(Type converterType)
+ {
+ if (converterType == null) throw new ArgumentNullException(nameof(converterType));
+ var ctor = converterType.GetConstructor(EmptyArgTypeList);
+ if (ctor == null) throw new ArgumentException("Specified converter must have public parameterless constructor");
+ this.Converter = (IPyArgumentConverter)ctor.Invoke(EmptyArgList);
+ this.ConverterType = converterType;
+ }
+ }
+}
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