From 4de38d19197bc04b9e4897258710591043d68dbf Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 09:39:09 +0200 Subject: [PATCH 1/5] Add IMemberInterfaceProperty Interface for defining ContextProperties in interfaces +semver:feature --- .../IMemberContextProperty.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 phirSOFT.ContextProperties/IMemberContextProperty.cs diff --git a/phirSOFT.ContextProperties/IMemberContextProperty.cs b/phirSOFT.ContextProperties/IMemberContextProperty.cs new file mode 100644 index 0000000..91b4c43 --- /dev/null +++ b/phirSOFT.ContextProperties/IMemberContextProperty.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace phirSOFT.ContextProperties +{ + /// + /// Provides a way to define a context property in an interface. + /// + /// The type of the property in the interface. + public interface IMemberContextProperty + { + TValue this[IContextProvider, TValue> context] { get; } + } +} From 884819fae9bb751de902b4094338ea98a6009e8f Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 09:50:50 +0200 Subject: [PATCH 2/5] Add DefaultContext Value IMemberContextProperties now supports default contexts Values --- phirSOFT.ContextProperties/IMemberContextProperty.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phirSOFT.ContextProperties/IMemberContextProperty.cs b/phirSOFT.ContextProperties/IMemberContextProperty.cs index 91b4c43..dd1605b 100644 --- a/phirSOFT.ContextProperties/IMemberContextProperty.cs +++ b/phirSOFT.ContextProperties/IMemberContextProperty.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Text; namespace phirSOFT.ContextProperties @@ -11,5 +10,7 @@ namespace phirSOFT.ContextProperties public interface IMemberContextProperty { TValue this[IContextProvider, TValue> context] { get; } + + TValue Value { get; } } } From 0eaa9e092bec4ebf0e12453ad507860cb751c9a6 Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 09:52:18 +0200 Subject: [PATCH 3/5] Refactor IContextPropery + Moved Members from ContextProperty to IContextProperty + Used more abstract types + Moved IContextProperty to own file --- phirSOFT.ContextProperties/ContextProperty.cs | 2 +- phirSOFT.ContextProperties/IContextProperty.cs | 9 +++++++++ phirSOFT.ContextProperties/IContextProvider.cs | 4 ---- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 phirSOFT.ContextProperties/IContextProperty.cs diff --git a/phirSOFT.ContextProperties/ContextProperty.cs b/phirSOFT.ContextProperties/ContextProperty.cs index bce64ce..233a5d1 100644 --- a/phirSOFT.ContextProperties/ContextProperty.cs +++ b/phirSOFT.ContextProperties/ContextProperty.cs @@ -17,7 +17,7 @@ public ContextProperty(IContextPool, TValue> contextPoo public IContextPool, TValue> ContextPool { get; } - public IContextProvider, TValue> DefaultContext { get; set; } + public IContextProvider, TValue> DefaultContext { get; set; } public TValue this[object target, IContextProvider, TValue> context] => ContextPool[context] .First(c => c.OverridesValue(target, this)).GetValue(target, this); diff --git a/phirSOFT.ContextProperties/IContextProperty.cs b/phirSOFT.ContextProperties/IContextProperty.cs new file mode 100644 index 0000000..d57ccab --- /dev/null +++ b/phirSOFT.ContextProperties/IContextProperty.cs @@ -0,0 +1,9 @@ +namespace phirSOFT.ContextProperties +{ + public interface IContextProperty + { + TValue this[object instance, IContextProvider, TValue> context] { get; } + + IContextProvider, TValue> DefaultContext { get; } + } +} \ No newline at end of file diff --git a/phirSOFT.ContextProperties/IContextProvider.cs b/phirSOFT.ContextProperties/IContextProvider.cs index e71235f..4c31dc0 100644 --- a/phirSOFT.ContextProperties/IContextProvider.cs +++ b/phirSOFT.ContextProperties/IContextProvider.cs @@ -7,8 +7,4 @@ public interface IContextProvider where TProperty : IC TValue GetValue(object targetObject, TProperty targetProperty); bool OverridesValue(object targetObject, TProperty targetProperty); } - - public interface IContextProperty - { - } } \ No newline at end of file From f499585d5575a523bc549b895340cca3124918bf Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 09:52:43 +0200 Subject: [PATCH 4/5] Implement IMemberContextProperty --- .../MemberContextProperty.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 phirSOFT.ContextProperties/MemberContextProperty.cs diff --git a/phirSOFT.ContextProperties/MemberContextProperty.cs b/phirSOFT.ContextProperties/MemberContextProperty.cs new file mode 100644 index 0000000..8931da9 --- /dev/null +++ b/phirSOFT.ContextProperties/MemberContextProperty.cs @@ -0,0 +1,19 @@ +using System; + +namespace phirSOFT.ContextProperties +{ + /// + /// Implements the . This implementation does not keep the object alive. + /// + /// + public class MemberContextProperty : IMemberContextProperty + { + private IContextProperty contextProperty; + private readonly WeakReference _instance; + + public TValue this[IContextProvider, TValue> context] => + contextProperty[_instance, context]; + + public TValue Value => contextProperty[_instance.Target, contextProperty.DefaultContext]; + } +} \ No newline at end of file From 214c19acd2996cfbecaeec6ad7e536744553bbc2 Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 10:56:14 +0200 Subject: [PATCH 5/5] Provide Constructor for MemberContextProperty --- phirSOFT.ContextProperties/MemberContextProperty.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/phirSOFT.ContextProperties/MemberContextProperty.cs b/phirSOFT.ContextProperties/MemberContextProperty.cs index 8931da9..ec753ea 100644 --- a/phirSOFT.ContextProperties/MemberContextProperty.cs +++ b/phirSOFT.ContextProperties/MemberContextProperty.cs @@ -8,12 +8,18 @@ namespace phirSOFT.ContextProperties /// public class MemberContextProperty : IMemberContextProperty { - private IContextProperty contextProperty; + private readonly IContextProperty _contextProperty; private readonly WeakReference _instance; + public MemberContextProperty(IContextProperty contextProperty, object instance) + { + _contextProperty = contextProperty; + _instance = new WeakReference(instance); + } + public TValue this[IContextProvider, TValue> context] => - contextProperty[_instance, context]; + _contextProperty[_instance, context]; - public TValue Value => contextProperty[_instance.Target, contextProperty.DefaultContext]; + public TValue Value => _contextProperty[_instance.Target, _contextProperty.DefaultContext]; } } \ No newline at end of file