以下に示すような名前空間があります。
namespace testnamespace
{
public class testclass : System.Web.UI.Page
{
public static string testData;
public void test()
{
string s = "fgdfgdg";
}
protected string Invoke(string methodname)
{
//string methodName = "test";
string classname = methodname.Split('-')[0];
string funcname=methodname.Split('-')[1];
Type type = Type.GetType(classname);
Activator.CreateInstance(type);
MethodInfo method = type.GetMethod(funcname);
string result = (string)method.Invoke(Activator.CreateInstance(type), null);
return result;
}
public static string testfunc(string temp)
{
hdnData = temp;
string strval= Invoke(s);
return strval;
}
}
}
以下に示すように、別のアプリケーションでこの dll を参照しています。
using testnamespace;
protected void Button1_Click(object sender, EventArgs e)
{
string test='testfunction';
string s=testfunc(test);
}
関数を public im として宣言すると、エラーが発生します
"非静的フィールド、メソッド、またはプロパティにはオブジェクト参照が必要です"
しかし、パブリック静的として宣言すると、関数だけでなく他のすべての関数にもアクセスできます。変数は静的として宣言する必要があります。そのクラスのすべての関数を静的にするのではなく、関数 testfunc だけにしたいのです。これどうやってするの?