-
Notifications
You must be signed in to change notification settings - Fork 226
How to implement OnPropertyChanged
Simon Hughes edited this page May 16, 2019
·
8 revisions
In EF.Reverse.POCO.Core.ttinclude line 1082, change
from
Entity = string.Format(
"public {0}{1} {2} {{ get; {3}set; }}{4}{5}",
(OverrideModifier ? "override " : ""), WrapIfNullable(PropertyType, this), NameHumanCase, Settings.UsePrivateSetterForComputedColumns && IsComputed ? "private " : string.Empty, initialization, inlineComments
);to
Entity = string.Format(
"public {0}{1} {2} {{ get {{ return {2}; }} {3}set{{{2}=value;OnPropertyChanged(\"{2}\");}} }}{4}{5}",
(OverrideModifier ? "override " : ""), WrapIfNullable(PropertyType, this), NameHumanCase, Settings.UsePrivateSetterForComputedColumns && IsComputed ? "private " : string.Empty, initialization, inlineComments
);Changes to database.tt :
Settings.AdditionalNamespaces = new[] { "System.ComponentModel" };
// Writes optional base classes
Func<Table, string> WritePocoBaseClasses = t =>
{
return ": INotifyPropertyChanged";
};
// Writes any boilerplate stuff inside the POCO class
Action<Table> WritePocoBaseClassBody = t =>
{
WriteLine(" public event PropertyChangedEventHandler PropertyChanged;");
WriteLine(@" protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}");
};- Home
- Compared with the Microsoft scaffolder
- Connection strings
- JetBrains Rider
- Upgrading from v3 to v4
- Saving .tt does nothing
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets