User: cneuwirt
Date: 2009/11/16 05:05 AM

Added:
 /Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/
  DictionaryAdapterInstance.cs, DictionaryAdapterMeta.cs

Modified:
 /Components/DictionaryAdapter/trunk/src/
  Changes.txt
 
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/
  DictionaryAdapterFactoryTestCase.cs, TestDictionaryValidator.cs
 /Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/
  Castle.Components.DictionaryAdapter-vs2008.csproj, 
DictionaryAdapterBase.Create.cs, DictionaryAdapterBase.Edit.cs, 
DictionaryAdapterBase.Notify.cs, DictionaryAdapterBase.Validate.cs, 
DictionaryAdapterBase.cs, DictionaryAdapterFactory.cs, 
DictionaryValidateGroup.cs, IDictionaryAdapter.cs, PropertyDescriptor.cs
 
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/
  DictionaryComponentAttribute.cs, NewGuidAttribute.cs, OnDemandAttribute.cs, 
StringListAttribute.cs

Log:
 - Group meta and instance properties together to avoid conflict with user 
defined properties
 - Standardize edit and non-edit mode so that notifications occur consistently

File Changes:

Directory: 
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/
==================================================================================================

File [modified]: DictionaryComponentAttribute.cs
Delta lines: +2 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/NewGuidAttribute.cs
   2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/NewGuidAttribute.cs
   2009-11-16 12:05:50 UTC (rev 6336)
@@ -30,7 +30,8 @@
                        if (storedValue == null || 
storedValue.Equals(UnassignedGuid))
                        {
                                storedValue = Guid.NewGuid();
-                               property.SetPropertyValue(dictionaryAdapter, 
key, ref storedValue, dictionaryAdapter.Descriptor);
+                               property.SetPropertyValue(dictionaryAdapter, 
key, ref storedValue, 
+                                                                               
  dictionaryAdapter.This.Descriptor);
                        }
 

File [modified]: NewGuidAttribute.cs
Delta lines: +3 -2
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/OnDemandAttribute.cs
  2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/OnDemandAttribute.cs
  2009-11-16 12:05:50 UTC (rev 6336)
@@ -88,7 +88,7 @@
                                                                constructor = 
(from ctor in type.GetConstructors()
                                                                        let 
parms = ctor.GetParameters()
                                                                         where 
parms.Length == 1 && 
-                                                                               
parms[0].ParameterType.IsAssignableFrom(dictionaryAdapter.Type)
+                                                                               
parms[0].ParameterType.IsAssignableFrom(dictionaryAdapter.Meta.Type)
                                                                         select 
ctor).FirstOrDefault();
 
                                                                if (constructor 
!= null) args = new[] { dictionaryAdapter };
@@ -122,7 +122,8 @@
                                                        
initializer.Initialize(dictionaryAdapter, storedValue);
                                                }
 
-                                               
property.SetPropertyValue(dictionaryAdapter, key, ref storedValue, 
dictionaryAdapter.Descriptor);
+                                               
property.SetPropertyValue(dictionaryAdapter, key, ref storedValue, 
+                                                                               
                  dictionaryAdapter.This.Descriptor);
                     }
                                }

File [modified]: OnDemandAttribute.cs
Delta lines: +2 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/StringListAttribute.cs
        2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Attributes/StringListAttribute.cs
        2009-11-16 12:05:50 UTC (rev 6336)
@@ -63,7 +63,8 @@
                                                if (converter != null && 
converter.CanConvertFrom(typeof(string)))
                                                {
                                                        var genericList = 
typeof(StringListWrapper<>).MakeGenericType(new[] {paramType});
-                                                       return 
Activator.CreateInstance(genericList, key, storedValue, separator, 
dictionaryAdapter.Dictionary);
+                                                       return 
Activator.CreateInstance(genericList, key, storedValue, separator, 
+                                                                               
                                        dictionaryAdapter.This.Dictionary);
                                                }
                                        }

File [modified]: StringListAttribute.cs
Delta lines: +2 -0
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj
        2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj
        2009-11-16 12:05:50 UTC (rev 6336)
@@ -78,6 +78,8 @@
     <Compile Include="Attributes\DictionaryComponentAttribute.cs" />
     <Compile Include="Attributes\StringValuesAttribute.cs" />
     <Compile Include="CascadingDictionaryAdapter.cs" />
+    <Compile Include="DictionaryAdapterInstance.cs" />
+    <Compile Include="DictionaryAdapterMeta.cs" />
     <Compile Include="DictionaryDescriptor.cs" />
     <Compile Include="DictionaryValidateGroup.cs" />

Directory: 
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/
=======================================================================================

File [modified]: Castle.Components.DictionaryAdapter-vs2008.csproj
Delta lines: +1 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Create.cs
  2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Create.cs
  2009-11-16 12:05:50 UTC (rev 6336)
@@ -38,7 +38,7 @@
                public object Create(Type type, IDictionary dictionary)
                {
                        dictionary = dictionary ?? new HybridDictionary();
-                       return Factory.GetAdapter(type, dictionary, Descriptor);
+                       return This.Factory.GetAdapter(type, dictionary, 
This.Descriptor);
                }
 

File [modified]: DictionaryAdapterBase.Create.cs
Delta lines: +60 -28
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs
    2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs
    2009-11-16 12:05:50 UTC (rev 6336)
