Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phirSOFT.ContextProperties/ContextProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ContextProperty(IContextPool<IContextProperty<TValue>, TValue> contextPoo

public IContextPool<IContextProperty<TValue>, TValue> ContextPool { get; }

public IContextProvider<ContextProperty<TValue>, TValue> DefaultContext { get; set; }
public IContextProvider<IContextProperty<TValue>, TValue> DefaultContext { get; set; }

public TValue this[object target, IContextProvider<IContextProperty<TValue>, TValue> context] => ContextPool[context]
.First(c => c.OverridesValue(target, this)).GetValue(target, this);
Expand Down
9 changes: 9 additions & 0 deletions phirSOFT.ContextProperties/IContextProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace phirSOFT.ContextProperties
{
public interface IContextProperty<TValue>
{
TValue this[object instance, IContextProvider<IContextProperty<TValue>, TValue> context] { get; }

IContextProvider<IContextProperty<TValue>, TValue> DefaultContext { get; }
}
}
4 changes: 0 additions & 4 deletions phirSOFT.ContextProperties/IContextProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ public interface IContextProvider<in TProperty, out TValue> where TProperty : IC
TValue GetValue(object targetObject, TProperty targetProperty);
bool OverridesValue(object targetObject, TProperty targetProperty);
}

public interface IContextProperty<TValue>
{
}
}
16 changes: 16 additions & 0 deletions phirSOFT.ContextProperties/IMemberContextProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Text;

namespace phirSOFT.ContextProperties
{
/// <summary>
/// Provides a way to define a context property in an interface.
/// </summary>
/// <typeparam name="TValue">The type of the property in the interface.</typeparam>
public interface IMemberContextProperty<TValue>
{
TValue this[IContextProvider<IContextProperty<TValue>, TValue> context] { get; }

TValue Value { get; }
}
}
25 changes: 25 additions & 0 deletions phirSOFT.ContextProperties/MemberContextProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace phirSOFT.ContextProperties
{
/// <summary>
/// Implements the <see cref="IMemberContextProperty{TValue}"/>. This implementation does not keep the object alive.
/// </summary>
/// <typeparam name="TValue"></typeparam>
public class MemberContextProperty<TValue> : IMemberContextProperty<TValue>
{
private readonly IContextProperty<TValue> _contextProperty;
private readonly WeakReference _instance;

public MemberContextProperty(IContextProperty<TValue> contextProperty, object instance)
{
_contextProperty = contextProperty;
_instance = new WeakReference(instance);
}

public TValue this[IContextProvider<IContextProperty<TValue>, TValue> context] =>
_contextProperty[_instance, context];

public TValue Value => _contextProperty[_instance.Target, _contextProperty.DefaultContext];
}
}