public AuthView() { InitializeComponent(); this.WhenActivated(d => { // Control bindings d(this.Bind(ViewModel, x => x.Username, x => x.Username.Text)); d(this.Bind(ViewModel, x => x.Password, x => x.Password.Password, Password.Events().PasswordChanged)); d(this.BindCommand(ViewModel, x => x.SignIn, x => x.SignIn)); // Change the text of the SignIn control based on state d(this.WhenAnyObservable(x => x.ViewModel.SignIn.IsExecuting) .Subscribe(state => { SignIn.Content = state ? "Signing In..." : "Sign In"; })); // Invoke ViewModel commands when the external "links" are clicked d(NoAccount.Events().MouseLeftButtonUp.InvokeCommand(ViewModel, x => x.Registration)); d(ForgotPass.Events().MouseLeftButtonUp.InvokeCommand(ViewModel, x => x.ResetPassword)); // Attempt to grab the users avatar when the Username control loses focus d(Username.Events().LostFocus.InvokeCommand(ViewModel, x => x.Avatar)); // Received `IBitmap` of the users avatar d(this.WhenAnyObservable(x => x.ViewModel.Avatar) .Subscribe(bitmap => Avatar.Source = bitmap.ToNative())); // Allow 'Enter/Return' to execute authentication d(this.Events().KeyUp .Where(x => x.Key == Key.Enter) .Where(_ => ViewModel.SignIn.CanExecute(null)) .Subscribe(_ => ViewModel.SignIn.Execute(null))); }); }
public static void Main() { Account acc = new Account(100); // Use a class reference Console.WriteLine("balance = {0}", acc.Balance); acc.Deposit(25); Console.WriteLine("balance = {0}", acc.Balance); // Use an interface reference IBasicAccount ifc = (IBasicAccount)acc; ifc.Deposit(25); Console.WriteLine("balance = {0}", ifc.Balance); // Now try same things with class not implementing IBasicAccount NoAccount acc2 = new NoAccount(500); // Use a class reference Console.WriteLine("balance = {0}", acc2.Balance); acc2.Deposit(25); Console.WriteLine("balance = {0}", acc2.Balance); // Try an interface pointer try { IBasicAccount ifc2 = (IBasicAccount)acc2; ifc2.Deposit(25); Console.WriteLine("balance = {0}", ifc2.Balance); } catch (InvalidCastException e) { Console.WriteLine("IBasicAccount is not supported"); Console.WriteLine(e.Message); } }