asp net 3.5unleashed

Page 486

throw new ArgumentOutOfRangeException( "value", value, "value must be > 0"); someField = value; } } public event ThreadStart SomeEvent; private void NoCompilerWarnings() { SomeEvent.ToString(); } }

class App { static void Main() { Type t = typeof(SomeType); BindingFlags bf = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

#if BindAndInvokeTogether

// Construct an instance of the Type. Object[] args = new Object[] { 12 };

// Constructor argume

nts Console.WriteLine("x before constructor called: " + args[0] ); Object obj = t.InvokeMember(null, bf | BindingFlags.CreateInstance, null, null, args); Console.WriteLine("Type: " + obj.GetType().ToString()); Console.WriteLine("x after constructor returns: " + args[0] );

// Read and write to a field. t.InvokeMember("someField", bf | BindingFlags.SetField, null, obj, new Object[] { 5 }); Int32 v = (Int32) t.InvokeMember("someField", bf | BindingFlags.GetField, null, obj, null); Console.WriteLine("someField: " + v);

// Call a method. String s = (String) t.InvokeMember("ToString",


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.