-
Notifications
You must be signed in to change notification settings - Fork 6
/
NonPersistentObjectBase.cs
45 lines (42 loc) · 1.66 KB
/
NonPersistentObjectBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
namespace NonPersistentObjectsDemo.Module.BusinessObjects {
public abstract class NonPersistentObjectBase : INotifyPropertyChanged, IObjectSpaceLink {
private IObjectSpace objectSpace;
protected IObjectSpace ObjectSpace { get { return objectSpace; } }
IObjectSpace IObjectSpaceLink.ObjectSpace {
get { return objectSpace; }
set {
if(objectSpace != value) {
OnObjectSpaceChanging();
objectSpace = value;
OnObjectSpaceChanged();
}
}
}
protected virtual void OnObjectSpaceChanging() { }
protected virtual void OnObjectSpaceChanged() { }
protected IObjectSpace FindPersistentObjectSpace(Type type) {
return ((NonPersistentObjectSpace)objectSpace).AdditionalObjectSpaces.FirstOrDefault(os => os.IsKnownType(type));
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected void SetPropertyValue<T>(string name, ref T field, T value) {
if(!Equals(field, value)) {
field = value;
OnPropertyChanged(name);
}
}
[Browsable(false)]
public object This { get { return this; } }
}
}