c#


How to call an IronPython 2 method from C#


I can get an IronPython 2 class back to my C#. What is the new IronPython 2 way of calling a member on that class?
object ironPythonClass = scope.GetVariable("Hamish");
object[] args = new object[0];
object pythonObject = engine.Operations.Call(ironPythonClass, args);
var member = "Home";
// old way IronPython 1
// var methodResult = Ops.Invoke(this.pythonObject, SymbolTable.StringToId(member), args);
I thought all I'd have to do was
var methodResult = PythonOps.Invoke(codeContext, pythonObject, SymbolTable.StringToId(member), args);
but creating a dummy CodeContext doesn't seem to be right. I feel as though I should be able to derive one from my
code.Execute();
that runs the Python file creating the class, plus the scope that arises out of that execution.
Found a way to do it:
var ops = engine.Operations;
var x = ops.GetMember(pythonObject, member);
var h = ops.Call(x, new object[0]);
Looks like the Operations produces an OperationsObject which has useful members.
Looking at the DLR code (Microsoft.Scripting.Hosting) however I see that Call is deprecated:
[Obsolete("Use Invoke instead")]
public object Call(object obj, params object[] parameters) {
return _ops.Invoke(obj, parameters);
}
My version of scripting 0.9.20209, doesn't yet have the Invoke however.
After updating to the newer IronPython 2.6Beta and its scripting dlls I find I can write:
var h = ops.InvokeMember(pythonObject, member, new object[0]);

Related Links

C# How to use multiple interface implementations
how to create an ASP.NET Web Page to manage folders and files for loading and reading to an external server?
Thread safe calls to windows form are freezing the application
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property
Is it possible to create bidirectional relationships using only data annotations with EF Code First?
Do not unsubscribe from COMObject events can cause memory leak although I use Marshal.FinalReleaseComObject?
Parent-Child Matrix Chaining/Order Hierarchy
Invoke a non generic method with generic arguments defined in a generic class
Display ticket remaining time
Can't call Click Event on dynamic button
OdbcConnection.GetSchema(“TABLES”); not working
How to filter data in RDLC report?
defining characters to ignore while matching strings C# [closed]
How do I get the network interface and its right IPv4 address?
How can I delete a directory in a Zip file using .NET?
receiving string from c# to Java mistakes

Categories

HOME
asterisk
asp.net
repository
model-view-controller
salesforce
casting
x509certificate
okhttp3
azure-resource-manager
redhawksdr
sms
uml-designer
symfony-3.2
meson-build
doctrine2
coding-style
oxid
mbed
infopath
reportlab
web-parts
hapijs
beacon
dev-c++
angular2-pipe
datastax-enterprise
sqldependency
angular-schema-form
spock
kundera
ds-5
blockly
slim-lang
choco
luhn
javax
wunderground
yelp
linkurious
blueimp
lfe
paperclip
amazon-rds-aurora
smooth-streaming
gridgain
hdpi
cc
fileopendialog
turbolinks
jira-agile
tinybox2
database-administration
video-embedding
hana-sql-script
jquery-draggable
transbase
om
pushwoosh
winforms-interop
borland-c++
p4python
playn
autopep8
service-broker
jad
mri
applinks
crtdbg.h
xcode5
information-hiding
agent-based-modeling
javacompiler
rpt
step
amzi-prolog
twitter-finagle
dateadd
azure-caching
rssi
mixradio
zend-db-table
jython-2.5
latex-suite
servicemanager
biztalk-deployment
screensharing
certificate-revocation
winrt-async
django-1.4
diazo
helicontech
visual-leak-detector
mcpd
httppostedfilebase
flexbuilder
xpolog
funambol
n2
virtual-destructor
opengl-to-opengles
hotfix

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App