-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from phirSOFT/TargetContextProvider
Implement TargetObjectContextProvider
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace phirSOFT.ContextProperties | ||
{ | ||
/// <summary> | ||
/// Implements a <see cref="IContextProvider{TProperty,TValue}"/> that redirects the calls to the target object if possible. | ||
/// </summary> | ||
/// <typeparam name="TProperty">THe type of the property.</typeparam> | ||
/// <typeparam name="TValue">The type of the value.</typeparam> | ||
public class TargetObjectContextProvider<TProperty, TValue> : IContextProvider<TProperty, TValue> where TProperty : IContextProperty<TValue> | ||
{ | ||
/// <inheritdoc cref="IContextProvider{TProperty,TValue}.GetValue"/> | ||
public TValue GetValue(object targetObject, TProperty targetProperty) | ||
{ | ||
return ((IContextProvider<TProperty, TValue>) targetObject).GetValue(targetObject, targetProperty); | ||
} | ||
|
||
/// <inheritdoc cref="IContextProvider{TProperty,TValue}.OverridesValue"/> | ||
public bool OverridesValue(object targetObject, TProperty targetProperty) | ||
{ | ||
return targetObject is IContextProvider<TProperty, TValue> provider && | ||
provider.OverridesValue(targetObject, targetProperty); | ||
} | ||
} | ||
} |