public class Article
{
    private string _Title;
    public string Title
    {
        set
        {
            this._Title = value;
        }
        get
        {
            return this._Title;
        }
    }    private string _xxx
    public string xxx{set{}get{}}    ...
} public class ArticleAbc
{
    public string GetArticle(Article aa)
    {
        return null;//别在意返回值,测试用
    }
} public class Test1
{
    Article article=new Article();
    article.Title= "new ipad上市";    string abc = GetArticle(article);
}public class Test2
{
    Article article=new Article();
    article.Title= "微软收购谷歌";
    article.xxxx= "xxxx2 ";
    article.....= ".... "    string mystr = GetArticle(article);
}
Test1里面调用GetArticle(article)的方法我只为里面参数的Title属性赋了值,其它xxx的属性我没动,而Test2里面就为很多个属性赋了值。能不能在执行GetArticle方法就直接知道哪个属性被赋值了呢?不然总是得把Article这个类里面的所有属性都判断了才知道哪个属性被赋了值,哪个是null,感觉这样做不是很好

解决方案 »

  1.   

    估计你是用来搞拼接sql语句的把?正规开发里面估计没人会去想这个问题,也就只有比较在乎sql拼接的比较在乎因为不知道你具体想干啥,我就只好泛泛的回答几个可能的方案1.使用反射取值去判定
    2.使用InofityPropertyChanged的接口去,设置修改监控点,去记录是否有更改
    3.使用类似EF,linq2sql在Iqueryable这块自己去晚解析过程 比如我自己的 dbcontext<article>.where(p=>p.Title=="微软收购谷歌")
      

  2.   


    这个没说用来干嘛的,测试随便写的程序,主要是很多地方用到实体类,是属性判断问题,调用方法传递实体类参数的时候不一定都要为每个属性赋值,但是执行方法的时候要判断实体类里面所有属性才能知道哪个属性不是null。