Groups | Blog | Home
all groups > dotnet clr > january 2005 >

dotnet clr : Can I SET InitOnly(readonly) attribute in FieldInfo ??


Dmitri Sazonov
1/21/2005 6:15:42 AM
Hi
I need to be able to pass const parameters to function.
And I'm using reflection to get class (which I will when
pass as parameter) and I'm using FieldInfo.SetValue to
set that's class fields.
So, best way to acheve constness, will be to set change
FieldAttributes of that field. I need way to SET
System.Reflection.FieldInfo.IsInitOnly Property.

Is it doable? If not, what is an options?

thanks
Yiru Tang via DotNetMonster.com
1/21/2005 9:52:36 PM
No I don't think you have a way to change a field attribute through Reflection. You can only do it when you are emitting the code.

I think in CLR all the parameters will be immutable by default unless they are ref or out types. So you really don't need to worry this.

--
AddThis Social Bookmark Button