static void Main(string[] args) { Gun mGun = new MachineGun(); Gun sGun = new ShotGun(); Gun mGunWithClip = new GunClip(mGun, 40); Gun mGunWithTwoClips = new GunClip(mGunWithClip, 60); Gun mGunWithEverything = new GunSilencer(mGunWithTwoClips, 0.9f); Console.Write("MachineGun:\n\t"); mGun.Fire(); Console.Write("ShotGun:\n\t"); sGun.Fire(); Console.Write("MachineGun with clip:\n\t"); mGunWithClip.Fire(); Console.Write("MachineGun with two clips:\n\t"); mGunWithTwoClips.Fire(); Console.Write("MachineGun with everything:\n\t"); mGunWithEverything.Fire(); try { new GunSilencer(mGun, 1.2f); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } finally { Console.WriteLine("Thanks for shooting!!"); } }
void FireHandling() { if (Input.GetKey(KeyCode.Mouse0)) { machinGun.Fire(transform.up); } if (Input.GetKey(KeyCode.Mouse1)) { launcher.Fire(transform.up); } }
/// <summary> /// Shows interception of an class method. /// </summary> private static void ClassInvocation() { Console.WriteLine("ClassInvocation"); //Wraping the class MachineGun machineGun = _engine.WrapClass(typeof(MachineGun)) as MachineGun; //Not intercepted. It isn't a virtual method. machineGun.Fire(5); //Intercepted. machineGun.FireTenTimes(); }