public static void DelegateCastTest3() { Cast_Func2 afunc = (x) => { return(null); }; object obj = afunc; var action6 = (Action <DelegateCast <CastSubObj>, CastSubObj>)obj; if (action6 != null)//TODO:cast后应为空 { throw new Exception(); } }
public static void DelegateCastTest2() { Cast_Func2 afunc = (x) => { return(null); }; object obj = afunc; Func <DelegateCast <CastSubObj>, CastSubObj> action2 = obj as Func <DelegateCast <CastSubObj>, CastSubObj>; Action <DelegateCast <CastSubObj>, CastSubObj> action3 = obj as Action <DelegateCast <CastSubObj>, CastSubObj>; Action action4 = obj as Action; var action5 = obj as Action <DelegateCast <CastSubObj>, CastSubObj>; var action7 = obj as Func <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(); } if (action7 == null) { throw new Exception(); } }