Skip to content

Instantly share code, notes, and snippets.

@andybrackley
Created February 23, 2014 19:42
Show Gist options
  • Save andybrackley/9176249 to your computer and use it in GitHub Desktop.
Save andybrackley/9176249 to your computer and use it in GitHub Desktop.
namespace MvvmCrossTests.Core.FSharp
open System
open Cirrious.MvvmCross.ViewModels
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
// One way of accessing the name of an expression that can be passed to the RaisePropertyChanged is
// to provide a ToString style method
// Unfortunately F# won't let me add an extension method to the Expr<string> as it's a generic type and currently
// this isn't supported.
module test =
let tostring (expr : Expr<string>) =
match expr with
| PropertyGet(a, b, list) -> b.Name
| _ -> ""
// New base class to encapsulate the RaisePropertyChanged from the expression
type MvxViewModelBase1() =
inherit MvxViewModel()
// Unfortunately there is no protected in F#
member self.RaisePropertyChanged(expr : Expr<string>) =
match expr with
| PropertyGet(a, b, list) -> self.RaisePropertyChanged(b.Name)
| _ -> ()
type Class1() =
inherit MvxViewModelBase1()
let mutable url = ""
let mutable other = ""
member self.Url
with get() = url
and set(value) =
url <- value
self.RaisePropertyChanged( <@ self.Url @> |> test.tostring )
member self.Other
with get() = other
and set(value) =
other <- value
self.RaisePropertyChanged( <@ self.Other @> )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment