jjzjj

MethodInfo

全部标签

c# - C#中的函数指针

我想在某些方面(或两者)Delegate或MethodInfo符合这个标题。但是,两者都没有提供我正在寻找的语法优美性。所以,简而言之,有什么方法可以写出以下内容:FunctionPointerfoo=//whatever,createthefunctionpointerusingmechanismsfoo();我不能使用实体委托(delegate)(即,使用delegate关键字来声明委托(delegate)类型),因为在运行时之前无法知道确切的参数列表。作为引用,这是我目前在LINQPad中玩弄的内容,其中B将(主要)是用户生成的代码,Main也是如此,因此为了美观我的用户,我正在

c# - 引用所需的重载泛型方法

给定publicClassExample{publicstaticvoidFoo(intID){}publicstaticvoidFoo(intID){}}问题:将其称为“重载泛型方法”是否正确?如何在创建MethodInfo对象时指定任一方法?TypeexampleType=Type.GetType("fullyqualifiednameOfExample,namespaceOfExample");MethodInfomi=exampleType.GetMethod("Foo",BindingFlags.Public|BindingFlags.Static,null,newType[

c# - 如何使用反射获取构造函数作为 MethodInfo

构造函数如下所示:publicNameAndValue(stringname,stringvalue)我需要使用反射将其作为MethodInfo获取。它尝试了以下操作,但没有找到构造函数(GetMethod返回null)。MethodInfoconstructor=typeof(NameAndValue).GetMethod(".ctor",new[]{typeof(string),typeof(string)});我做错了什么? 最佳答案 Type.GetConstructor.请注意,这会返回一个ConstructorInfo而

c# - 非静态方法需要 objective-c #

我有一个带有显示方法(按属性)的列表框的win表单应用程序。我试图在线程中动态调用方法,使用反射从列表框的选定值中获取方法信息。但是,在调用Methodinfo.Invoke时,我收到此内部异常“非静态方法需要objective-c#”。这是我的代码(请记住,我对C#和一般编程仍然是新手。)privatevoidPopulateComboBox(){//PopulateslistboxbygettingmethodswithdeclaredattributesMethodInfo[]methods=typeof(MainForm).GetMethods();MyTokentoken=n

c# - MethodInfo.Invoke 性能问题

我正在从一个文件中读取和写入数据。文件中的数据可以是float、double、整数等。直到运行时才知道类型。我将文件中存储的数据类型称为Tin。数据从Tout类型的数组中读取或写入。这种类型在运行时也是未知的。代码序列是这样的。在已知Tin和Tout的Open方法中,我们可以为已知数据类型创建读写方法。Open(...){MethodInfoReadMethod=typeof(...)GetMethod("ReadGeneric").MakeGenericMethod(newType[]{typeof(Tin),typeof(Tout)}));}读写循环重复数百万次并依靠反射来调用适当

c# - 使用反射检查方法是否为 "Extension Method"

作为我的应用程序的一部分,我有一个接收MethodInfo的函数,并且需要根据该方法是否为“扩展方法”对其执行特定操作。我检查了MethodInfo类,但找不到任何显示该方法是扩展的IsExtension属性或标志。有谁知道如何从方法的MethodInfo中找到它? 最佳答案 您可以在MethodInfo实例上调用IsDefined方法,通过检查ExtensionAttribute是否应用于该方法来找出这一点:boolisExtension=someMethod.IsDefined(typeof(ExtensionAttribute

c++ - 如何从指向方法的指针获取类(对象类型)

我有一个指向方法的指针:structA{intmethod(){return0;}};autofn=&A::method;我可以通过std::result_of获取返回类型,但是如何从fn获取方法的类所有者? 最佳答案 试试这个:templatestructMethodInfo;templatestructMethodInfo//methodpointer{typedefCClassType;typedefRReturnType;typedefstd::tupleArgsTuple;};templatestructMethodInf

java - 如何将jobject转换为jstring

我正在尝试获取一个字符串作为从cpp到java的函数调用的返回值。这是我的JNI调用stringGetIDJni(){cocos2d::JniMethodInfomethodInfo;if(!JniHelper::getStaticMethodInfo(methodInfo,CLASS_NAME,"GetID","()Ljava/lang/String")){return"";}jobjectretObj=methodInfo.env->CallStaticObjectMethod(methodInfo.classID,methodInfo.methodID);jstringretSt

java - 调用静态 JNI 方法以从 C++ 返回字符串

我正在尝试在Android中调用以下java方法publicstaticStringgetLevelFile(StringlevelName){/*body*/}从c++使用以下jni代码JniMethodInfoJavaApimethodInfo;if(!getStaticMethodInfo(methodInfo,"getLevelFile","(Ljava/lang/String;)Ljava/lang/String;")){returnstd::string("");}LOGD("callinggetLevelFile");jstringreturnString=(jstrin

c# - 从方法引用 C# 获取方法信息

当我们想要获取指定类型的Type实例时,我们可以使用C#typeof关键字。但是,如果我想通过引用获取方法的MethodInfo,我可以使用什么?例如,我有一个简单的控制台应用程序。它包含Program.Main方法。我想通过使用类似methodinfoof(Program.Main)的方法来获取MethodInfo。我遇到这个问题是因为方法名称可能会更改,所以我不能只为此使用Type.GetMethodInfo(stringMethodName)。我有大约10000个方法,我想为其获取MethodInfo,因此向我的方法添加任何自定义属性或任何其他内容都不是解决方案。