From a4d4bd21faeab08a9253a36d2496a5a427247a53 Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Tue, 13 Mar 2018 14:02:39 +0100 Subject: [PATCH 1/4] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fa05ec..1a67361 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # ContextProperties -A Framework that enables you to evaluate properties context dependent. +The ContextProperty Framework provides a way to define properties that can return differenc values depending on a given context. The actual use of the such a property may be very specific but there are some examples: + +* Localistaion of strin properties From 7cd73426430db7ac5bfbdd33636566124bfaf743 Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 11:09:54 +0200 Subject: [PATCH 2/4] Implement TargetObjectContextProvider --- .../TargetObjectContextProvider.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 phirSOFT.ContextProperties/TargetObjectContextProvider.cs diff --git a/phirSOFT.ContextProperties/TargetObjectContextProvider.cs b/phirSOFT.ContextProperties/TargetObjectContextProvider.cs new file mode 100644 index 0000000..5d61e96 --- /dev/null +++ b/phirSOFT.ContextProperties/TargetObjectContextProvider.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace phirSOFT.ContextProperties +{ + /// + /// Implements a that redirects the calls to the target object if possible. + /// + /// THe type of the property. + /// The type of the value. + public class TargetObjectContextProvider : IContextProvider where TProperty : IContextProperty + { + /// + public TValue GetValue(object targetObject, TProperty targetProperty) + { + return ((IContextProvider) targetObject).GetValue(targetObject, targetProperty); + } + + /// + public bool OverridesValue(object targetObject, TProperty targetProperty) + { + return targetObject is IContextProvider provider && + provider.OverridesValue(targetObject, targetProperty); + } + } +} From af4558abde9c8f195c0d1cf36d727f664792260a Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 12:41:22 +0200 Subject: [PATCH 3/4] Implement special comparer --- ...extProviderTree.ContextProviderComparer.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.ContextProviderComparer.cs diff --git a/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.ContextProviderComparer.cs b/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.ContextProviderComparer.cs new file mode 100644 index 0000000..1cab1c2 --- /dev/null +++ b/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.ContextProviderComparer.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Text; +using phirSOFT.TopologicalComparison; + +namespace phirSOFT.ContextProperties +{ + public partial class ContextProperty + { + private partial class ContextProviderTree + { + internal class ContextProviderComparer : ITopologicalComparer, TValue>> + { + public int Compare(IContextProvider, TValue> x, IContextProvider, TValue> y) + { + { + if (x is ITopologicalComparable, TValue>> xcomp) + return xcomp.CompareTo(y); + + if (y is ITopologicalComparable, TValue>> ycomp) + return ycomp.CompareTo(x); + } + + { + if (x is ITopologicalComparable xcomp) + return xcomp.CompareTo(y); + + if (y is ITopologicalComparable ycomp) + return ycomp.CompareTo(x); + } + + { + if (x is IComparable, TValue>> xcomp) + return xcomp.CompareTo(y); + + if (y is IComparable, TValue>> ycomp) + return ycomp.CompareTo(x); + } + + { + if (x is IComparable xcomp) + return xcomp.CompareTo(y); + + if (y is IComparable ycomp) + return ycomp.CompareTo(x); + } + + throw new InvalidOperationException("Could not compare types"); + } + + public bool CanCompare(IContextProvider, TValue> x, IContextProvider, TValue> y) + { + { + if (x is ITopologicalComparable, TValue>> xcomp) + return xcomp.CanCompareTo(y); + + if (y is ITopologicalComparable, TValue>> ycomp) + return ycomp.CanCompareTo(x); + } + + { + if (x is ITopologicalComparable xcomp) + return xcomp.CanCompareTo(y); + + if (y is ITopologicalComparable ycomp) + return ycomp.CanCompareTo(x); + } + + return x is IComparable, TValue>> || + y is IComparable, TValue>> || + x is IComparable || + y is IComparable; + } + } + } + } +} From 2fad253ec12de46c9b6981eb4662584cebc157c6 Mon Sep 17 00:00:00 2001 From: Philemon Eichin Date: Thu, 12 Apr 2018 12:43:20 +0200 Subject: [PATCH 4/4] Changed ContextProviderTrees comparer --- .../ContextProperty.ContextProviderTree.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.cs b/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.cs index 486fb4d..0fb06f7 100644 --- a/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.cs +++ b/phirSOFT.ContextProperties/ContextProperty.ContextProviderTree.cs @@ -88,7 +88,7 @@ public IEnumerable, TValue>> this[ICon return _nodes[key]; IContextProvider, TValue> lastFound = null; - var comparer = TopologicalComparer, TValue>>.Default; + var comparer = new ContextProviderComparer(); foreach (var nodesKey in _nodes.Keys) {