SetRaiseMethod() public method

public SetRaiseMethod ( System mdBuilder ) : void
mdBuilder System
return void
        static MethodBuilder BuildOnPropertyChanged(System.Reflection.Emit.TypeBuilder typeBuilder, EventBuilder eventBuilder, FieldInfo eventBackingField)
        {
            var raisePropertyChanged = typeBuilder.DefineMethod("OnPropertyChanged", MethodAttributes.Private, typeof(void), new[] {typeof(string)});
            var generator = raisePropertyChanged.GetILGenerator();
            var returnLabel = generator.DefineLabel();

            generator.DeclareLocal(typeof(PropertyChangedEventHandler));
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldfld, eventBackingField);
            generator.Emit(OpCodes.Stloc_0);
            generator.Emit(OpCodes.Ldloc_0);
            generator.Emit(OpCodes.Ldnull);
            generator.Emit(OpCodes.Ceq);
            generator.Emit(OpCodes.Brtrue, returnLabel);

            generator.Emit(OpCodes.Ldloc_0);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Newobj, _createEventArgs.Value);
            generator.Emit(OpCodes.Callvirt, Info<ProgressChangedEventHandler>.GetMethod("Invoke").First().MethodInfo);

            generator.MarkLabel(returnLabel);
            generator.Emit(OpCodes.Ret);

            eventBuilder.SetRaiseMethod(raisePropertyChanged);
            return raisePropertyChanged;
        }
	public void TestCreation () {
		eb = tb.DefineEvent ("event2", EventAttributes.SpecialName, typeof (AnEvent));

		eb.SetRaiseMethod (mb);
		eb.SetAddOnMethod (mb);
		eb.SetRemoveOnMethod (mb);
		eb.AddOtherMethod (mb);
		eb.AddOtherMethod (mb);

		Type t = tb.CreateType ();

		MethodInfo mi = t.GetMethod ("OnAnEvent");

		EventInfo[] events = t.GetEvents ();
		AssertEquals (2, events.Length);

		{
			EventInfo ev = t.GetEvent ("event1");
			AssertEquals ("event1", ev.Name);
			AssertEquals (EventAttributes.None, ev.Attributes);
			AssertEquals (t, ev.DeclaringType);

			AssertEquals (typeof (AnEvent), ev.EventHandlerType);
			AssertEquals (true, ev.IsMulticast);
			AssertEquals (false, ev.IsSpecialName);

			AssertEquals (mi, ev.GetAddMethod ());
			AssertEquals (null, ev.GetRaiseMethod ());
			AssertEquals (mi, ev.GetRemoveMethod ());
		}

		{
			EventInfo ev = t.GetEvent ("event2");
			AssertEquals ("event2", ev.Name);
			AssertEquals (EventAttributes.SpecialName, ev.Attributes);
			AssertEquals (t, ev.DeclaringType);

			AssertEquals (typeof (AnEvent), ev.EventHandlerType);
			AssertEquals (true, ev.IsMulticast);
			AssertEquals (true, ev.IsSpecialName);

			AssertEquals (mi, ev.GetAddMethod ());
			AssertEquals (mi, ev.GetRaiseMethod ());
			AssertEquals (mi, ev.GetRemoveMethod ());
		}
	}