From 7410fc9afc066b0da0f6289a994ea3b59e2c025b Mon Sep 17 00:00:00 2001 From: cneuwirt Date: Thu, 20 Mar 2008 12:49:28 +0000 Subject: [PATCH] Added DictionaryTypeKeyPrefixAttribute to scope keys with interface name. git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4921 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../DictionaryAdapterFactoryTestCase.cs | 17 ++++++++++++ .../Attributes/DictionaryTypeKeyPrefixAttribute.cs | 32 ++++++++++++++++++++++ ...stle.Components.DictionaryAdapter-vs2008.csproj | 1 + Components/DictionaryAdapter/Changes.txt | 2 ++ 4 files changed, 52 insertions(+) create mode 100644 Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Attributes/DictionaryTypeKeyPrefixAttribute.cs diff --git a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs index bd7536690..05312979f 100644 --- a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs +++ b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/DictionaryAdapterFactoryTestCase.cs @@ -124,6 +124,17 @@ namespace Castle.Components.DictionaryAdapter.Tests } [Test] + public void UpdateAdapterAndRead_TypePrefix_Matches() + { + IPersonWithTypePrefixOverride person = + factory.GetAdapter(dictionary); + person.Height = 72; + + Assert.AreEqual(72, person.Height); + Assert.AreEqual(72, dictionary["Castle.Components.DictionaryAdapter.Tests.IPersonWithTypePrefixOverride#Height"]); + } + + [Test] public void ReadAdapter_NoPrefixUnitialized_ReturnsDefaults() { IPerson person = factory.GetAdapter(dictionary); @@ -721,6 +732,12 @@ namespace Castle.Components.DictionaryAdapter.Tests string EyeColour { get; set; } } + [DictionaryTypeKeyPrefix] + public interface IPersonWithTypePrefixOverride : IPersonWithPrefixOverride + { + int Height { get; set; } + } + public interface IPersonWithPrefixOverrideFurtherOverride : IPersonWithPrefixOverride { int NumberOfHeads { get; set; } diff --git a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Attributes/DictionaryTypeKeyPrefixAttribute.cs b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Attributes/DictionaryTypeKeyPrefixAttribute.cs new file mode 100644 index 000000000..16dda55f3 --- /dev/null +++ b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Attributes/DictionaryTypeKeyPrefixAttribute.cs @@ -0,0 +1,32 @@ +// Copyright 2004-2008 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; + + /// + /// Assigns a prefix to the keyed properties using the interface name. + /// + [AttributeUsage(AttributeTargets.Interface, AllowMultiple = false, Inherited = true)] + public class DictionaryTypeKeyPrefixAttribute : DictionaryBehaviorAttribute, IDictionaryKeyBuilder + { + String IDictionaryKeyBuilder.GetKey(IDictionary dictionary, String key, + PropertyDescriptor property) + { + return property.Property.DeclaringType.FullName + "#" + key; + } + } +} \ No newline at end of file diff --git a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj index d6b167c07..826dd1eda 100644 --- a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj +++ b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj @@ -61,6 +61,7 @@ + diff --git a/Components/DictionaryAdapter/Changes.txt b/Components/DictionaryAdapter/Changes.txt index f853a01e4..bbe87d9e4 100644 --- a/Components/DictionaryAdapter/Changes.txt +++ b/Components/DictionaryAdapter/Changes.txt @@ -1,6 +1,8 @@ RC 4 ==== +- Added DictionaryTypeKeyPrefixAttribute to use the interface type for scoping + - Added DictionaryStringListAttribute to support delimited string conversion - Created PropertyDescriptor to simplify IL generation -- 2.11.4.GIT