复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Member
/// </summary>
namespace Insus.NET
{
public class Member
{
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
public Member()
{
//
// TODO: Add constructor logic here
//
}
}
}
复制代码 代码如下:
using Insus.NET;
using System.Reflection;
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
using System.Reflection;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//实例化类
Member objMember = new Member();
//对属性set值
PropertyInfo pi = objMember.GetType().GetProperty("Name", BindingFlags.Public | BindingFlags.Instance);
if (null != pi && pi.CanWrite)
{
pi.SetValue(objMember, "Insus.NET", null);
}
//对属性get值
PropertyInfo pii = objMember.GetType().GetProperty("Name", BindingFlags.Public | BindingFlags.Instance);
if (null != pii && pi.CanRead)
{
object obj_Name = pii.GetValue(objMember, null);
Response.Write(obj_Name.ToString());
}
}
}
新闻热点
疑难解答
图片精选