类似
[KeyField("UserName")]
public String UserName
{
get{return this._UserName;}
set{this._UserName=value;}
}
[DataField("UserPsw")]
public String UserPsw
{
get{return this._UserPsw;}
set{this._UserPsw=value;}
}
如何访问 UserName 是 [KeyField("UserName")] 而UserPsw 是[DataField("UserPsw")]
[KeyField("UserName")]
public String UserName
{
get{return this._UserName;}
set{this._UserName=value;}
}
[DataField("UserPsw")]
public String UserPsw
{
get{return this._UserPsw;}
set{this._UserPsw=value;}
}
如何访问 UserName 是 [KeyField("UserName")] 而UserPsw 是[DataField("UserPsw")]
解决方案 »
- 虚拟目录下web.config设置问题
- 急!急!急!求教关于下拉框多选DropDownCheckList的几个问题!
- asp.net 技术问题、求解。谢谢。
- ASP.net 4.5!!!
- Intelligencia.UrlRewriter 为什么我的地址不会重写?
- 字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。
- 初学.net,创建asp.net应用程序时出现错误,求教!!!!!
- VS.NET2005(C#)+Oracle网站,为什么在VS下调试能正常用,但在IIS下通过http://127.0.0.1/WEB.ASPX访问时,连接不上数据库????
- 为什么我的Session会莫名丢失?
- 请问,用.net将一个WebApplication改成WebSite的方法?
- 关于数据查询的问题
- 写了一段乱七八糟的代码(代码不长)。用来实现一个table表格的。
Type t = typeof(Scan);
PropertyInfo info = t.GetProperty("UserName");Attribute[] attrs = (Attribute[])info.GetCustomAttributes(typeof(Attribute), false);
for (int i = 0; i < attrs.Length; i++)
{
Console.WriteLine(attrs[i].ToString());
}
{
foreach(PropertyInfo pi in typeof(Person).GetProperties())
{
Console.WriteLine(pi.Name);
foreach(Attribute attr in pi.GetCustomAttributes(false))
{
if(attr is KeyFieldAttribute)
{
Console.WriteLine("\tKeyField");
}
else if(attr is DataFieldAttribute)
{
Console.WriteLine("\tDataField");
}
}
}
}
Attribute attr=System.Attribute.GetCusmtomAttribute(p,typeof(KeyField));
if(attr!=null)
....//现在可以知道当前的p准确对应的数据库字段是attr.FieldName的值,可以对p进行处理
Attribute attr=System.Attribute.GetCusmtomAttribute(p,typeof(KeyField));
if(attr!=null)
....//现在可以知道当前的p准确对应的数据库字段是attr.FieldName的值,可以对p进行处理
另外请问如何能够设置这种自定义的格式
我使用
Model.Game_News dd=new Model.Game_News();
// Type t = dd.GetType();
Type objType = dd.GetType();
PropertyInfo[] objPropertiesArray = objType.GetProperties();
foreach (PropertyInfo objProperty in objPropertiesArray)
{
System.Web.HttpContext.Current.Response.Write(string.Format("{0}={1};type={2}<br>",objProperty.Attributes,objProperty.GetValue(dd,null),objProperty.PropertyType==typeof(int)?true:false));
}
请问这个是做什么用的阿,谢谢哦``