Exemple #1
0
        public static void DelegateCastTest1()
        {
            Cast_Func3 afunc = new CastSubObj().AddValue;



            object obj = afunc;


            Func <DelegateCast <CastSubObj>, CastSubObj>  action2 = obj as Func <DelegateCast <CastSubObj>, CastSubObj>;
            Func <DelegateCast <CastSubObj>, CastSubObj2> action3 = obj as Func <DelegateCast <CastSubObj>, CastSubObj2>;
            var action4 = obj as Cast_Func2;
            var action5 = obj as Action <DelegateCast <CastSubObj>, CastSubObj2>;


            if (action2 != null)
            {
                throw new Exception();
            }
            if (action3 == null)
            {
                throw new Exception();
            }
            if (action4 == null)
            {
                throw new Exception();
            }
            if (action5 != null)
            {
                throw new Exception();
            }
        }
Exemple #2
0
 public static CastSubObj2 AddValue(this CastSubObj cast, DelegateCast <CastSubObj> arg)
 {
     Console.WriteLine(arg);
     return(new CastSubObj2());
 }