By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

FieldInfo class

P: n/a
Posting on behalf of a colleague (no, really! ;) )...

Hi,

I was wondering if there is any equivalent of FieldInfo.SetValue(Object,
Object) that is strongly typed or uses generics? I have been looking at
the source for FieldInfo to see if I could implement my own generic
version of this method but unfortunately the code seems to be hidden, is
there anyway I can implement my own method if there is no equivalent?

TIA!
May 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
David,

You could easily write a wrapper, like so:

public static SetValue<T>(object obj, FieldInfo fieldInfo, T value)
{
// Set the value.
fieldInfo.SetValue(obj, value);
}

public static T GetValue<T>(object obj, FieldInfo fieldInfo)
{
// Get the value and return.
return (T) fieldInfo.GetValue(obj);
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Gouge" <da**@premiersoftware.co.uk> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Posting on behalf of a colleague (no, really! ;) )...

Hi,

I was wondering if there is any equivalent of FieldInfo.SetValue(Object,
Object) that is strongly typed or uses generics? I have been looking at
the source for FieldInfo to see if I could implement my own generic
version of this method but unfortunately the code seems to be hidden, is
there anyway I can implement my own method if there is no equivalent?

TIA!

May 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.