62,265
社区成员
发帖
与我相关
我的任务
分享
public object Get()
{
int a = 10, b = 20;
return new { a = a, b = b };
}
protected void Page_Load(object sender, EventArgs e)
{
var a = Get();
Response.Write(GetValue(a, "a", true));
Response.End();
}
public object Get()
{
int a = 10, b = 20;
return new { a = a, b = b };
}
public static object GetValue(object obj, string propertyName, bool IgnoreCase)
{
object l_ret;
BindingFlags flags =
BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.Instance;
if (IgnoreCase)
flags |= BindingFlags.IgnoreCase;
PropertyInfo info =
obj.GetType().GetProperty(propertyName,flags);
//BindingFlags.IgnoreCase |
//PropertyInfo info = obj.GetType().GetProperty(propertyName, BindingFlags.);
//object l_tmp = obj.GetType().InvokeMember(propertyName, BindingFlags.GetProperty, null, obj, null);
if (info != null)
{
l_ret = info.GetValue(obj, null);
}
else
{
l_ret = null;
}
return l_ret;
}
List<object> keyval = Get();
string[] str=new string [keyval.Count];
int i = 0;
foreach (object s in keyval)
{
str[i++] = s.ToString();
}
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public object Get()
{
int a = 10, b = 20;
return new { a = a, b = b };
}
}
}