예제 #1
0
        static void Main(string[] args)
        {
            #region 接口实现多态
            //麻雀会飞,鹦鹉会飞,鸵鸟会飞,企鹅会飞,直升机会飞
            //用多态来实现,方法,抽象类,接口
            //IFlyable fly = new Helicopper();//new YinWu();//new MaQue();
            //fly.Fly();
            #endregion

            #region 接口的修饰符
            MyBase         mb = new MyBase();
            MyDerivedClass dc = new MyDerivedClass();

            mb.DoSomething();
            IMyInterface imb = mb;
            imb.DoSomethingElse();

            Console.WriteLine("-------------------");
            dc.DoSomething();
            dc.DoSomethingElse();

            Console.WriteLine("-------------------");
            //MyDerivedClass dc1 = (MyDerivedClass) mb;//父类不能赋值给子类

            #endregion

            Console.ReadKey();
        }
예제 #2
0
    protected override bool EqualsCore(MyBase other)
    {
        Derived obj = (Derived)other;

        return(base.EqualsCore(obj) &&
               this.DerivedProperty == obj.DerivedProperty);
    }
예제 #3
0
    public void BadSuperCall()
    {
        try
        {
            MyBase a = NSObject.AllocAndInitInstance("MyBase").To <MyBase>();
            a.badAccumulate(0);
            Assert.Fail("badAccumulate should have thrown an exception");
        }
        catch (InvalidCallException i)
        {
            if (!i.Message.Contains("NSSimpleCString"))
            {
                Assert.Fail("Expected 'NSSimpleCString' in '{0}", i.Message);
            }

            if (!i.Message.Contains("badAccumulate"))
            {
                Assert.Fail("Expected 'badAccumulate' in '{0}", i.Message);
            }
        }
        catch (Exception e)
        {
            Assert.Fail("badAccumulate should have thrown an InvalidCallException, not a {0}", e.GetType());
        }
    }
예제 #4
0
        public void Is_ArgumentIsDifferentType_Throws()
        {
            // Arrange
            var arg = new MyBase();

            // Act/Assert
            Assert.Throws <ArgumentException>(() => Guard.That(arg).Is(typeof(int)));
        }
예제 #5
0
        public void Is_ArgumentIsDifferentType_Throws()
        {
            // Arrange
            var arg = new MyBase();

            // Act/Assert
            Assert.Throws<ArgumentException>(() => Guard.That(() => arg).Is(typeof(int)));
        }
    public static void Main()
    {
        var derived = new MyDerived();

        Console.WriteLine("Value = {0}", derived.GetValue());
        MyBase myBase = derived;

        Console.WriteLine("Value = {0}", myBase.GetValue());
    }
예제 #7
0
    public static void Main()
    {
        MyDerived mD = new MyDerived();
        MyBase    mB = (MyBase)mD;

        System.Console.WriteLine(mB.Meth1());
        System.Console.WriteLine(mB.Meth2());
        System.Console.WriteLine(mB.Meth3());
    }
예제 #8
0
 // make a damage on target
 private void TargetHit(GameObject target)
 {
     Debug.Log("TargetHit: " + target.name);
     if (target.name == "Base")
     {
         // make damage on base
         MyBase baseCtr = target.GetComponent <MyBase> ();
         baseCtr.TakeHit(damage);
         StartCoroutine(DestroyCube());
     }
 }
 public static void main()
 {
     MyBase       myBase       = new MyBase();
     string       a            = myBase.ToString();                 // I'm a base class
     MyFixedChild myFixedChild = new MyFixedChild();
     string       b            = myFixedChild.ToString();           // I'm the fixed child class
     string       c            = ((MyBase)myFixedChild).ToString(); // I'm the fixed child class
     MyFlexiChild myFlexiChild = new MyFlexiChild();
     string       d            = myFlexiChild.ToString();           // I'm the flexi child class
     string       e            = ((MyBase)myFlexiChild).ToString(); // I'm a base class
 }