@@ -22,18 +22,29 @@
        public abstract partial class DictionaryAdapterBase
        {
                private int suppressEditingCount = 0;
-               private Stack<Dictionary<string, object>> updates;
+               private Stack<Dictionary<string, Edit>> updates;
                private HashSet<IEditableObject> editDependencies;
 
+               struct Edit
+               {
+                       public Edit(PropertyDescriptor property, object 
propertyValue)
+                       {
+                               Property = property;
+                               PropertyValue = propertyValue;
+                       }
+                       public readonly PropertyDescriptor Property;
+                       public object PropertyValue;
+               }
+
                public bool CanEdit
                {
                        get { return suppressEditingCount == 0 && updates != 
null; }
-                       set { updates = value ? new Stack<Dictionary<string, 
object>>() : null; }
+                       set { updates = value ? new Stack<Dictionary<string, 
Edit>>() : null; }
                }
 
                public bool IsEditing
                {
-                       get { return updates != null && updates.Count > 0; }
+                       get { return CanEdit && updates != null && 
updates.Count > 0; }
                }
 
                public bool SupportsMultiLevelEdit { get; set; }
@@ -45,7 +56,7 @@
                                if (IsEditing && updates.Any(level => 
level.Count > 0))
                                        return true;
 
-                               return Properties.Values
+                               return Meta.Properties.Values
                                        .Where(prop => 
typeof(IChangeTracking).IsAssignableFrom(prop.PropertyType))
                                        .Select(prop => 
GetProperty(prop.PropertyName))
                                        .Cast<IChangeTracking>().Any(track => 
track.IsChanged);
@@ -56,7 +67,7 @@
                {
                        if (CanEdit && (!IsEditing || SupportsMultiLevelEdit))
                        {
-                               updates.Push(new Dictionary<string, object>());
+                               updates.Push(new Dictionary<string, Edit>());
                        }
                }
 
@@ -73,9 +84,36 @@
                                        editDependencies.Clear();
                                }
 
