Resolve property at runtime. C#

Posted by user1031381 on Stack Overflow See other posts from Stack Overflow or by user1031381
Published on 2012-10-09T15:19:24Z Indexed on 2012/10/09 15:37 UTC
Read the original article Hit count: 136

Filed under:
|
|

I have some class which have some code

public IEnumerable<TypeOne> TypeOne
    {
        get
        {
            if (db != null)
            {
                var col = db.Select<TypeOne>();
                if (col.Count > 0) return col;
            }
            return db2.TypeOne;
        }
    }
    public IEnumerable<TypeTwo> TypeTwo
    {
        get
        {
            if (db != null)
            {
                var col = db.Select<TypeTwo>();
                if (col.Count > 0) return col;
            }
            return db2.TypeTwo;
        }
    }

So as You can see there is a lot of duplicated Code and there are same property name and item type of enumerable. I want to call some property of object like "obj.MyProp". And MyProp must be resolved at runtime with some generic or non-generic method. Is it possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dynamic