예제 #10
0
        public void Test(object obj)
        {
            MyBase a = obj as MyBase;

            Console.WriteLine(a);

            bool ok = obj is MyBase;

            Console.WriteLine(ok);

            MyBase b = (MyBase)obj;
        }
예제 #11
0
    public void SuperCall4()
    {
        try
        {
            MyBase a = NSObject.AllocAndInitInstance("MyBase").To <MyBase>();

            a.SuperCall(NSObject.Class, "accumulate:", 5);
            Assert.Fail("SuperCall should have thrown an exception");
        }
        catch (InvalidCallException e)
        {
            Assert.AreEqual("Couldn't find a method for NSObject.accumulate:", e.Message);
        }
    }
예제 #12
0
        public override MyBase MapToPersistentObject(MyBase obj)
        {
            if (obj is ClockifyUser user)
            {
                user.ActiveWorkspace  = ActiveWorkspace;
                user.DefaultWorkspace = DefaultWorkspace;
                user.Email            = Email;
                user.Id     = Id;
                user.Name   = Name;
                user.Status = Status;
            }

            return(obj);
        }
예제 #13
0
            public static void OverideDemo()
            {
                MyDerived mD = new MyDerived();
                MyBase    mB = (MyBase)mD;

                //overide重写后转回 还是重写后的继承方法。
                System.Console.WriteLine(mB.Meth1());

                // 使用 new 关键字显式隐藏
                System.Console.WriteLine(mB.Meth2());

                // 该方法隐藏了继承的成员 MyBase.Meth3():
                System.Console.WriteLine(mB.Meth3());
            }
예제 #14
0
    public void SuperCall1()
    {
        try
        {
            MyBase a = NSObject.AllocAndInitInstance("MyBase").To <MyBase>();

            int result = a.accumulate(0);
            Assert.AreEqual(2, result);
        }
        catch (Exception e)
        {
            Console.WriteLine("SuperCall1 failed:");
            Console.WriteLine("{0}", e);
        }
    }
예제 #15
0
 public virtual void SourcesAreProperForm(SteadyStateEvolutionState state)
 {
     for (var x = 0; x < Sources.Length; x++)
     {
         if (!(Sources[x] is ISteadyStateBSource))
         {
             state.Output.Error("The following breeding source is not of ISteadyStateBSource.",
                                MyBase.Push(P_SOURCE).Push("" + x), DefaultBase.Push(P_SOURCE).Push("" + x));
         }
         else
         {
             ((ISteadyStateBSource)Sources[x]).SourcesAreProperForm(state);
         }
     }
 }
        public override MyBase MapToPersistentObject(MyBase obj)
        {
            if (obj is ClockifyTime time)
            {
                time.Id          = Id;
                time.billable    = billable;
                time.description = description;
                time.duration    = timeInterval.duration;
                time.end         = timeInterval.end;
                time.isLocked    = isLocked;
                time.projectId   = projectId;
                time.start       = timeInterval.start;
                time.tagIds      = tagIds;
                time.taskId      = taskId;
                time.userId      = userId;
                time.workspaceId = workspaceId;
            }

            return(obj);
        }
        static void PolymorphismConcepts()
        {
            MyHelper.PrintHeaderMessage("Base Reference Base Object");
            MyBase obj1 = new MyBase(); obj1.f1(); obj1.f2(); obj1.f3(); obj1.f4(); obj1.f5();

            MyHelper.PrintNoteConcept("In this case, all base function will be called.");

            MyHelper.PrintHeaderMessage("Derived Reference Derived Object");
            MyDerived obj2 = new MyDerived(); obj2.f1(); obj2.f2(); obj2.f3(); obj2.f4(); obj2.f5();

            MyHelper.PrintNoteConcept("In this case, all derived function will be called.");

            MyHelper.PrintHeaderMessage("Base Reference Derived Object");
            MyBase obj3 = new MyDerived(); obj3.f1(); obj3.f2(); obj3.f3(); obj3.f4(); obj3.f5();

            MyHelper.PrintNoteConcept("In this case, Only derived override will be called else all base will be called");

            Console.Out.WriteLine("Derived Reference  Base Object With Type Cast");
            //MyDerived obj4 = (MyDerived)new MyBase(); obj4.f1(); obj4.f2(); obj4.f3(); obj4.f4(); obj4.f5();
            MyHelper.PrintNoteConcept("Run Time Error: Unable to cast Base type to Derived type");

            MyHelper.PrintNoteConcept();
            MyHelper.PrintEndMessage();
        }
