[XmlElement("all_count")]
public long AllCount { get; set; }
[XmlElement("bulletin")]
public string Bulletin { get; set; }
//xml这块我不太熟悉,请问我能获取到all_count,bulletin吗?//传入一个已经序列化的类,得到所有的xmlelment属性值,最后拼成一个字符串返回
public long AllCount { get; set; }
[XmlElement("bulletin")]
public string Bulletin { get; set; }
//xml这块我不太熟悉,请问我能获取到all_count,bulletin吗?//传入一个已经序列化的类,得到所有的xmlelment属性值,最后拼成一个字符串返回
解决方案 »
- 请问哪里有周红安老师的21天学通C#视频教程下载
- c#+acess数据库插入问题
- 高分求解--Cell插件显示问题
- 有关dataGridView中dataGridCheckBoxColumn的问题
- 怎么把WebClint得到的得数据转成IHTMLDocument2
- 请问大虾,怎么样用socket实现文件的传输????
- c#中如何调用存储过程
- C#编程:如何实现“浏览”按钮?如何实现在上传?
- 难道分别在不同线程中的mutex.waitany(gms)与mutex.waitall(gms)不能够等待同一个mutex对象吗???
- 如何使用ASP.NET+C#技术如何来实现动态的新闻发布系统呢?
- XmlDocument.load()缺少根元素
- 这种格式的xml,怎么读进dgv呀?
[Serializable]
public class Shop : TopObject
{
public Shop(); [XmlElement("all_count")]
public long AllCount { get; set; }
[XmlElement("bulletin")]
public string Bulletin { get; set; }
[XmlElement("cid")]
public long Cid { get; set; }
[XmlElement("created")]
public string Created { get; set; }
[XmlElement("desc")]
public string Desc { get; set; }
[XmlElement("modified")]
public string Modified { get; set; }
[XmlElement("nick")]
public string Nick { get; set; }
[XmlElement("pic_path")]
public string PicPath { get; set; }
[XmlElement("remain_count")]
public long RemainCount { get; set; }
[XmlElement("shop_score")]
public ShopScore ShopScore { get; set; }
[XmlElement("sid")]
public long Sid { get; set; }
[XmlElement("title")]
public string Title { get; set; }
[XmlElement("used_count")]
public long UsedCount { get; set; }
}我想写一个方法,GetStringForObject(Type t)
假定我传入Shop,最后返回我的结果是all_count,bulletin,cid.......used_count获取这个类的 [XmlElement("created")]的结果,最后拼成一个字符串返回
{
string strObject = "";
PropertyInfo[] pis = type.GetProperties();
foreach (var pi in pis)
{
var attr = pi.GetCustomAttributes(typeof(XmlElementAttribute), true);
var elem = attr[0] as XmlElementAttribute;
strObject += elem.ElementName + ",";
}
strObject = strObject.TrimEnd(',');
return strObject;
}
{
static void Main()
{
PropertyInfo[] peroperties = typeof(A).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo property in peroperties)
{
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (objs.Length > 0)
{
Console.WriteLine("{0}: {1}", property.Name, ((DescriptionAttribute)objs[0]).Description);
}
}
Console.ReadKey();
}
}class A
{
[Description("X")]
public string X
{
get { return null; }
}
[Description("Y")]
public string Y
{
get { return null; }
}
}