- presentationmodeldemo.zip
- App.Configuration.Wpf
- App.Configuration
- App.Core
- App.Data
- libs
- AttachedCommandBehavior.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- Castle.MicroKernel.dll
- Castle.Windsor.dll
- PresentationModelBase
- PresentationModelDemo.sln
- WPFUI
|
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Reflection;
namespace App.Core
{
class EntityViewPropertyDescriptor : PropertyDescriptor
{
private Type _entityType;
private Type _entityViewType;
private PropertyInfo _entityProperty;
private string _entityViewPropertyName;
private FieldInfo _entityField;
MethodInfo _propertyChangeNotification;
static Type GetPropertyType(string propertyName, Type entityType)
{
return entityType.GetProperty(propertyName).PropertyType;
}
static string GetPropertyName(string entityPropertyName, Type entityType)
{
return entityType.Name + entityPropertyName;
}
public EntityViewPropertyDescriptor(string entityPropertyName, Type entityType, Type entityViewType)
: base(
TypeDescriptor.CreateProperty
(entityViewType, GetPropertyName(entityPropertyName, entityType), GetPropertyType(entityPropertyName, entityType), null))
{
_entityType = entityType;
_entityProperty = _entityType.GetProperty(entityPropertyName);
_entityViewPropertyName = entityType.Name + entityPropertyName;
_entityViewType = entityViewType;
_entityField = _entityViewType.GetField("_entity", BindingFlags.NonPublic | BindingFlags.Instance);
_propertyChangeNotification = _entityViewType.GetMethod("OnPropertyChanged", BindingFlags.NonPublic | BindingFlags.Instance);
}
public override bool CanResetValue(object component)
{
return false;
}
public override Type ComponentType
{
get { return _entityViewType; }
}
public override object GetValue(object component)
{
object innerEntity = _entityField.GetValue(component);
return _entityType.GetProperty(_entityProperty.Name).GetValue(innerEntity, null);
}
public override bool IsReadOnly
{
get { return !_entityProperty.CanWrite; }
}
public override Type PropertyType
{
get { return _entityProperty.PropertyType; }
}
public override void ResetValue(object component)
{
throw new NotImplementedException();
}
public override void SetValue(object component, object value)
{
if (_entityProperty.CanWrite)
{
object innerEntity = _entityField.GetValue(component);
_entityProperty.SetValue(innerEntity, value, null);
_propertyChangeNotification.Invoke(component, new object[] { _entityViewPropertyName });
}
}
public override bool ShouldSerializeValue(object component)
{
return false;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.