Skip to content

Instantly share code, notes, and snippets.

View thallippoli's full-sized avatar

Ashwin Sudhir thallippoli

View GitHub Profile
@thallippoli
thallippoli / InitializationWithReflection
Created November 14, 2012 06:49
Initializing private members using reflection
public void Initialize()
{
FieldInfo[] fields = this.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance );
for( int i = 0; i < fields.Length; i++ )
{
if( fields[ i ].Name == "m_baz" )
fields[ i ].SetValue( this, 42 );
}
}