Browse Source

Log binding path.

pull/237/head
Steven Kirk 11 years ago
parent
commit
14ca308900
  1. 11
      src/Markup/Perspex.Markup/Binding/ExpressionObserver.cs
  2. 5
      src/Markup/Perspex.Markup/Binding/ExpressionSubject.cs
  3. 6
      src/Markup/Perspex.Markup/Perspex.Markup.csproj
  4. 24
      src/Perspex.Base/PerspexObject.cs
  5. 4
      tests/Perspex.Markup.UnitTests/Perspex.Markup.UnitTests.csproj

11
src/Markup/Perspex.Markup/Binding/ExpressionObserver.cs

@ -10,7 +10,7 @@ namespace Perspex.Markup.Binding
/// <summary> /// <summary>
/// Observes and sets the value of an expression on an object. /// Observes and sets the value of an expression on an object.
/// </summary> /// </summary>
public class ExpressionObserver : ObservableBase<ExpressionValue> public class ExpressionObserver : ObservableBase<ExpressionValue>, IDescription
{ {
private object _root; private object _root;
private int _count; private int _count;
@ -25,6 +25,7 @@ namespace Perspex.Markup.Binding
{ {
_root = root; _root = root;
_node = ExpressionNodeBuilder.Build(expression); _node = ExpressionNodeBuilder.Build(expression);
Expression = expression;
} }
/// <summary> /// <summary>
@ -49,6 +50,11 @@ namespace Perspex.Markup.Binding
} }
} }
/// <summary>
/// Gets the expression being observed.
/// </summary>
public string Expression { get; }
/// <summary> /// <summary>
/// Gets or sets the root object that the expression is being observed on. /// Gets or sets the root object that the expression is being observed on.
/// </summary> /// </summary>
@ -73,6 +79,9 @@ namespace Perspex.Markup.Binding
} }
} }
/// <inheritdoc/>
string IDescription.Description => Expression;
/// <inheritdoc/> /// <inheritdoc/>
protected override IDisposable SubscribeCore(IObserver<ExpressionValue> observer) protected override IDisposable SubscribeCore(IObserver<ExpressionValue> observer)
{ {

5
src/Markup/Perspex.Markup/Binding/ExpressionSubject.cs

@ -10,7 +10,7 @@ namespace Perspex.Markup.Binding
/// <summary> /// <summary>
/// Turns an <see cref="ExpressionObserver"/> into a subject that can be bound two-ways. /// Turns an <see cref="ExpressionObserver"/> into a subject that can be bound two-ways.
/// </summary> /// </summary>
public class ExpressionSubject : ISubject<object> public class ExpressionSubject : ISubject<object>, IDescription
{ {
private ExpressionObserver _inner; private ExpressionObserver _inner;
@ -23,6 +23,9 @@ namespace Perspex.Markup.Binding
_inner = inner; _inner = inner;
} }
/// <inheritdoc/>
string IDescription.Description => _inner.Expression;
/// <inheritdoc/> /// <inheritdoc/>
public void OnCompleted() public void OnCompleted()
{ {

6
src/Markup/Perspex.Markup/Perspex.Markup.csproj

@ -71,6 +71,12 @@
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj">
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

24
src/Perspex.Base/PerspexObject.cs

@ -335,7 +335,7 @@ namespace Perspex
PropertyChanged -= handler; PropertyChanged -= handler;
}); });
}, },
GetObservableDescription(property)); GetDescription(property));
} }
/// <summary> /// <summary>
@ -378,7 +378,7 @@ namespace Perspex
PropertyChanged -= handler; PropertyChanged -= handler;
}); });
}, },
GetObservableDescription(property)); GetDescription(property));
} }
/// <summary> /// <summary>
@ -591,14 +591,13 @@ namespace Perspex
_propertyLog.Verbose( _propertyLog.Verbose(
"Bound {Property} to {Binding} with priority LocalValue", "Bound {Property} to {Binding} with priority LocalValue",
property, property,
source); GetDescription(source));
return source.Subscribe(x => SetValue(property, x)); return source.Subscribe(x => SetValue(property, x));
} }
else else
{ {
PriorityValue v; PriorityValue v;
IDescription description = source as IDescription;
if (!IsRegistered(property)) if (!IsRegistered(property))
{ {
@ -614,7 +613,7 @@ namespace Perspex
_propertyLog.Verbose( _propertyLog.Verbose(
"Bound {Property} to {Binding} with priority {Priority}", "Bound {Property} to {Binding} with priority {Priority}",
property, property,
source, GetDescription(source),
priority); priority);
return v.Add(source, (int)priority); return v.Add(source, (int)priority);
@ -706,7 +705,7 @@ namespace Perspex
_propertyLog.Verbose( _propertyLog.Verbose(
"Bound two way {Property} to {Binding} with priority {Priority}", "Bound two way {Property} to {Binding} with priority {Priority}",
property, property,
source, GetDescription(source),
priority); priority);
return new CompositeDisposable( return new CompositeDisposable(
@ -959,11 +958,22 @@ namespace Perspex
/// </summary> /// </summary>
/// <param name="property">The property</param> /// <param name="property">The property</param>
/// <returns>The description.</returns> /// <returns>The description.</returns>
private string GetObservableDescription(PerspexProperty property) private string GetDescription(PerspexProperty property)
{ {
return string.Format("{0}.{1}", GetType().Name, property.Name); return string.Format("{0}.{1}", GetType().Name, property.Name);
} }
/// <summary>
/// Gets a description of an observable that van be used in logs.
/// </summary>
/// <param name="o">The observable.</param>
/// <returns>The description.</returns>
private string GetDescription(IObservable<object> o)
{
var description = o as IDescription;
return description?.Description ?? o.ToString();
}
/// <summary> /// <summary>
/// Logs a property set message. /// Logs a property set message.
/// </summary> /// </summary>

4
tests/Perspex.Markup.UnitTests/Perspex.Markup.UnitTests.csproj

@ -91,6 +91,10 @@
<Project>{6417e941-21bc-467b-a771-0de389353ce6}</Project> <Project>{6417e941-21bc-467b-a771-0de389353ce6}</Project>
<Name>Perspex.Markup</Name> <Name>Perspex.Markup</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\src\Perspex.Base\Perspex.Base.csproj">
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

Loading…
Cancel
Save