Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace VfTable {
- class Program {
- static void JIT() {
- Derived2Class derived2Class = new Derived2Class(0xDEAD);
- DoForDerivedClass2(derived2Class);
- DoForInterface(derived2Class);
- DoForDerivedClass(derived2Class);
- DoForBaseClass(derived2Class);
- }
- static void Main() {
- JIT();
- Console.Clear();
- Console.WriteLine("For breakpoint");
- Console.ReadLine();
- Derived2Class derived2Class = new Derived2Class(0xDEAD);
- DoForDerivedClass2(derived2Class);
- DoForInterface(derived2Class);
- DoForDerivedClass(derived2Class);
- DoForBaseClass(derived2Class);
- }
- static void DoForDerivedClass2(Derived2Class derived2Class) {
- derived2Class.InterfaceMethod();
- derived2Class.InterfaceProperty = 0xBEEF;
- Console.WriteLine(derived2Class.InterfaceProperty);
- derived2Class.baseField1 = 64;
- }
- static void DoForBaseClass(BaseClass baseClass) {
- baseClass.BaseProperty1 = 0xBEEF;
- baseClass.BaseProperty2 = 0xBEEF;
- Console.WriteLine(baseClass.BaseProperty1);
- Console.WriteLine(baseClass.BaseProperty2);
- baseClass.VirtualMethod();
- baseClass.NormalMethod();
- BaseClass.StaticMethod();
- baseClass.baseField1 = 64;
- }
- static void DoForDerivedClass(DerivedClass derivedClass) {
- derivedClass.DerivedProperty1 = 0xBEEF;
- derivedClass.BaseProperty1 = 0xBEEF;
- derivedClass.BaseProperty2 = 0xBEEF;
- Console.WriteLine(derivedClass.DerivedProperty1);
- Console.WriteLine(derivedClass.BaseProperty1);
- Console.WriteLine(derivedClass.BaseProperty2);
- derivedClass.VirtualMethod();
- derivedClass.NormalMethod();
- derivedClass.derivedField1 = 64;
- }
- static void DoForInterface(IInterface iInterface) {
- iInterface.InterfaceMethod();
- Console.WriteLine(iInterface.InterfaceProperty);
- }
- }
- public class BaseClass {
- public int baseField1;
- int baseField2;
- int backingFieldForBaseProperty2;
- protected readonly int baseProtectedField;
- public int BaseProperty1 { get; set; }
- public int BaseProperty2 {
- get {
- Console.WriteLine("BaseProperty2 get");
- return backingFieldForBaseProperty2;
- }
- set {
- Console.WriteLine("BaseProperty2 set");
- backingFieldForBaseProperty2 = value;
- }
- }
- protected int BaseProtectedProperty { get; set; }
- public BaseClass(int param) {
- baseField1 = param;
- baseField2 = param;
- BaseProperty1 = param;
- BaseProperty2 = param;
- BaseProtectedProperty = param;
- baseProtectedField = param;
- }
- public static void StaticMethod() {
- Console.WriteLine("Static method");
- }
- public void NormalMethod() {
- Console.WriteLine("Normal method");
- if (baseProtectedField == 100)
- throw new Exception();
- if(baseField1 == 100)
- throw new Exception();
- if(baseField2 == 100)
- throw new Exception();
- }
- public virtual void VirtualMethod() {
- Console.WriteLine("Base virtual method");
- }
- }
- public class DerivedClass : BaseClass {
- internal int derivedField1;
- public int DerivedProperty1 { get; set; }
- public DerivedClass(int param) : base(param) {
- derivedField1 = param;
- DerivedProperty1 = param;
- BaseProtectedProperty = param;
- }
- public override void VirtualMethod() {
- base.VirtualMethod();
- Console.WriteLine("Derived virtual method");
- if(baseProtectedField == 100)
- throw new Exception();
- if(derivedField1 == 100)
- throw new Exception();
- if (BaseProtectedProperty == 100)
- throw new Exception();
- }
- }
- public interface IInterface {
- int InterfaceProperty { get; }
- void InterfaceMethod();
- }
- public class Derived2Class : DerivedClass, IInterface {
- int derived2Field1;
- public Derived2Class(int param) : base(param) {
- derived2Field1 = param;
- InterfaceProperty = param;
- }
- public int InterfaceProperty { get; set; }
- public void InterfaceMethod() {
- Console.WriteLine("Interface Method");
- if (derived2Field1 == 100)
- throw new Exception();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement