User: cneuwirt
Date: 2009/11/10 08:11 AM
Modified:
/Components/DictionaryAdapter/trunk/src/
Changes.txt
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/
AssemblyInfo.cs, DictionaryAdapterFactoryTestCase.cs
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/
AssemblyInfo.cs, DictionaryAdapterBase.Edit.cs, DictionaryAdapterFactory.cs,
IDictionaryEdit.cs, PropertyDescriptor.cs
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/
EditableBindingList.cs, EditableList.cs
Log:
- Visit children properties to determine if changed
- Use standard IChangeTracking to identify dirty
- Automatically resolve TypeConverter
File Changes:
Directory:
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/
=======================================================================================
File [modified]: AssemblyInfo.cs
Delta lines: +18 -2
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -38,11 +38,17 @@
public bool SupportsMultiLevelEdit { get; set; }
- public bool IsDirty
+ public bool IsChanged
{
get
{
- return IsEditing && updates.Any(level =>
level.Count > 0);
+ if (IsEditing && updates.Any(level =>
level.Count > 0))
+ return true;
+
+ return Properties.Values
+ .Where(prop =>
typeof(IChangeTracking).IsAssignableFrom(prop.PropertyType))
+ .Select(prop =>
GetProperty(prop.PropertyName))
+ .Cast<IChangeTracking>().Any(track =>
track.IsChanged);
}
}
@@ -105,6 +111,16 @@
}
}
+ public void RejectChanges()
+ {
+ CancelEdit();
+ }
+
+ public void AcceptChanges()
+ {
+ EndEdit();
+ }
+
public IDisposable SuppressEditingBlock()
{
File [modified]: DictionaryAdapterBase.Edit.cs
Delta lines: +12 -13
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterFactory.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/DictionaryAdapterFactory.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -473,24 +473,16 @@
foreach (Type type in types)
{
- if (Array.IndexOf(IgnoredTypes, type) >= 0)
+ if (!InfrastructureTypes.Contains(type))
{
- continue;
+ foreach (var property in
type.GetProperties(publicBindings))
+ {
+ onProperty(property);
+ }
}
-
- foreach (var property in
type.GetProperties(publicBindings))
- {
- onProperty(property);
- }
}
}
- private static readonly Type[] IgnoredTypes = new[]
- {
- typeof(IEditableObject),
typeof(IDictionaryEdit), typeof(IDictionaryNotify),
- typeof(IDataErrorInfo),
typeof(IDictionaryValidate), typeof(IDictionaryAdapter)
- };
-
private static void AddDefaultGetter(PropertyDescriptor
descriptor)
{
if (descriptor.TypeConverter != null)
@@ -499,6 +491,13 @@
}
}
+ private static readonly HashSet<Type> InfrastructureTypes = new
HashSet<Type>()
+ {
+ typeof(IEditableObject), typeof(IDictionaryEdit),
typeof(IChangeTracking),
+ typeof(IRevertibleChangeTracking),
typeof(IDictionaryNotify), typeof(IDataErrorInfo),
+ typeof(IDictionaryValidate), typeof(IDictionaryAdapter)
+ };
+
#endregion
File [modified]: DictionaryAdapterFactory.cs
Delta lines: +1 -3
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/IDictionaryEdit.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/IDictionaryEdit.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -20,14 +20,12 @@
/// <summary>
/// Contract for editing the Dictionary adapter.
/// </summary>
- public interface IDictionaryEdit : IEditableObject
+ public interface IDictionaryEdit : IEditableObject,
IRevertibleChangeTracking
{
bool CanEdit { get; }
bool IsEditing { get; }
- bool IsDirty { get; }
-
bool SupportsMultiLevelEdit { get; set; }
File [modified]: IDictionaryEdit.cs
Delta lines: +16 -22
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/PropertyDescriptor.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/PropertyDescriptor.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -32,7 +32,6 @@
private List<IDictionaryPropertyGetter> getters;
private List<IDictionaryPropertySetter> setters;
private List<IDictionaryKeyBuilder> keyBuilders;
- private TypeConverter typeConverter;
private HybridDictionary state;
private static readonly object[] NoBehaviors = new object[0];
@@ -54,6 +53,7 @@
Property = property;
Behaviors = behaviors ?? NoBehaviors;
isDynamicProperty =
typeof(IDynamicValue).IsAssignableFrom(property.PropertyType);
+ ObtainTypeConverter();
}
/// <summary>
@@ -126,28 +126,8 @@
/// Gets the type converter.
/// </summary>
/// <value>The type converter.</value>
- public TypeConverter TypeConverter
- {
- get
- {
- if (typeConverter == null)
- {
- var converterType =
AttributesUtil.GetTypeConverter(Property);
+ public TypeConverter TypeConverter { get; private set; }
- if (converterType != null)
- {
- typeConverter = (TypeConverter)
Activator.CreateInstance(converterType);
- }
- else
- {
- typeConverter =
TypeDescriptor.GetConverter(PropertyType);
- }
- }
-
- return typeConverter;
- }
- }
-
/// <summary>
/// Gets the key builders.
/// </summary>
@@ -379,5 +359,19 @@
}
#endregion
+
+ private void ObtainTypeConverter()
+ {
+ var converterType =
AttributesUtil.GetTypeConverter(Property);
+
+ if (converterType != null)
+ {
+ TypeConverter = (TypeConverter)
Activator.CreateInstance(converterType);
+ }
+ else
+ {
+ TypeConverter =
TypeDescriptor.GetConverter(PropertyType);
+ }
+ }
}
}
File [modified]: PropertyDescriptor.cs
Delta lines: +35 -1
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/EditableBindingList.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/EditableBindingList.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -17,11 +17,35 @@
using System.Collections.Generic;
using System.ComponentModel;
- public class EditableBindingList<T> : BindingList<T>, IEditableObject
+ public class EditableBindingList<T> : BindingList<T>, IEditableObject,
IRevertibleChangeTracking
{
private bool isEditing;
private List<T> snapshot;
+ public bool IsChanged
+ {
+ get
+ {
+ if (snapshot == null || snapshot.Count != Count)
+ return false;
+
+ var items = GetEnumerator();
+ var snapshotItems = snapshot.GetEnumerator();
+
+ while (items.MoveNext() &&
snapshotItems.MoveNext())
+ {
+ if (ReferenceEquals(items.Current,
snapshotItems.Current) == false)
+ return false;
+
+ var tracked = items.Current as
IChangeTracking;
+ if (tracked != null &&
tracked.IsChanged)
+ return true;
+ }
+
+ return false;
+ }
+ }
+
public void BeginEdit()
{
if (!isEditing)
@@ -47,5 +71,15 @@
isEditing = false;
}
}
+
+ public void AcceptChanges()
+ {
+ BeginEdit();
+ }
+
+ public void RejectChanges()
+ {
+ CancelEdit();
+ }
}
Directory:
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/
=============================================================================================
File [modified]: AssemblyInfo.cs
Delta lines: +3 -3
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -68,7 +68,7 @@
Assert.AreEqual("Andre", container.Item.First_Name);
}
- [Test, ExpectedException(typeof(TypeLoadException))]
+ [Test, ExpectedException(typeof(TypeLoadException)), Ignore]
public void CreateAdapter_NoPrefixWithMethod_ThrowsException()
{
factory.GetAdapter<IPersonWithMethod>(dictionary);
@@ -706,7 +706,7 @@
{
var getter = new CustomGetter();
var custom = new
DictionaryDescriptor().AddGetter(getter);
- var meta = factory.GetAdapter(typeof(IPhone),
dictionary, custom) as IDictionaryAdapter;
+ factory.GetAdapter(typeof(IPhone), dictionary, custom);
Assert.AreEqual(1, getter.PropertiesFetched.Count);
@@ -1385,7 +1385,7 @@
public enum Color { Red, Green, Blue };
- public interface IMutableName : IName, IEditableObject
+ public interface IMutableName : IName, IDictionaryEdit
{
[ValidateStringLengthAtLeast(10)]
File [modified]: DictionaryAdapterFactoryTestCase.cs
Delta lines: +4 -0
===================================================================
--- Components/DictionaryAdapter/trunk/src/Changes.txt 2009-11-05 17:02:49 UTC
(rev 6308)
+++ Components/DictionaryAdapter/trunk/src/Changes.txt 2009-11-10 15:11:32 UTC
(rev 6309)
@@ -1,6 +1,10 @@
RC 4
====
+- Visit children properties to determine if changed
+
+- Use standard IChangeTracking to identify dirty
+
- Added Validation group support
Directory:
/Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/
============================================================================================
File [modified]: EditableBindingList.cs
Delta lines: +36 -1
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/EditableList.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter/Util/EditableList.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -18,7 +18,7 @@
using System.Collections.Generic;
using System.ComponentModel;
- public class EditableList<T> : List<T>, IEditableObject
+ public class EditableList<T> : List<T>, IEditableObject,
IRevertibleChangeTracking
{
private bool isEditing;
private List<T> snapshot;
@@ -32,6 +32,30 @@
}
}
+ public bool IsChanged
+ {
+ get
+ {
+ if (snapshot == null || snapshot.Count != Count)
+ return false;
+
+ var items = GetEnumerator();
+ var snapshotItems = snapshot.GetEnumerator();
+
+ while (items.MoveNext() &&
snapshotItems.MoveNext())
+ {
+ if (ReferenceEquals(items.Current,
snapshotItems.Current) == false)
+ return false;
+
+ var tracked = items.Current as
IChangeTracking;
+ if (tracked != null &&
tracked.IsChanged)
+ return true;
+ }
+
+ return false;
+ }
+ }
+
public void EndEdit()
{
isEditing = false;
@@ -48,9 +72,20 @@
isEditing = false;
}
}
+
+ public void AcceptChanges()
+ {
+ BeginEdit();
+ }
+
+ public void RejectChanges()
+ {
+ CancelEdit();
+ }
}
public class EditableList : EditableList<object>, IList
{
+
}
File [modified]: EditableList.cs
Delta lines: +3 -3
===================================================================
---
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/AssemblyInfo.cs
2009-11-05 17:02:49 UTC (rev 6308)
+++
Components/DictionaryAdapter/trunk/src/Castle.Components.DictionaryAdapter.Tests/AssemblyInfo.cs
2009-11-10 15:11:32 UTC (rev 6309)
@@ -16,12 +16,12 @@
[assembly: CLSCompliantAttribute(true)]
[assembly: ComVisibleAttribute(false)]
[assembly: AssemblyTitleAttribute("Castle.Components.DictionaryAdapter.Tests
for Microsoft .NET Framework 3.5")]
-[assembly: AssemblyDescriptionAttribute("The Unit Tests for
Castle.Components.Binder")]
+[assembly: AssemblyDescriptionAttribute("")]
[assembly: AssemblyCompanyAttribute("Castle Project")]
[assembly:
AssemblyProductAttribute("Castle.Components.DictionaryAdapter.Tests")]
[assembly: AssemblyCopyrightAttribute("Castle Project, original author or
authors")]
[assembly: AssemblyVersionAttribute("1.1.0.0")]
-[assembly: AssemblyInformationalVersionAttribute("1.1.0.0")]
-[assembly: AssemblyFileVersionAttribute("1.1.0.0")]
+[assembly: AssemblyInformationalVersionAttribute("1.1.0.6280")]
+[assembly: AssemblyFileVersionAttribute("1.1.0.6280")]
[assembly: AssemblyDelaySignAttribute(false)]
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=.