예제 #18
0
        public static bool isEqualTo(MyBase obj_1, MyBase obj_2, string indent)
        {
            // handle ALL classes derived from MyBase here
            bool ret = false;

            try
            {
                //MyDebug.DPrint(Global.sprintf("{0}{1,-22}     vs.     {2,22}", indent, Tools.NamedPtr(obj_1), Tools.NamedPtr(obj_2)));
                Type t  = obj_1.GetType();
                Type t2 = obj_2.GetType();
                if (!t.Equals(t2))
                {
                    return(false);
                }
                if (t.Equals(typeof(MyKey)))
                {
                    ret = ((MyKey)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyNode)))
                {
                    ret = ((MyNode)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyTextField)))
                {
                    ret = ((MyTextField)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyStack)))
                {
                    ret = ((MyStack)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyView_Stk)))
                {
                    ret = ((MyView_Stk)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyBase)))
                {
                    ret = ((MyBase)obj_1).isEqualTo(indent, obj_2);
                }
                #if __MyEQE__
                else if (t.Equals(typeof(MyEqLabel)))
                {
                    ret = ((MyEqLabel)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyEqRow)))
                {
                    ret = ((MyEqRow)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MyCell)))
                {
                    ret = ((MyCell)obj_1).isEqualTo(indent, obj_2);
                }
                else if (t.Equals(typeof(MySection)))
                {
                    ret = ((MySection)obj_1).isEqualTo(indent, obj_2);
                }
                #endif //__MyEQE__
                else
                {
                    MyDebug.DoAssert(false, "fixme: shouldn't call this with null arg: " + t.ToString());
                }
            }
            catch (Exception e)
            {
                Global.DumpException(e);
                MyDebug.DoAssert(false, "fixme: shouldn't call this with null arg:  " + obj_1.GetType().ToString());
            }
            return(ret);
        }
예제 #19
0
 public MyDerived(MyBase obj)
 {
     A = obj.A;
 }
 public static void SerializeAnyDescendant(IShapeshifterWriter writer, MyBase item)
 {
     writer.Write("MyKey", item.BaseProperty);
 }
예제 #21
0
 protected static object GetPropertyOfBaseOf(MyBase obj)
 {
     return(obj.PropertyOfBase);
 }
 public static void CopyFromBase(this MyBase target, MyBase source)
 {
     target.DateAdded = source.DateAdded;
 }
예제 #23
0
 protected virtual FooBase Overloaded(MyBase myBase)
 {
     return(null);
 }
예제 #24
0
 public NSObject TakeBase(MyBase s)
 {
     return (NSObject) s.Call("description");
 }
예제 #25
0
 public NSObject TakeBase(MyBase s)
 {
     return((NSObject)s.Call("description"));
 }
예제 #26
0
 public UsersInfoRepos(MyBase context)
 {
     _UsersInfoContext = context;
 }
예제 #27
0
 public MySecond(MyBase prototype)
 {
     this.CopyFromBase(prototype);
 }
예제 #28
0
 private static void PutObject(ref MyBase obj, MyClass inObj)
 {
     obj = inObj;
 }
 public MyClass(MyBase source)
 {
     Mapper.Map(source, this);
 }
예제 #30
0
		public static override void Initialize(String name, NameValueCollection col)
		{
			MyBase.Initialize(Me.ApplicationName, col);
		} // End Sub
 public virtual MyBase MapToPersistentObject(MyBase obj) => throw new NotImplementedException();
 public void MyMethod(MyBase parameter)
 {
     object p = parameter.PropertyOfBase;
 }
 public new static string GetData()
 {
     return(MyBase.GetData() + MySpecialData);
 }