Skip to content

Commit

Permalink
Merge pull request #1 from phirSOFT/TargetContextProvider
Browse files Browse the repository at this point in the history
Implement TargetObjectContextProvider
  • Loading branch information
Pretasoc authored Apr 12, 2018
2 parents a4d4bd2 + 7cd7342 commit 3158d42
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions phirSOFT.ContextProperties/TargetObjectContextProvider.cs
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);
}
}
}

0 comments on commit 3158d42

Please sign in to comment.