-
Notifications
You must be signed in to change notification settings - Fork 752
Enable user classes to override how Python.NET processes parameters of their functions #835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c355bd6
introduced IPyArgumentConverter interface, that controls marshaling o…
lostmsu b5cae6c
enabled an ability to override Python to .NET argument coversion usin…
lostmsu bea9e0d
mentioned PyArgConverter in the CHANGELOG.md
lostmsu 11a3ee6
fixed pyargconverter.cs not included into the older project file
lostmsu 9c81661
moved default arg converter to its own file; cached converter lookup
lostmsu b6421e9
fixed defaultpyargconverter.cs not included in the older project file
lostmsu 6cd7bd4
when looking for a custom argument converter look at base types too
lostmsu
10000
Jun 13, 2019
56ca4c9
a test to ensure it is possible to override argument conversion for i…
lostmsu 7f894fa
fixed MarshallerOverride test
lostmsu aaafea8
fixed crash in MethodBinder.Bind when MethodInfo to invoke is passed …
lostmsu 3804438
Merge branch 'master' into PR/PyArgConverter
lostmsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
introduced IPyArgumentConverter interface, that controls marshaling o…
…f Python objects when calling .NET methods
- Loading branch information
commit c355bd6995487eb5d0c993821f97a02207290a4c
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,47 @@ | ||
namespace Python.Runtime { | ||
using System; | ||
|
||
/// <summary> | ||
/// Specifies how to convert Python objects, passed to .NET functions to the expected CLR types. | ||
/// </summary> | ||
public interface IPyArgumentConverter | ||
{ | ||
/// <summary> | ||
/// Attempts to convert an argument passed by Python to the specified parameter type. | ||
/// </summary> | ||
/// <param name="pyarg">Unmanaged pointer to the Python argument value</param> | ||
/// <param name="parameterType">The expected type of the parameter</param> | ||
/// <param name="needsResolution"><c>true</c> if the method is overloaded</param> | ||
/// <param name="arg">This parameter will receive the converted value, matching the specified type</param> | ||
/// <param name="isOut">This parameter will be set to <c>true</c>, | ||
/// if the final type needs to be marshaled as an out argument.</param> | ||
/// <returns><c>true</c>, if the object matches requested type, | ||
/// and conversion was successful, otherwise <c>false</c></returns> | ||
bool TryConvertArgument(IntPtr pyarg, Type parameterType, | ||
bool needsResolution, out object arg, out bool isOut); | ||
} | ||
|
||
public class DefaultPyArgumentConverter: IPyArgumentConverter { | ||
public static DefaultPyArgumentConverter Instance { get; }= new DefaultPyArgumentConverter(); | ||
|
||
/// <summary> | ||
/// Attempts to convert an argument passed by Python to the specified parameter type. | ||
/// </summary> | ||
/// <param name="pyarg">Unmanaged pointer to the Python argument value</param> | ||
/// <param name="parameterType">The expected type of the parameter</param> | ||
/// <param name="needsResolution"><c>true</c> if the method is overloaded</param> | ||
/// <param name="arg">This parameter will receive the converted value, matching the specified type</param> | ||
/// <param name="isOut">This parameter will be set to <c>true</c>, | ||
/// if the final type needs to be marshaled as an out argument.</param> | ||
/// <returns><c>true</c>, if the object matches requested type, | ||
/// and conversion was successful, otherwise <c>false</c></returns> | ||
public virtual bool TryConvertArgument( | ||
IntPtr pyarg, Type parameterType, bool needsResolution, | ||
out object arg, out bool isOut) | ||
{ | ||
return MethodBinder.TryConvertArgument( | ||
pyarg, parameterType, needsResolution, | ||
out arg, out isOut); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.