Programmatically create properties - Out of a database table

Posted by Kosta on Stack Overflow See other posts from Stack Overflow or by Kosta
Published on 2010-03-09T09:34:53Z Indexed on 2010/03/09 9:36 UTC
Read the original article Hit count: 211

Filed under:
|

I already googled around to find a solution for my need, with no success.

Let's say I've a table that looks like this:

ID |KeyId |Name |Description
1 |153 |Currency |XXXXXXXX
2 |68 |Signature |YYYYYYYY
3 |983 |Contact |ZZZZZZZZ .

Now I want to access theses values not by a collection, because I cannot remember all the values, let's say for the name.

So this is not what I want: Values.Where(v => v.Name == "Currency").Select(v => v.KeyId);

The table content changes rarely but still it is not a nice solution having a struct with all "Names" and getting the KeyId like this.

struct Values
{
    public static int Currency
    {
        get { return GetKeyId("Currency"); }
    }
}

I'm looking for a solution that creates me automatically properties out of this table. So that I can access the KeyId with intellisense. As you have for Resources in ASP.NET. There the class is automatically updated as soon as you add a new entry in the RESX file.

For example: Values.Currency , this gives me back the corresponding KeyId.

Thanks for reply

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET