Open Collective
Open Collective
Loading
Catel.Fody now weaves ObservableObject models
Published on December 21, 2018 by Geert van Horrik

Today we have released a beta of Catel.Fody (3.7.0). This version will introduce support for weaving of automatic properties of the ObservableObject in Catel (it alread supports ModelBase and ViewModelBase).

Automatic weaving of properties

Tired of writing all the dreadful RaisePropertyChange calls in your ObservableObject models? Catel will now weave everything for you.

public class Person : ObservableObject

{

public string FirstName { get; set; }

public string LastName { get; set; }

}

will be weaved into:

public class Person : ObservableObject

{

private string _firstName;

private string _lastName;

public string FirstName

{

get { return _firstName; }

set

{

_firstName = value;

RaisePropertyChanged(nameof(FirstName));

}

}

public string LastName

{

get { return _lastName; }

set

{

_lastName = value;

RaisePropertyChanged(nameof(LastName));

}

}

}

Automatic weaving of custom change notifications

Want to implement your own custom (local) change notifications? Just like you can do with ModelBase, define a method named On[PropertyName]Changed and it will automatically be invoked.

public class Person : ObservableObject

{

public string FirstName { get; set; }

private void OnFirstNameChanged()

{

// Your code here!

}

}

will be weaved into:

public class Person : ObservableObject

{

private string _firstName;

public string FirstName

{

get { return _firstName; }

set

{

_firstName = value;

OnFirstNameChanged();

RaisePropertyChanged(nameof(FirstName));

}

}

private void OnFirstNameChanged()

{

// Your code here!

}

}

Ignoring weaving of models or properties

To ignore weaving of a whole model deriving from ObservableObject, use this code:

[NoWeaving]

public class Person : ObservableObject

{

// … left out for readability

}

To ignore weaving of a specific property, use this code:

public class Person : ObservableObject

{

[NoWeaving]

public string FirstName { get; set; }

}

Try the beta now!

Please try the new beta and let us know if you hit any issues!