-                               updates.Pop();
+                               using (SuppressEditingBlock())
+                               {
+                                       using (TrackReadonlyPropertyChanges())
+                                       {
+                                               var top = updates.Peek();
 
-                               Invalidate();
+                                               if (top.Count > 0)
+                                               {
+                                                       foreach (var update in 
top.Values)
+                                                       {
+                                                               var existing = 
update;
+                                                               
existing.PropertyValue = GetProperty(existing.Property.PropertyName);
+                                                       }
+
+                                                       updates.Pop();
+
+                                                       foreach (var update in 
top.Values.ToArray())
+                                                       {
+                                                               var oldValue = 
update.PropertyValue;
+                                                               var newValue = 
GetProperty(update.Property.PropertyName);
+                                                               
+                                                               if 
(!Object.Equals(oldValue, newValue))
+                                                               {
+                                                                       
NotifyPropertyChanging(update.Property, oldValue, newValue);
+                                                                       
NotifyPropertyChanged(update.Property, oldValue, newValue);
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
                        }
                }
 
@@ -87,26 +125,19 @@
                 {
                                        var top = updates.Pop();
 
-                                       if (top.Count > 0)
+                                       if (top.Count > 0) foreach (var update 
in top.ToArray())
                                        {
-                                               using 
(TrackReadonlyPropertyChanges())
-                                               {
-                                                       foreach (var update in 
top.ToArray())
-                                                       {
-                                                               object value = 
update.Value;
-                                                               
SetProperty(update.Key, ref value);
-                                                       }
-                                               }
+                                               StoreProperty(null, update.Key, 
update.Value.PropertyValue);
                                        }
-
-                                       if (editDependencies != null)
+                               }
+                               
+                               if (editDependencies != null)
+                               {
+                                       foreach (var editDependency in 
editDependencies.ToArray())
                                        {
-                                               foreach (var editDependency in 
editDependencies.ToArray())
-                                               {
-                                                       
editDependency.EndEdit();
-                                               }
-                                               editDependencies.Clear();
+                                               editDependency.EndEdit();
                                        }
+                                       editDependencies.Clear();
                                }
                        }
                }
@@ -138,10 +169,12 @@
 
                protected bool GetEditedProperty(string propertyName, out 
object propertyValue)
                {
-                       if (IsEditing) foreach (var level in updates.ToArray())
+                       if (updates != null) foreach (var level in 
updates.ToArray())
                        {
-                               if (level.TryGetValue(propertyName, out 
propertyValue))
+                               Edit edit;
+                               if (level.TryGetValue(propertyName, out edit))
                                {
+                                       propertyValue = edit.PropertyValue;
                                        return true;
                                }
                        }
@@ -149,12 +182,11 @@
                        return false;
                }
 
-               protected bool EditProperty(string propertyName, object 
propertyValue)
+               protected bool EditProperty(PropertyDescriptor property, string 
key, object propertyValue)
                {
                        if (IsEditing)
                        {
-                               updates.Peek()[propertyName] = propertyValue;
-                               Invalidate();
+                               updates.Peek()[key] = new Edit(property, 
propertyValue);
                                return true;
                        }

File [modified]: DictionaryAdapterBase.Edit.cs
Delta lines: +1 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs
  2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs
  2009-11-16 12:05:50 UTC (rev 6336)
@@ -249,7 +249,7 @@
                        public TrackPropertyChangeScope(DictionaryAdapterBase 
adapter)
                        {
                                this.adapter = adapter;
-                               readonlyProperties = 
adapter.Properties.Values.Where(
+                               readonlyProperties = 
adapter.Meta.Properties.Values.Where(
                                        pd => !pd.Property.CanWrite || 
pd.IsDynamicProperty)
                                        .ToDictionary(pd => pd, pd => 
GetEffectivePropertyValue(pd));

File [modified]: DictionaryAdapterBase.Notify.cs
Delta lines: +1 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Validate.cs
        2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Validate.cs
        2009-11-16 12:05:50 UTC (rev 6336)
@@ -56,7 +56,7 @@
                                if (CanValidate && validators != null)
                                {
                                        PropertyDescriptor property;
-                                       if (Properties.TryGetValue(columnName, 
out property))
+                                       if 
(Meta.Properties.TryGetValue(columnName, out property))
                                        {
                                                return 
string.Join(Environment.NewLine, validators.Select(

File [modified]: DictionaryAdapterBase.Validate.cs
Delta lines: +33 -56
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.cs
 2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.cs
 2009-11-16 12:05:50 UTC (rev 6336)
@@ -14,68 +14,32 @@
 
 namespace Castle.Components.DictionaryAdapter
 {
-       using System;
-       using System.Collections;
-       using System.Collections.Generic;
-       using System.Collections.Specialized;
        using System.ComponentModel;
        using System.Linq;
 
        public abstract partial class DictionaryAdapterBase : IDictionaryAdapter
        {
-               private HybridDictionary state;
-
-               public DictionaryAdapterBase(Type type, 
IDictionaryAdapterFactory factory,
-                                                                        
IDictionary dictionary, PropertyDescriptor descriptor)
+               public DictionaryAdapterBase(DictionaryAdapterInstance instance)
                {
-                       Type = type;
-                       Factory = factory;
-                       Dictionary = dictionary;
-                       Descriptor = descriptor;
+                       This = instance;
 
-                       CanEdit = 
typeof(IEditableObject).IsAssignableFrom(type);
-                       CanNotify = 
typeof(INotifyPropertyChanged).IsAssignableFrom(type);
-                       CanValidate = 
typeof(IDataErrorInfo).IsAssignableFrom(type);
+                       CanEdit = 
typeof(IEditableObject).IsAssignableFrom(Meta.Type);
+                       CanNotify = 
typeof(INotifyPropertyChanged).IsAssignableFrom(Meta.Type);
+                       CanValidate = 
typeof(IDataErrorInfo).IsAssignableFrom(Meta.Type);
 
                        Initialize();
                }
 
-               public Type Type { get; private set; }
+               public abstract DictionaryAdapterMeta Meta { get; }
 
-               public IDictionary State
-               {
-                       get
-                       {
-                               if (state == null)
-                                       state = new HybridDictionary();
-                               return state;
-                       }
-               }
+               public DictionaryAdapterInstance This { get; private set; }
 
-               public IDictionary Dictionary { get; private set;  }
-
-               public PropertyDescriptor Descriptor { get; private set; }
-
-               public IDictionaryAdapterFactory Factory { get; private set; }
-
-               public abstract object[] Behaviors { get; }
-
-               public abstract IDictionaryInitializer[] Initializers { get; }
-
-               public abstract IDictionary<string, PropertyDescriptor> 
Properties { get; }
-
                public virtual object GetProperty(string propertyName)
                {
                        PropertyDescriptor descriptor;
-                       if (Properties.TryGetValue(propertyName, out 
descriptor))
+                       if (Meta.Properties.TryGetValue(propertyName, out 
descriptor))
                        {
-                               object propertyValue;
-                               if (GetEditedProperty(propertyName, out 
propertyValue))
-                               {
-                                       return propertyValue;
-                               }
-
-                               propertyValue = 
descriptor.GetPropertyValue(this, propertyName, null, Descriptor);
+                               var propertyValue = 
descriptor.GetPropertyValue(this, propertyName, null, This.Descriptor);
                                if (propertyValue is IEditableObject)
                                {
                                        
AddEditDependency((IEditableObject)propertyValue);
@@ -87,6 +51,16 @@
                        return null;
                }
 
+               public object ReadProperty(PropertyDescriptor property, string 
key)
+               {
+                       object propertyValue = null;
+                       if (!GetEditedProperty(key, out propertyValue))
+                       {
+                               propertyValue = This.Dictionary[key];
+                       }
+                       return propertyValue;
+               }
+        
                public T GetPropertyOfType<T>(string propertyName)
                {
                        return (T)GetProperty(propertyName);
@@ -97,16 +71,11 @@
                        bool stored = false;
 
                        PropertyDescriptor descriptor;
-                       if (Properties.TryGetValue(propertyName, out 
descriptor))
+                       if (Meta.Properties.TryGetValue(propertyName, out 
descriptor))
                        {
-                               if (EditProperty(propertyName, value))
-                               {
-                                       return true;
-                               }
-
                                if (!ShouldNotify)
                                {
-                                       stored = 
descriptor.SetPropertyValue(this, propertyName, ref value, Descriptor);
+                                       stored = 
descriptor.SetPropertyValue(this, propertyName, ref value, This.Descriptor);
                                        Invalidate();
                                        return stored;
                                }
@@ -119,7 +88,7 @@
 
                                var trackPropertyChange = 
TrackPropertyChange(descriptor, existingValue, value);
 
-                               stored = descriptor.SetPropertyValue(this, 
propertyName, ref value, Descriptor);
+                               stored = descriptor.SetPropertyValue(this, 
propertyName, ref value, This.Descriptor);
 
                                if (stored && trackPropertyChange != null)
                                {
@@ -130,14 +99,22 @@
                        return stored;
                }
 
+               public void StoreProperty(PropertyDescriptor property, string 
key, object value)
+               {
+                       if (property == null || !EditProperty(property, key, 
value))
+                       {
+                               This.Dictionary[key] = value;
+                       }
+               }
+        
                protected void Initialize()
                {
-                       foreach (var initializer in Initializers)
+                       foreach (var initializer in Meta.Initializers)
                        {
-                               initializer.Initialize(this, Behaviors);
+                               initializer.Initialize(this, Meta.Behaviors);
                        }
 
-                       foreach (var property in Properties.Values.Where(p => 
p.Fetch))
+                       foreach (var property in Meta.Properties.Values.Where(p 
=> p.Fetch))
                        {
                                GetProperty(property.PropertyName);

File [modified]: DictionaryAdapterBase.cs
Delta lines: +34 -59
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterFactory.cs
      2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterFactory.cs
      2009-11-16 12:05:50 UTC (rev 6336)
@@ -165,12 +165,10 @@
                        return typeBuilder;
                }
 
-               private static Assembly CreateAdapterAssembly(Type type, 
TypeBuilder typeBuilder, PropertyDescriptor descriptor)
+               private Assembly CreateAdapterAssembly(Type type, TypeBuilder 
typeBuilder, PropertyDescriptor descriptor)
                {
                        var binding = FieldAttributes.Private | 
FieldAttributes.Static;
-                       var behaviorsField = 
typeBuilder.DefineField("behaviors", typeof(object[]), binding);
-                       var initializersField = 
typeBuilder.DefineField("initializers", typeof(IDictionaryInitializer[]), 
binding);
-                       var propertyMapField = 
typeBuilder.DefineField("propertyMap", typeof(Dictionary<String, 
PropertyDescriptor>), binding);
+                       var metaField = typeBuilder.DefineField("__meta", 
typeof(DictionaryAdapterMeta), binding);
 
                        CreateAdapterConstructor(type, typeBuilder);
 
@@ -178,21 +176,19 @@
                        IDictionaryInitializer[] initializers;
                        var propertyMap = GetPropertyDescriptors(type, 
descriptor, out initializers, out behaviors);
 
-                       CreateDictionaryAdapterMetaProperty(typeBuilder, 
MetaBehaviorsProp, behaviorsField);
-                       CreateDictionaryAdapterMetaProperty(typeBuilder, 
MetaInitializersProp, initializersField);
-                       CreateDictionaryAdapterMetaProperty(typeBuilder, 
MetaPropertiesProp, propertyMapField);
+                       CreateMetaProperty(typeBuilder, AdapterGetMeta, 
metaField);
 
                        foreach (var property in propertyMap)
                        {
-                               CreateAdapterProperty(typeBuilder, 
propertyMapField, property.Value);
+                               CreateAdapterProperty(typeBuilder, 
property.Value);
                        }
 
                        var adapterType = typeBuilder.CreateType();
                        var metaBindings = BindingFlags.NonPublic | 
BindingFlags.Static | BindingFlags.SetField;
-                       adapterType.InvokeMember("behaviors", metaBindings, 
null, null, new[] { behaviors });
-                       adapterType.InvokeMember("initializers", metaBindings, 
null, null, new[] { initializers });
-                       adapterType.InvokeMember("propertyMap", metaBindings, 
null, null, new[] { propertyMap });
 
+                       var meta = new DictionaryAdapterMeta(type, 
initializers, behaviors, propertyMap);
+                       adapterType.InvokeMember("__meta", metaBindings, null, 
null, new[] { meta });
+
                        return typeBuilder.Assembly;
                }
 
@@ -203,16 +199,10 @@
                private static void CreateAdapterConstructor(Type type, 
TypeBuilder typeBuilder)
                {
                        var constructorBuilder = typeBuilder.DefineConstructor(
-                               MethodAttributes.Public | 
MethodAttributes.HideBySig, CallingConventions.Standard,
-                               new [] { typeof(Type), 
typeof(DictionaryAdapterFactory), 
-                                                typeof(IDictionary), 
typeof(PropertyDescriptor) 
-                               });
+                               MethodAttributes.Public | 
MethodAttributes.HideBySig, CallingConventions.Standard, 
+                               new [] { typeof(DictionaryAdapterInstance) }
+                               );
 
-                       constructorBuilder.DefineParameter(1, 
ParameterAttributes.None, "type");
-                       constructorBuilder.DefineParameter(2, 
ParameterAttributes.None, "factory");
-                       constructorBuilder.DefineParameter(3, 
ParameterAttributes.None, "dictionary");
-                       constructorBuilder.DefineParameter(4, 
ParameterAttributes.None, "descriptor");
-
                        var ilGenerator = constructorBuilder.GetILGenerator();
 
                        var baseType = typeof(DictionaryAdapterBase);
@@ -220,11 +210,7 @@
 
                        ilGenerator.Emit(OpCodes.Ldarg_0);
                        ilGenerator.Emit(OpCodes.Ldarg_1);
-                       ilGenerator.Emit(OpCodes.Ldarg_2);
-                       ilGenerator.Emit(OpCodes.Ldarg_3);
-                       ilGenerator.Emit(OpCodes.Ldarg_S, 4);
                        ilGenerator.Emit(OpCodes.Call, baseConstructorInfo);
-
                        ilGenerator.Emit(OpCodes.Ret);
                }
 
@@ -232,37 +218,35 @@
 
                #region CreateDictionaryAdapterMeta
 
-               private static void 
CreateDictionaryAdapterMetaProperty(TypeBuilder typeBuilder, PropertyInfo 
metaProp, 
-                                                                               
                                                FieldInfo metaField)
+               private static void CreateMetaProperty(TypeBuilder typeBuilder, 
PropertyInfo prop, FieldInfo field)
                {
                        var propAttribs = MethodAttributes.Public    | 
MethodAttributes.SpecialName |
                                                          
MethodAttributes.HideBySig | MethodAttributes.ReuseSlot |
                                                          
MethodAttributes.Virtual   | MethodAttributes.Final;
 
-                       var getMethodBuilder = typeBuilder.DefineMethod("get_" 
+ metaProp.Name,
-                                                                               
                                    propAttribs, metaProp.PropertyType, null);
+                       var getMethodBuilder = typeBuilder.DefineMethod("get_" 
+ prop.Name,
+                                                                               
                                    propAttribs, prop.PropertyType, null);
 
                        var getILGenerator = getMethodBuilder.GetILGenerator();
-                       if (metaField.IsStatic)
+                       if (field.IsStatic)
                        {
-                               getILGenerator.Emit(OpCodes.Ldsfld, metaField);
+                               getILGenerator.Emit(OpCodes.Ldsfld, field);
                        }
                        else
                        {
                                getILGenerator.Emit(OpCodes.Ldarg_0);
-                               getILGenerator.Emit(OpCodes.Ldfld, metaField);
+                               getILGenerator.Emit(OpCodes.Ldfld, field);
                        }
                        getILGenerator.Emit(OpCodes.Ret);
 
-                       typeBuilder.DefineMethodOverride(getMethodBuilder, 
metaProp.GetGetMethod());
+                       typeBuilder.DefineMethodOverride(getMethodBuilder, 
prop.GetGetMethod());
                }
 
                #endregion
 
                #region CreateAdapterProperty
 
-               private static void CreateAdapterProperty(TypeBuilder 
typeBuilder, FieldInfo propertyMapField, 
-                                                                               
                  PropertyDescriptor descriptor)
+               private static void CreateAdapterProperty(TypeBuilder 
typeBuilder, PropertyDescriptor descriptor)
                {
                        var property = descriptor.Property;
                        var propertyBuilder = 
typeBuilder.DefineProperty(property.Name, property.Attributes, 
property.PropertyType, null);
@@ -272,17 +256,16 @@
 
                        if (property.CanRead)
                        {
-                               CreatePropertyGetMethod(typeBuilder, 
propertyMapField, propertyBuilder, descriptor, propAttribs);
+                               CreatePropertyGetMethod(typeBuilder, 
propertyBuilder, descriptor, propAttribs);
                        }
 
                        if (property.CanWrite)
                        {
-                               CreatePropertySetMethod(typeBuilder, 
propertyMapField, propertyBuilder, descriptor, propAttribs);
+                               CreatePropertySetMethod(typeBuilder, 
propertyBuilder, descriptor, propAttribs);
                        }
                }
 
-               private static void PreparePropertyMethod(
-                       PropertyDescriptor descriptor, FieldInfo 
propertyMapField, ILGenerator propILGenerator)
+               private static void PreparePropertyMethod(PropertyDescriptor 
descriptor, ILGenerator propILGenerator)
                {
                        propILGenerator.DeclareLocal(typeof(String));
                        propILGenerator.DeclareLocal(typeof(object));
@@ -296,8 +279,7 @@
 
                #region CreatePropertyGetMethod
 
-               private static void CreatePropertyGetMethod(
-                       TypeBuilder typeBuilder, FieldInfo propertyMapField, 
PropertyBuilder propertyBuilder, 
+               private static void CreatePropertyGetMethod(TypeBuilder 
typeBuilder, PropertyBuilder propertyBuilder, 
                        PropertyDescriptor descriptor, MethodAttributes 
propAttribs)
                {
                        var getMethodBuilder = typeBuilder.DefineMethod(
@@ -309,14 +291,14 @@
                        var storeResult = getILGenerator.DefineLabel();
                        var loadResult = getILGenerator.DefineLabel();
 
-                       PreparePropertyMethod(descriptor, propertyMapField, 
getILGenerator);
+                       PreparePropertyMethod(descriptor, getILGenerator);
 
                        var result = 
getILGenerator.DeclareLocal(descriptor.PropertyType);
 
                        // value = GetProperty(key, value)
                        getILGenerator.Emit(OpCodes.Ldarg_0);
                        getILGenerator.Emit(OpCodes.Ldloc_0);
-                       getILGenerator.Emit(OpCodes.Callvirt, MetaGetProperty);
+                       getILGenerator.Emit(OpCodes.Callvirt, 
AdapterGetProperty);
                        getILGenerator.Emit(OpCodes.Stloc_1);
 
                        // if (value == null) return null
@@ -348,15 +330,14 @@
 
                #region CreatePropertySetMethod
 
-               private static void CreatePropertySetMethod(
-                       TypeBuilder typeBuilder, FieldInfo propertyMapField, 
PropertyBuilder propertyBuilder,
+               private static void CreatePropertySetMethod(TypeBuilder 
typeBuilder, PropertyBuilder propertyBuilder,
                        PropertyDescriptor descriptor, MethodAttributes 
propAttribs)
                {
                        var setMethodBuilder = typeBuilder.DefineMethod(
                                "set_" + descriptor.PropertyName, propAttribs, 
null, new[] {descriptor.PropertyType});
 
                        var setILGenerator = setMethodBuilder.GetILGenerator();
-                       PreparePropertyMethod(descriptor, propertyMapField, 
setILGenerator);
+                       PreparePropertyMethod(descriptor, setILGenerator);
 
                        setILGenerator.Emit(OpCodes.Ldarg_1);
                        if (descriptor.PropertyType.IsValueType)
@@ -369,7 +350,7 @@
                        setILGenerator.Emit(OpCodes.Ldarg_0);
                        setILGenerator.Emit(OpCodes.Ldloc_0);
                        setILGenerator.Emit(OpCodes.Ldloca_S, 1);
-                       setILGenerator.Emit(OpCodes.Callvirt, MetaSetProperty);
+                       setILGenerator.Emit(OpCodes.Callvirt, 
AdapterSetProperty);
                        setILGenerator.Emit(OpCodes.Pop);
                        setILGenerator.Emit(OpCodes.Ret);
 
@@ -582,11 +563,11 @@
                }
 
                private object GetExistingAdapter(Type type, Assembly assembly, 
IDictionary dictionary,
-                                                 PropertyDescriptor descriptor)
+                                                                               
  PropertyDescriptor descriptor)
                {
                        var adapterFullTypeName = GetAdapterFullTypeName(type);
-                       return 
Activator.CreateInstance(assembly.GetType(adapterFullTypeName, true),
-                                                       type, this, dictionary, 
descriptor);
+                       var instance = new 
DictionaryAdapterInstance(dictionary, descriptor, this);
+                       return 
Activator.CreateInstance(assembly.GetType(adapterFullTypeName, true), instance);
                }
 
                private Assembly GetExistingAdapterAssembly(AppDomain 
appDomain, string assemblyName)
@@ -598,19 +579,13 @@
 
                #region Reflection Cache
 
-               private static readonly PropertyInfo MetaPropertiesProp =
-                       typeof(IDictionaryAdapter).GetProperty("Properties");
+               private static readonly PropertyInfo AdapterGetMeta =
+                       typeof(IDictionaryAdapter).GetProperty("Meta");
 
-               private static readonly PropertyInfo MetaBehaviorsProp =
-                       typeof(DictionaryAdapterBase).GetProperty("Behaviors");
-
-               private static readonly PropertyInfo MetaInitializersProp =
-                       
typeof(DictionaryAdapterBase).GetProperty("Initializers");
-
-               private static readonly MethodInfo MetaGetProperty =
+               private static readonly MethodInfo AdapterGetProperty =
                        typeof(IDictionaryAdapter).GetMethod("GetProperty");
 
-               private static readonly MethodInfo MetaSetProperty =
+               private static readonly MethodInfo AdapterSetProperty =
                        typeof(IDictionaryAdapter).GetMethod("SetProperty");
 

File [modified]: DictionaryAdapterFactory.cs
Delta lines: +47 -0
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterInstance.cs
                             (rev 0)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterInstance.cs
     2009-11-16 12:05:50 UTC (rev 6336)
@@ -0,0 +1,48 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Components.DictionaryAdapter
+{
+       using System.Collections;
+       using System.Collections.Specialized;
+
+       public class DictionaryAdapterInstance
+       {
+               private HybridDictionary extendedProperties;
+
+               public DictionaryAdapterInstance(IDictionary dictionary, 
PropertyDescriptor descriptor, 
+                                                                               
 IDictionaryAdapterFactory factory)
+               {
+                       Dictionary = dictionary;
+                       Descriptor = descriptor;
+                       Factory = factory;
+               }
+
+               public IDictionary Dictionary { get; private set; }
+
+               public PropertyDescriptor Descriptor { get; private set; }
+
+               public IDictionaryAdapterFactory Factory { get; private set; }
+
+               public IDictionary ExtendedProperties
+               {
+                       get
+                       {
+                               if (extendedProperties == null)
+                                       extendedProperties = new 
HybridDictionary();
+                               return extendedProperties;
+                       }
+               }
+       }

File [added]: DictionaryAdapterInstance.cs
Delta lines: +40 -0
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterMeta.cs
                         (rev 0)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterMeta.cs
 2009-11-16 12:05:50 UTC (rev 6336)
@@ -0,0 +1,41 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Components.DictionaryAdapter
+{
+       using System;
+       using System.Collections;
+       using System.Collections.Generic;
+       using System.Collections.Specialized;
+
+       public class DictionaryAdapterMeta
+       {
+               public DictionaryAdapterMeta(Type type, 
IDictionaryInitializer[] initializers,
+                                                                        
object[] behaviors,  IDictionary<String, PropertyDescriptor> properties)
+               {
+                       Type = type;
+                       Initializers = initializers;
+                       Behaviors = behaviors;
+                       Properties = properties;
+               }
+
+               public Type Type { get; private set; }
+
+               public IDictionaryInitializer[] Initializers { get; private 
set; }
+
+               public object[] Behaviors { get; private set; }
+
+               public IDictionary<String, PropertyDescriptor> Properties { 
get; private set; }
+       }

File [added]: DictionaryAdapterMeta.cs
Delta lines: +1 -1
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryValidateGroup.cs
       2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryValidateGroup.cs
       2009-11-16 12:05:50 UTC (rev 6336)
@@ -30,7 +30,7 @@
                        _groups = groups;
                        _adapter = adapter;
 
-                       _propertyNames = (from property in 
_adapter.Properties.Values
+                       _propertyNames = (from property in 
_adapter.Meta.Properties.Values
                                          from groupings in 
property.Behaviors.OfType<GroupAttribute>()
                                          where Array.IndexOf(_groups, 
groupings.Group) >= 0

File [modified]: DictionaryValidateGroup.cs
Delta lines: +6 -14
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/IDictionaryAdapter.cs
    2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/IDictionaryAdapter.cs
    2009-11-16 12:05:50 UTC (rev 6336)
@@ -23,26 +23,18 @@
        /// </summary>
        public interface IDictionaryAdapter : IDictionaryEdit, 
IDictionaryNotify, IDictionaryValidate, IDictionaryCreate
        {
-               Type Type { get; }
+               DictionaryAdapterMeta Meta { get; }
 
-               IDictionary State { get; }
+               DictionaryAdapterInstance This { get; }
 
-               IDictionary Dictionary { get; }
-
-               IDictionaryInitializer[] Initializers { get; }
-
-               object[] Behaviors { get; }
-
-               PropertyDescriptor Descriptor { get; }
-
-               IDictionary<String, PropertyDescriptor> Properties { get; }
-
-               IDictionaryAdapterFactory Factory { get; }
-
                object GetProperty(string propertyName);
 
+               object ReadProperty(PropertyDescriptor property, string key);
+
                T GetPropertyOfType<T>(string propertyName);
 
                bool SetProperty(string propertyName, ref object value);
+
+               void StoreProperty(PropertyDescriptor property, string key, 
object value);
        }

File [modified]: IDictionaryAdapter.cs
Delta lines: +2 -2
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/PropertyDescriptor.cs
    2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/PropertyDescriptor.cs
    2009-11-16 12:05:50 UTC (rev 6336)
@@ -230,7 +230,7 @@
                        string key, object storedValue, PropertyDescriptor 
descriptor)
                {
                        key = GetKey(dictionaryAdapter, key, descriptor);
-                       storedValue = storedValue ?? 
dictionaryAdapter.Dictionary[key];
+                       storedValue = storedValue ?? 
dictionaryAdapter.ReadProperty(this, key);
 
                        if (getters != null)
                        {
@@ -323,7 +323,7 @@
 
                        if (!consumed)
                        {
-                               dictionaryAdapter.Dictionary[key] = value;
+                               dictionaryAdapter.StoreProperty(this, key, 
value);
                        }
 

File [modified]: PropertyDescriptor.cs
Delta lines: +18 -18
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs
        2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs
        2009-11-16 12:05:50 UTC (rev 6336)
@@ -679,10 +679,10 @@
                [Test]
                public void CanObtainDictionaryAdapterMeta()
                {
-                       var meta = factory.GetAdapter<IPerson>(dictionary) as 
IDictionaryAdapter;
-                       Assert.AreSame(dictionary, meta.Dictionary);
-                       Assert.AreSame(factory, meta.Factory);
-                       Assert.AreEqual(8, meta.Properties.Count);
+                       var adapter = factory.GetAdapter<IPerson>(dictionary) 
as IDictionaryAdapter;
+                       Assert.AreSame(dictionary, adapter.This.Dictionary);
+                       Assert.AreSame(factory, adapter.This.Factory);
+                       Assert.AreEqual(8, adapter.Meta.Properties.Count);
                }
 
                [Test]
@@ -696,9 +696,9 @@
                        Assert.AreEqual("Hello", dictionary["Dictionary"]);
                        Assert.AreEqual(1, dictionary["Properties"]);
 
-                       var meta = i as IDictionaryAdapter;
-                       Assert.AreSame(dictionary, meta.Dictionary);
-                       Assert.AreEqual(3, meta.Properties.Count);
+                       var adapter = i as IDictionaryAdapter;
+                       Assert.AreSame(dictionary, adapter.This.Dictionary);
+                       Assert.AreEqual(3, adapter.Meta.Properties.Count);
                }
 
                [Test]
@@ -1085,34 +1085,34 @@
                [Test]
                public void 
WillNotRaisePropertyChangedEventWhenEditsAreCancelled()
                {
-                       var notifyCalled = false;
+                       var notifyCalled = 0;
                        var person = factory.GetAdapter<IPerson>(dictionary);
                        person.PropertyChanged += (s, e) =>
                        {
                                if (e.PropertyName == "Name")
-                                       notifyCalled = true;
+                                       notifyCalled++;
                        };
                        person.BeginEdit();
                        person.Name = "Craig";
                        person.CancelEdit();
-                       Assert.IsFalse(notifyCalled);
+                       Assert.AreEqual(2, notifyCalled);
                }
 
                [Test]
-               public void 
WillNotRaisePropertyChangedEventWhenNestedEditsAreAccepted()
+               public void 
WillRaisePropertyChangedEventWhenNestedEditsAreCancelled()
                {
-                       var notifyCalled = false;
+                       var notifyCalled = 0;
                        var person = factory.GetAdapter<IPerson>(dictionary);
                        person.BillingAddress.Line1 = "77 Nutmeg Dr.";
                        person.BillingAddress.PropertyChanged += (s, e) =>
                        {
                                if (e.PropertyName == "Line1")
-                                       notifyCalled = true;
+                                       notifyCalled++;
                        };
                        person.BeginEdit();
                        person.BillingAddress.Line1 = "600 Tulip Ln.";
                        person.CancelEdit();
-                       Assert.IsFalse(notifyCalled);
+                       Assert.AreEqual(2, notifyCalled);
                }
 
                [Test]
@@ -1133,7 +1133,7 @@
                }
 
                [Test]
-               public void 
WillRaiseOnePropertyChangedEventsPerReadonlyPropertyWhenEditing()
+               public void 
WillRaisePropertyChangedEventsForReadonlyPropertyWhenEditing()
                {
                        int notifications = 0;
                        var name = factory.GetAdapter<IMutableName>(dictionary);
@@ -1149,11 +1149,11 @@
                        name.EndEdit();
 
                        Assert.AreEqual("Big Tex", name.FullName);
-                       Assert.AreEqual(1, notifications);
+                       Assert.AreEqual(2, notifications);
                }
 
                [Test]
-               public void 
WillNotRaisePropertyChangedEventsForReadonlyPropertyWhenCancelEditing()
+               public void 
WillRaisePropertyChangedEventsForReadonlyPropertyWhenCancelEditing()
                {
                        int notifications = 0;
                        var name = factory.GetAdapter<IMutableName>(dictionary);
@@ -1169,7 +1169,7 @@
                        name.CancelEdit();
 
                        Assert.AreEqual("", name.FullName);
-                       Assert.AreEqual(0, notifications);
+                       Assert.AreEqual(3, notifications);
                }
 

Directory: 
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/
=============================================================================================

File [modified]: DictionaryAdapterFactoryTestCase.cs
Delta lines: +3 -3
===================================================================

--- 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/TestDictionaryValidator.cs
 2009-11-15 22:40:29 UTC (rev 6335)
+++ 
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/TestDictionaryValidator.cs
 2009-11-16 12:05:50 UTC (rev 6336)
@@ -45,9 +45,9 @@
                public string Validate(IDictionaryAdapter dictionaryAdapter)
                {
                        List<String> errors = new List<string>();
-                       var globalRules = 
AttributesUtil.GetTypeAttributes<IValidationRule>(dictionaryAdapter.Type);
+                       var globalRules = 
AttributesUtil.GetTypeAttributes<IValidationRule>(dictionaryAdapter.Meta.Type);
 
-                       foreach (var property in 
dictionaryAdapter.Properties.Values)
+                       foreach (var property in 
dictionaryAdapter.Meta.Properties.Values)
                        {
                                var propertyRules = 
AttributesUtil.GetAttributes<IValidationRule>(property.Property);
                                var propertyValue = 
dictionaryAdapter.GetProperty(property.PropertyName);
@@ -61,7 +61,7 @@
                public string Validate(IDictionaryAdapter dictionaryAdapter, 
PropertyDescriptor property)
                {
                        List<String> errors = new List<string>();
-                       var globalRules = 
AttributesUtil.GetTypeAttributes<IValidationRule>(dictionaryAdapter.Type);
+                       var globalRules = 
AttributesUtil.GetTypeAttributes<IValidationRule>(dictionaryAdapter.Meta.Type);
 
                        var propertyRules = 
AttributesUtil.GetAttributes<IValidationRule>(property.Property);

File [modified]: TestDictionaryValidator.cs
Delta lines: +4 -0
===================================================================

--- Components/DictionaryAdapter/trunk/src/Changes.txt  2009-11-15 22:40:29 UTC 
(rev 6335)
+++ Components/DictionaryAdapter/trunk/src/Changes.txt  2009-11-16 12:05:50 UTC 
(rev 6336)
@@ -1,6 +1,10 @@
 RC 4
 ====
 
+- Group meta and instance properties together
+
+- Standardize edit and non-edit mode with notifications
+
 - Visit children properties to determine if changed
 

Directory: /Components/DictionaryAdapter/trunk/src/
===================================================

File [modified]: Changes.txt
Delta lines: +0 -0
===================================================================

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=.


Reply via email to