【发布时间】:2014-09-06 23:28:31
【问题描述】:
我在徘徊,如果我在某些 DLL 中有这样的代码:
public class DemoClass
{
public void TestAction(XMParams command)
{
var firstName = command.Parse<string>(Params.First, "First Name");
var lastName = command.Parse<string>(Params.Second, "Last Name");
var userData = new UserDataDto{
FirstName = firstName,
LastName = lastName
}
command.StoreValue(userData, "User Data");
}
}
是否可以检测到使用 command.Parse 的这些行,并提取这些数据: command.ParseType>(Index, Description)
和
command.StoreValue(Type, DescriptiveName);
如下所示的对象列表:
public class InputParamObj
{
public int Index {get;set;}
public string Type {get;set;}
public string Description {get;set;}
}
public class OutputObj
{
public string Type {get;set;}
public string Description {get;set;}
}
public class CommandData
{
public List<InputParamObj> InputParams {get;set;}
public OutputObj Output {get;set;}
}
注意,这段代码总是在已知方法中,例如在“TestAction”方法中。
【问题讨论】:
-
听起来根本不是反射任务。 Reflection 是一个元数据 API,允许获取有关类型、方法等的信息,而不是关于如何以及从何处调用它们的信息。我想你想要的叫做拦截,是另一个世界。请在此处查看这些技术的一个示例 (msdn.microsoft.com/en-us/library/dn178466(v=pandp.30).aspx)
标签: c# .net reflection