Wednesday, February 06, 2008 3:44 PM
I've googled, windowslivesearched, Yahoosearched etc on Generic property indexer and I found nothing.
I did try many things with no success to date.
I would need a GENERIC PROPERTY INDEXER. I explain :
I got a class with an indexer like this
RETURN THE DATA TYPE of the value WITH the value of course
so instead of CASTING the returned OBJET as this indexer is object, I would just use generic so it really gives me the real DATA TYPE with its value ???
Save the value to the table...
I thought that would work but it doesn't
public this<T>[object ColumnName]
So I would just do this
DateTime dtDate = MyClass.Field<DateTime>["TheColumnI'mlookingFor"];
DateTime dtDate = (DateTime)MyClass.Field["TheColumnI'mlookingFor"];
Thank you for any help on this.
Thursday, February 07, 2008 12:08 AM
A workaround is to declare a method (cannot use the "this" accessor) like the following.
public T GetValue<T>(object ColumnName)
return (T) yourValue;
You could call itas follows:
DateTime dtDate = MyClass.GetValue<DateTime>("TheColumnI'mLookingFor")
So, you were on the right track, you just can't use generics this way with the "this" keyword.