如何通过镜像API获得静态方法的具体对象? [英] How to get concrete object of a static method via mirror API?

查看:112
本文介绍了如何通过镜像API获得静态方法的具体对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的:

class MyClass
{
   static void DoSomething(arg1, arg2){...}
}

,我能够得到这个类的ClassMirror。从这一点,我将如何获得具体的静态函数,所以我可以调用它。

Via reflection, I am able to get the ClassMirror of this class. From this point, how would I get to the concrete static function so I can call it.

注意,我试图使用:

ObjectMirror.invoke('DoSomething', [arg1, arg2]); 

它最初似乎工作,但它不支持传递复杂类型作为参数,静态函数需要一个复杂的类型作为它的一个参数。

which would initially appear to work, but it doesn't support passing of complex types as arguments, This static function requires a complex type as one of it's arguments.

理想情况下,我想获得表示静态方法的'Function'对象,直接。

Ideally, I'd like to get the 'Function' object that represents the static method so I can invoke it directly.

推荐答案

a。当前的事态是暂时的。计划是,镜像API将为您的镜像包装参数。

a. The current state of affairs is temporary. The plan is that the mirror API will wrap the arguments with mirrors for you.

b。 API最终可能支持一个getProperty方法,它将为您提供一个函数对象的Future。然而,你不会直接得到一个Function对象,所以在这种情况下这不会有什么区别。

b. The API may eventually support a getProperty method that will give you a Future on the function object. However, you will not get a Function object directly, so this won't really make any difference in this case.

c。核心思想是API基本上在镜像上工作。为了使它更可用,它应该接受非镜像作为输入,并将它们包装在镜像中。它将总是返回镜子,并在某些情况下返回期货。这就是为远程和本地案例的API工作原理。

c. The core idea is that the API fundamentally works on mirrors. To make it more usable, it should accept non-mirrors as input and wrap them in mirrors for you. It will always return mirrors, and in some cases return futures on these. This is so the API works the same for remote and local cases.

d。理解镜像的资源:

d. Resources for understanding mirrors:


  1. http:/ /www.bracha.org/mirrors.pdf (学术论文,坚韧不拔)

  2. http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LanguageisticReflectionViaMirrors_HPI.mp4 (视频,前Dart ,讨论早期的镜像系统)

  3. http:/ /gbracha.blogspot.com/2010/03/through-looking-glass-darkly.html (镜像上的一个旧的,飞镖前的博客帖子)

  4. http://www.wirfs-brock.com/allen/posts/228 (Allen Wirfs-Brock's

  5. http ://www.wirfs-brock.com/allen/posts/245

  1. http://www.bracha.org/mirrors.pdf (academic paper, tough going)
  2. http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LinguisticReflectionViaMirrors_HPI.mp4 (a video, pre-Dart, discusses earlier Mirror systems)
  3. http://gbracha.blogspot.com/2010/03/through-looking-glass-darkly.html (an old, pre-dart, blog post of mine on mirrors)
  4. http://www.wirfs-brock.com/allen/posts/228 (Allen Wirfs-Brock's blog. Allen was a mirror pioneer back in Smalltalk in the 90s)
  5. http://www.wirfs-brock.com/allen/posts/245

您也可以搜索我的博客,或 Allen Wirf-Brock的有关主题的帖子。

You can also search my blog, or Allen Wirf-Brock's for posts on the topic.

这篇关于如何通过镜像API获得静态方法的具体对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