protected void OnPropertyGet(string property) { if (this.EntityState != System.Data.EntityState.Detached) { instance.OnPropertyGet(property); } }
protected TValue Get <TValue>(Expression <Func <TValue> > property) { // Get the name of the property being fetched string propertyName = ((MemberExpression)property.Body).Member.Name; // Raise the property get notification instance.OnPropertyGet(propertyName); // Return a value if assigned object value; if (values.TryGetValue(propertyName, out value)) { return((TValue)value); } // Automatically initialize list fields if null when accessed if (typeof(TValue).IsGenericType && typeof(TValue).GetGenericTypeDefinition() == typeof(ICollection <>)) { value = Activator.CreateInstance(typeof(ObservableCollection <>).MakeGenericType(typeof(TValue).GetGenericArguments()[0])); values[propertyName] = value; } // Otherwise return null/default return(default(TValue)); }