Browse Source

More stylecop fixes.

pull/58/head
Steven Kirk 11 years ago
parent
commit
e125d7e10c
  1. 9
      Perspex.Base/IDescription.cs
  2. 72
      Perspex.Base/PerspexObject.cs
  3. 193
      Perspex.Base/PerspexProperty.cs
  4. 22
      Perspex.Base/PerspexPropertyChangedEventArgs.cs
  5. 80
      Perspex.Base/PerspexProperty`1.cs

9
Perspex.Base/IDescription.cs

@ -6,8 +6,17 @@
namespace Perspex
{
/// <summary>
/// Interface for objects with a <see cref="Description"/>.
/// </summary>
public interface IDescription
{
/// <summary>
/// Gets the description of the object.
/// </summary>
/// <value>
/// The description of the object.
/// </value>
string Description { get; }
}
}

72
Perspex.Base/PerspexObject.cs

@ -6,9 +6,6 @@
namespace Perspex
{
using Perspex.Reactive;
using Serilog;
using Serilog.Core.Enrichers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -16,6 +13,9 @@ namespace Perspex
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reflection;
using Perspex.Reactive;
using Serilog;
using Serilog.Core.Enrichers;
/// <summary>
/// The priority of a binding.
@ -36,9 +36,9 @@ namespace Perspex
/// A triggered style binding.
/// </summary>
/// <remarks>
/// A style trigger is a selector such as .class which overrides a
/// A style trigger is a selector such as .class which overrides a
/// <see cref="TemplatedParent"/> binding. In this way, a basic control can have
/// for example a Background from the templated parent which changes when the
/// for example a Background from the templated parent which changes when the
/// control has the :pointerover class.
/// </remarks>
StyleTrigger,
@ -134,9 +134,12 @@ namespace Perspex
}
/// <summary>
/// Gets or sets the parent object that inherited <see cref="PerspexProperty"/> values
/// Gets or sets the parent object that inherited <see cref="PerspexProperty"/> values
/// are inherited from.
/// </summary>
/// <value>
/// The inheritance parent.
/// </value>
protected PerspexObject InheritanceParent
{
get
@ -210,8 +213,8 @@ namespace Perspex
set
{
BindingMode mode = (binding.Mode == BindingMode.Default) ?
binding.Property.DefaultBindingMode :
BindingMode mode = (binding.Mode == BindingMode.Default) ?
binding.Property.DefaultBindingMode :
binding.Mode;
Binding sourceBinding = value as Binding;
@ -272,7 +275,7 @@ namespace Perspex
/// <param name="type">The type.</param>
/// <param name="property">The property.</param>
/// <remarks>
/// You won't usually want to call this method directly, instead use the
/// You won't usually want to call this method directly, instead use the
/// <see cref="PerspexProperty.Register"/> method.
/// </remarks>
public static void Register(Type type, PerspexProperty property)
@ -301,7 +304,7 @@ namespace Perspex
public void ClearValue(PerspexProperty property)
{
Contract.Requires<NullReferenceException>(property != null);
this.SetValue(property, PerspexProperty.UnsetValue);
}
@ -333,7 +336,7 @@ namespace Perspex
{
this.PropertyChanged -= handler;
});
},
},
this.GetObservableDescription(property));
}
@ -353,9 +356,10 @@ namespace Perspex
/// <summary>
/// Gets an observable for a <see cref="PerspexProperty"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="property"></param>
/// <returns></returns>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <returns>An observable which when subscribed pushes the old and new values of the
/// property each time it is changed.</returns>
public IObservable<Tuple<T, T>> GetObservableWithHistory<T>(PerspexProperty<T> property)
{
return new PerspexObservable<Tuple<T, T>>(
@ -375,7 +379,7 @@ namespace Perspex
{
this.PropertyChanged -= handler;
});
},
},
this.GetObservableDescription(property));
}
@ -412,6 +416,7 @@ namespace Perspex
/// <summary>
/// Gets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
public T GetValue<T>(PerspexProperty<T> property)
@ -493,8 +498,8 @@ namespace Perspex
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
public void SetValue(
PerspexProperty property,
object value,
PerspexProperty property,
object value,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
@ -530,8 +535,8 @@ namespace Perspex
}
this.propertyLog.Verbose(
"Set {Property} to {$Value} with priority {Priority}",
property,
"Set {Property} to {$Value} with priority {Priority}",
property,
value,
priority);
v.SetDirectValue(value, (int)priority);
@ -545,8 +550,8 @@ namespace Perspex
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
public void SetValue<T>(
PerspexProperty<T> property,
T value,
PerspexProperty<T> property,
T value,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
@ -557,7 +562,6 @@ namespace Perspex
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
@ -589,8 +593,8 @@ namespace Perspex
}
this.propertyLog.Verbose(
"Bound {Property} to {Binding} with priority {Priority}",
property,
"Bound {Property} to {Binding} with priority {Priority}",
property,
source,
priority);
@ -608,8 +612,8 @@ namespace Perspex
/// A disposable which can be used to terminate the binding.
/// </returns>
public IDisposable Bind<T>(
PerspexProperty<T> property,
IObservable<T> source,
PerspexProperty<T> property,
IObservable<T> source,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
@ -631,8 +635,8 @@ namespace Perspex
/// The binding is first carried out from <paramref name="source"/> to this.
/// </remarks>
public IDisposable BindTwoWay(
PerspexProperty property,
PerspexObject source,
PerspexProperty property,
PerspexObject source,
PerspexProperty sourceProperty,
BindingPriority priority = BindingPriority.LocalValue)
{
@ -782,17 +786,17 @@ namespace Perspex
/// <param name="newValue">The new property value.</param>
/// <param name="priority">The priority of the binding that produced the value.</param>
private void RaisePropertyChanged(
PerspexProperty property,
object oldValue,
object newValue,
PerspexProperty property,
object oldValue,
object newValue,
BindingPriority priority)
{
Contract.Requires<NullReferenceException>(property != null);
PerspexPropertyChangedEventArgs e = new PerspexPropertyChangedEventArgs(
this,
property,
oldValue,
this,
property,
oldValue,
newValue,
priority);

193
Perspex.Base/PerspexProperty.cs

@ -22,6 +22,7 @@ namespace Perspex
/// <summary>
/// Represents an unset property value.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields must be private", Justification = "It's readonly")]
public static readonly object UnsetValue = new Unset();
/// <summary>
@ -49,6 +50,7 @@ namespace Perspex
/// <param name="inherits">Whether the property inherits its value.</param>
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
/// <param name="coerce">A coercion function.</param>
/// <param name="isAttached">Whether the property is an attached property.</param>
public PerspexProperty(
string name,
Type valueType,
@ -76,37 +78,57 @@ namespace Perspex
/// <summary>
/// Gets the name of the property.
/// </summary>
/// <value>
/// The name of the property.
/// </value>
public string Name { get; }
/// <summary>
/// Gets the type of the property's value.
/// </summary>
/// <value>
/// The type of the property's value.
/// </value>
public Type PropertyType { get; }
/// <summary>
/// Gets the type of the class that registers the property.
/// </summary>
/// <value>
/// The type of the class that registers the property.
/// </value>
public Type OwnerType { get; }
/// <summary>
/// Gets a value indicating whether the property inherits its value.
/// </summary>
/// <value>
/// A value indicating whether the property inherits its value.
/// </value>
public bool Inherits { get; }
/// <summary>
/// Gets the default binding mode for the property.
/// </summary>
/// <returns></returns>
/// <value>
/// The default binding mode for the property.
/// </value>
public BindingMode DefaultBindingMode { get; }
/// <summary>
/// Gets the property's coerce function.
/// </summary>
/// <value>
/// The property's coerce function.
/// </value>
public Func<PerspexObject, object, object> Coerce { get; }
/// <summary>
/// Gets a value indicating whether this is an attached property.
/// </summary>
/// <value>
/// A value indicating whether this is an attached property.
/// </value>
public bool IsAttached { get; }
/// <summary>
@ -115,24 +137,62 @@ namespace Perspex
/// </summary>
/// <remarks>
/// This observable is fired each time a new <see cref="PerspexObject"/> is constructed
/// for all properties registered on the object's type. The default value of the property
/// for the object is passed in the args' NewValue (OldValue will always be
/// for all properties registered on the object's type. The default value of the property
/// for the object is passed in the args' NewValue (OldValue will always be
/// <see cref="UnsetValue"/>.
/// </remarks>
/// <value>
/// An observable that is fired when this property is initialized on a new
/// <see cref="PerspexObject"/> instance.
/// </value>
public IObservable<PerspexPropertyChangedEventArgs> Initialized
{
get { return this.initialized; }
}
/// <summary>
/// Gets an observable that is fired when this property changes on any
/// Gets an observable that is fired when this property changes on any
/// <see cref="PerspexObject"/> instance.
/// </summary>
/// <value>
/// An observable that is fired when this property changes on any
/// <see cref="PerspexObject"/> instance.
/// </value>
public IObservable<PerspexPropertyChangedEventArgs> Changed
{
get { return this.changed; }
}
/// <summary>
/// Provides access to a property's binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="Binding"/> describing the binding.</returns>
public static Binding operator !(PerspexProperty property)
{
return new Binding
{
Priority = BindingPriority.LocalValue,
Property = property,
};
}
/// <summary>
/// Provides access to a property's template binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="Binding"/> describing the binding.</returns>
public static Binding operator ~(PerspexProperty property)
{
return new Binding
{
Priority = BindingPriority.TemplatedParent,
Property = property,
};
}
/// <summary>
/// Registers a <see cref="PerspexProperty"/>.
/// </summary>
@ -240,37 +300,7 @@ namespace Perspex
}
/// <summary>
/// Provides access to a property's binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="Binding"/> describing the binding.</returns>
public static Binding operator !(PerspexProperty property)
{
return new Binding
{
Priority = BindingPriority.LocalValue,
Property = property,
};
}
/// <summary>
/// Provides access to a property's template binding via the <see cref="PerspexObject"/>
/// indexer.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>A <see cref="Binding"/> describing the binding.</returns>
public static Binding operator ~(PerspexProperty property)
{
return new Binding
{
Priority = BindingPriority.TemplatedParent,
Property = property,
};
}
/// <summary>
/// Returns a binding accessor that can be passed to <see cref="PerspexObject"/>'s []
/// Returns a binding accessor that can be passed to <see cref="PerspexObject"/>'s []
/// operator to initiate a binding.
/// </summary>
/// <returns>A <see cref="Binding"/>.</returns>
@ -309,6 +339,11 @@ namespace Perspex
return this.defaultValues[this.OwnerType];
}
/// <summary>
/// Checks whether the <paramref name="value"/> is valid for the property.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>True if the value is valid, otherwise false.</returns>
public bool IsValidValue(object value)
{
if (value == UnsetValue)
@ -342,96 +377,46 @@ namespace Perspex
this.defaultValues.Add(type, defaultValue);
}
/// <summary>
/// Gets the string representation of the property.
/// </summary>
/// <returns>The property's string representation.</returns>
public override string ToString()
{
return this.Name;
}
/// <summary>
/// Notifies the <see cref="Initialized"/> observable.
/// </summary>
/// <param name="e">The observable arguments.</param>
internal void NotifyInitialized(PerspexPropertyChangedEventArgs e)
{
this.initialized.OnNext(e);
}
/// <summary>
/// Notifies the <see cref="Changed"/> observable.
/// </summary>
/// <param name="e">The observable arguments.</param>
internal void NotifyChanged(PerspexPropertyChangedEventArgs e)
{
this.changed.OnNext(e);
}
/// <summary>
/// Class representing the <see cref="UnsetValue"/>.
/// </summary>
private class Unset
{
/// <summary>
/// Returns the string representation of the <see cref="UnsetValue"/>.
/// </summary>
/// <returns>The string "(unset)".</returns>
public override string ToString()
{
return "(unset)";
}
}
}
/// <summary>
/// A typed perspex property.
/// </summary>
public class PerspexProperty<TValue> : PerspexProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="PerspexProperty"/> class.
/// </summary>
/// <param name="name">The name of the property.</param>
/// <param name="ownerType">The type of the class that registers the property.</param>
/// <param name="defaultValue">The default value of the property.</param>
/// <param name="inherits">Whether the property inherits its value.</param>
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
/// <param name="coerce">A coercion function.</param>
/// <param name="isAttached">Whether the property is an attached property.</param>
public PerspexProperty(
string name,
Type ownerType,
TValue defaultValue = default(TValue),
bool inherits = false,
BindingMode defaultBindingMode = BindingMode.Default,
Func<PerspexObject, TValue, TValue> coerce = null,
bool isAttached = false)
: base(
name,
typeof(TValue),
ownerType,
defaultValue,
inherits,
defaultBindingMode,
Convert(coerce),
isAttached)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(ownerType != null);
}
/// <summary>
/// Registers the property on another type.
/// </summary>
/// <typeparam name="TOwner">The type of the additional owner.</typeparam>
/// <returns>The property.</returns>
public PerspexProperty<TValue> AddOwner<TOwner>()
{
PerspexObject.Register(typeof(TOwner), this);
return this;
}
/// <summary>
/// Gets the default value for the property on the specified type.
/// </summary>
/// <typeparam name="T">The type.</typeparam>
/// <returns>The default value.</returns>
public TValue GetDefaultValue<T>()
{
return (TValue)this.GetDefaultValue(typeof(T));
}
/// <summary>
/// Converts from a typed coercion function to an untyped.
/// </summary>
/// <param name="f">The typed coercion function.</param>
/// <returns>Te untyped coercion function.</returns>
private static Func<PerspexObject, object, object> Convert(Func<PerspexObject, TValue, TValue> f)
{
return f != null ? (o, v) => f(o, (TValue)v) : (Func<PerspexObject, object, object>)null;
}
}
}

22
Perspex.Base/PerspexPropertyChangedEventArgs.cs

@ -11,6 +11,14 @@ namespace Perspex
/// </summary>
public class PerspexPropertyChangedEventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="PerspexPropertyChangedEventArgs"/> class.
/// </summary>
/// <param name="sender">The object that the property changed on.</param>
/// <param name="property">The property that changed.</param>
/// <param name="oldValue">The old value of the property.</param>
/// <param name="newValue">The new value of the property.</param>
/// <param name="priority">The priority of the binding that produced the value.</param>
public PerspexPropertyChangedEventArgs(
PerspexObject sender,
PerspexProperty property,
@ -28,27 +36,39 @@ namespace Perspex
/// <summary>
/// Gets the <see cref="PerspexObject"/> that the property changed on.
/// </summary>
/// <returns></returns>
/// <value>The sender object.</value>
public PerspexObject Sender { get; private set; }
/// <summary>
/// Gets the property that changed.
/// </summary>
/// <value>
/// The property that changed.
/// </value>
public PerspexProperty Property { get; private set; }
/// <summary>
/// Gets the old value of the property.
/// </summary>
/// <value>
/// The old value of the property.
/// </value>
public object OldValue { get; private set; }
/// <summary>
/// Gets the new value of the property.
/// </summary>
/// <value>
/// The new value of the property.
/// </value>
public object NewValue { get; private set; }
/// <summary>
/// Gets the priority of the binding that produced the value.
/// </summary>
/// <value>
/// The priority of the binding that produced the value.
/// </value>
public BindingPriority Priority { get; private set; }
}
}

80
Perspex.Base/PerspexProperty`1.cs

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="PerspexProperty`1.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
/// <summary>
/// A typed perspex property.
/// </summary>
/// <typeparam name="TValue">The value type of the property.</typeparam>
public class PerspexProperty<TValue> : PerspexProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="PerspexProperty{TValue}"/> class.
/// </summary>
/// <param name="name">The name of the property.</param>
/// <param name="ownerType">The type of the class that registers the property.</param>
/// <param name="defaultValue">The default value of the property.</param>
/// <param name="inherits">Whether the property inherits its value.</param>
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
/// <param name="coerce">A coercion function.</param>
/// <param name="isAttached">Whether the property is an attached property.</param>
public PerspexProperty(
string name,
Type ownerType,
TValue defaultValue = default(TValue),
bool inherits = false,
BindingMode defaultBindingMode = BindingMode.Default,
Func<PerspexObject, TValue, TValue> coerce = null,
bool isAttached = false)
: base(
name,
typeof(TValue),
ownerType,
defaultValue,
inherits,
defaultBindingMode,
Convert(coerce),
isAttached)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(ownerType != null);
}
/// <summary>
/// Registers the property on another type.
/// </summary>
/// <typeparam name="TOwner">The type of the additional owner.</typeparam>
/// <returns>The property.</returns>
public PerspexProperty<TValue> AddOwner<TOwner>()
{
PerspexObject.Register(typeof(TOwner), this);
return this;
}
/// <summary>
/// Gets the default value for the property on the specified type.
/// </summary>
/// <typeparam name="T">The type.</typeparam>
/// <returns>The default value.</returns>
public TValue GetDefaultValue<T>()
{
return (TValue)this.GetDefaultValue(typeof(T));
}
/// <summary>
/// Converts from a typed coercion function to an untyped.
/// </summary>
/// <param name="f">The typed coercion function.</param>
/// <returns>Te untyped coercion function.</returns>
private static Func<PerspexObject, object, object> Convert(Func<PerspexObject, TValue, TValue> f)
{
return f != null ? (o, v) => f(o, (TValue)v) : (Func<PerspexObject, object, object>)null;
}
}
}
Loading…
Cancel
Save