二开案例.python插件.常见问题.私有函数调用(反射)

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

二开案例.python插件.常见问题.私有函数调用(反射)

【案例】在python中访问自定义c#组件的各种方法 如果需要了解实践的可查询 IronPython 【准备工作】 服务器bin目录下自定义组件,以及相关的代码 ![image.webp](/download/0100b7c88151164a4076b82010ae9bb3e126.webp) ```csharp namespace DynamicFormPlugIn.Tools { internal class ToolsTwoArgImpl { /* * 双参数构造函数, 反射访问 */ string arg1; string arg2; public ToolsTwoArgImpl(string a, string b) { arg1 = a; arg2 = b; } private string GetMessage() { return string.Format("ToolsTwoArgImpl.GetMessage(): arg1 = {0}, arg2={1}", arg1, arg2); } } } ``` 【python案例】 ![image.webp](/download/0100803a9773cfbd4de9a77f4476792a360b.webp) ```python import clr clr.AddReference("mscorlib") clr.AddReference("System.Data") #类型容器 clr.AddReference("Kingdee.BOS.DataEntity") from System import * from System.Collections.Generic import * from System.Data import * ##反射命名空间 和类型容器 from System.Reflection import * from Kingdee.BOS import * def BarItemClick(e): if (e.BarItemKey.Equals("tbTestPython", StringComparison.OrdinalIgnoreCase)): msg =ToolsTwoArgImplTest(); this.View.ShowMessage(msg); def ToolsTwoArgImplTest(): ##私有两参数实例类调用 ans = ''; implType = TypesContainer.GetOrRegister("DynamicFormPlugIn.Tools.ToolsTwoArgImpl,DynamicFormPlugIn"); array = Array.CreateInstance(object, 2); array[0] = 'my lhs'; array[1] = 'your rhs'; implObj = Activator.CreateInstance(implType, array); flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; method = implObj.GetType().GetMethod("GetMessage",flags); paramArray = Array.CreateInstance(object, 0); ans += method.Invoke(implObj, paramArray); ans += '\r\n'; method = implObj.GetType().GetMethod("GetMessageOne",flags); paramArray = Array.CreateInstance(object, 1); paramArray[0] = 'input arg'; ans += method.Invoke(implObj, paramArray); return ans; ``` 【效果】 ![image.webp](/download/0100de54530ef6e7465f82469e1e9c8ad080.webp)

二开案例.python插件.常见问题.私有函数调用(反射)

【案例】在python中访问自定义c#组件的各种方法如果需要了解实践的可查询 IronPython【准备工作】服务器bin目录下自定义组件,以及相关的...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息