Browse Source

Use correct Contract exception.

pull/223/head
Steven Kirk 11 years ago
parent
commit
00613b2d67
  1. 4
      src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs
  2. 28
      src/Perspex.Base/PerspexObject.cs
  3. 34
      src/Perspex.Base/PerspexProperty.cs
  4. 2
      src/Perspex.Base/Utilities/TypeUtilities.cs
  5. 2
      src/Perspex.Input/InputExtensions.cs
  6. 16
      src/Perspex.Interactivity/Interactive.cs
  7. 14
      src/Perspex.Interactivity/RoutedEvent.cs
  8. 8
      src/Perspex.SceneGraph/VisualTree/VisualExtensions.cs
  9. 2
      src/Perspex.Styling/LogicalTree/LogicalExtensions.cs
  10. 2
      src/Perspex.Styling/Styling/StyleBinding.cs

4
src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs

@ -24,8 +24,8 @@ namespace Perspex.Cairo.Media
TextAlignment textAlignment,
FontWeight fontWeight)
{
Contract.Requires<NullReferenceException>(context != null);
Contract.Requires<NullReferenceException> (text != null);
Contract.Requires<ArgumentNullException>(context != null);
Contract.Requires<ArgumentNullException> (text != null);
Layout = new Pango.Layout(context);
_text = text;
Layout.SetText(text);

28
src/Perspex.Base/PerspexObject.cs

@ -215,7 +215,7 @@ namespace Perspex
/// <returns>A collection of <see cref="PerspexProperty"/> definitions.</returns>
public static IEnumerable<PerspexProperty> GetRegisteredProperties(Type type)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<ArgumentNullException>(type != null);
TypeInfo i = type.GetTypeInfo();
@ -263,8 +263,8 @@ namespace Perspex
/// </remarks>
public static void Register(Type type, PerspexProperty property)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(type != null);
Contract.Requires<ArgumentNullException>(property != null);
List<PerspexProperty> list;
@ -300,7 +300,7 @@ namespace Perspex
/// <param name="property">The property.</param>
public void ClearValue(PerspexProperty property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
SetValue(property, PerspexProperty.UnsetValue);
}
@ -312,7 +312,7 @@ namespace Perspex
/// <returns>An observable.</returns>
public IObservable<object> GetObservable(PerspexProperty property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
return new PerspexObservable<object>(
observer =>
@ -345,7 +345,7 @@ namespace Perspex
/// <returns>An observable.</returns>
public IObservable<T> GetObservable<T>(PerspexProperty<T> property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
return GetObservable((PerspexProperty)property).Cast<T>();
}
@ -387,7 +387,7 @@ namespace Perspex
/// <returns>The value.</returns>
public object GetValue(PerspexProperty property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -425,7 +425,7 @@ namespace Perspex
/// <returns>The value.</returns>
public T GetValue<T>(PerspexProperty<T> property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -455,7 +455,7 @@ namespace Perspex
/// <returns>True if the property is set, otherwise false.</returns>
public bool IsSet(PerspexProperty property)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
return _values.ContainsKey(property);
}
@ -481,7 +481,7 @@ namespace Perspex
object value,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -546,7 +546,7 @@ namespace Perspex
T value,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -579,7 +579,7 @@ namespace Perspex
IObservable<object> source,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -638,7 +638,7 @@ namespace Perspex
IObservable<T> source,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
if (property.IsDirect)
{
@ -741,7 +741,7 @@ namespace Perspex
object newValue,
BindingPriority priority)
{
Contract.Requires<NullReferenceException>(property != null);
Contract.Requires<ArgumentNullException>(property != null);
PerspexPropertyChangedEventArgs e = new PerspexPropertyChangedEventArgs(
this,

34
src/Perspex.Base/PerspexProperty.cs

@ -74,9 +74,9 @@ namespace Perspex
Func<PerspexObject, object, object> validate = null,
bool isAttached = false)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(valueType != null);
Contract.Requires<NullReferenceException>(ownerType != null);
Contract.Requires<ArgumentNullException>(name != null);
Contract.Requires<ArgumentNullException>(valueType != null);
Contract.Requires<ArgumentNullException>(ownerType != null);
if (name.Contains("."))
{
@ -113,10 +113,10 @@ namespace Perspex
Func<PerspexObject, object> getter,
Action<PerspexObject, object> setter)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(valueType != null);
Contract.Requires<NullReferenceException>(ownerType != null);
Contract.Requires<NullReferenceException>(getter != null);
Contract.Requires<ArgumentNullException>(name != null);
Contract.Requires<ArgumentNullException>(valueType != null);
Contract.Requires<ArgumentNullException>(ownerType != null);
Contract.Requires<ArgumentNullException>(getter != null);
if (name.Contains("."))
{
@ -143,8 +143,8 @@ namespace Perspex
Func<PerspexObject, object> getter,
Action<PerspexObject, object> setter)
{
Contract.Requires<NullReferenceException>(source != null);
Contract.Requires<NullReferenceException>(getter != null);
Contract.Requires<ArgumentNullException>(source != null);
Contract.Requires<ArgumentNullException>(getter != null);
if (!source.IsDirect)
{
@ -321,7 +321,7 @@ namespace Perspex
Func<TOwner, TValue, TValue> validate = null)
where TOwner : PerspexObject
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
PerspexProperty<TValue> result = new PerspexProperty<TValue>(
name,
@ -352,7 +352,7 @@ namespace Perspex
Action<TOwner, TValue> setter = null)
where TOwner : PerspexObject
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
PerspexProperty<TValue> result = new PerspexProperty<TValue>(
name,
@ -384,7 +384,7 @@ namespace Perspex
BindingMode defaultBindingMode = BindingMode.OneWay,
Func<PerspexObject, TValue, TValue> validate = null)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
PerspexProperty<TValue> result = new PerspexProperty<TValue>(
name,
@ -420,7 +420,7 @@ namespace Perspex
BindingMode defaultBindingMode = BindingMode.OneWay,
Func<PerspexObject, TValue, TValue> validate = null)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
PerspexProperty<TValue> result = new PerspexProperty<TValue>(
name,
@ -478,7 +478,7 @@ namespace Perspex
/// <returns>The default value.</returns>
public object GetDefaultValue(Type type)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<ArgumentNullException>(type != null);
while (type != null)
{
@ -504,7 +504,7 @@ namespace Perspex
/// </returns>
public Func<PerspexObject, object, object> GetValidationFunc(Type type)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<ArgumentNullException>(type != null);
while (type != null)
{
@ -548,7 +548,7 @@ namespace Perspex
/// <param name="defaultValue">The default value.</param>
public void OverrideDefaultValue(Type type, object defaultValue)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<ArgumentNullException>(type != null);
if (!TypeUtilities.TryCast(PropertyType, defaultValue, out defaultValue))
{
@ -574,7 +574,7 @@ namespace Perspex
/// <param name="validation">The validation function.</param>
public void OverrideValidation(Type type, Func<PerspexObject, object, object> validation)
{
Contract.Requires<NullReferenceException>(type != null);
Contract.Requires<ArgumentNullException>(type != null);
if (_validation.ContainsKey(type))
{

2
src/Perspex.Base/Utilities/TypeUtilities.cs

@ -35,7 +35,7 @@ namespace Perspex.Utilities
/// <returns>True if the cast was sucessful, otherwise false.</returns>
public static bool TryCast(Type to, object value, out object result)
{
Contract.Requires<NullReferenceException>(to != null);
Contract.Requires<ArgumentNullException>(to != null);
if (value == null)
{

2
src/Perspex.Input/InputExtensions.cs

@ -11,7 +11,7 @@ namespace Perspex.Input
{
public static IEnumerable<IInputElement> GetInputElementsAt(this IInputElement element, Point p)
{
Contract.Requires<NullReferenceException>(element != null);
Contract.Requires<ArgumentNullException>(element != null);
if (element.Bounds.Contains(p) &&
element.IsVisible &&

16
src/Perspex.Interactivity/Interactive.cs

@ -37,8 +37,8 @@ namespace Perspex.Interactivity
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
bool handledEventsToo = false)
{
Contract.Requires<NullReferenceException>(routedEvent != null);
Contract.Requires<NullReferenceException>(handler != null);
Contract.Requires<ArgumentNullException>(routedEvent != null);
Contract.Requires<ArgumentNullException>(handler != null);
List<EventSubscription> subscriptions;
@ -85,8 +85,8 @@ namespace Perspex.Interactivity
/// <param name="handler">The handler.</param>
public void RemoveHandler(RoutedEvent routedEvent, Delegate handler)
{
Contract.Requires<NullReferenceException>(routedEvent != null);
Contract.Requires<NullReferenceException>(handler != null);
Contract.Requires<ArgumentNullException>(routedEvent != null);
Contract.Requires<ArgumentNullException>(handler != null);
List<EventSubscription> subscriptions;
@ -114,7 +114,7 @@ namespace Perspex.Interactivity
/// <param name="e">The event args.</param>
public void RaiseEvent(RoutedEventArgs e)
{
Contract.Requires<NullReferenceException>(e != null);
Contract.Requires<ArgumentNullException>(e != null);
e.Source = e.Source ?? this;
@ -141,7 +141,7 @@ namespace Perspex.Interactivity
/// <param name="e">The event args.</param>
private void BubbleEvent(RoutedEventArgs e)
{
Contract.Requires<NullReferenceException>(e != null);
Contract.Requires<ArgumentNullException>(e != null);
e.Route = RoutingStrategies.Bubble;
@ -157,7 +157,7 @@ namespace Perspex.Interactivity
/// <param name="e">The event args.</param>
private void TunnelEvent(RoutedEventArgs e)
{
Contract.Requires<NullReferenceException>(e != null);
Contract.Requires<ArgumentNullException>(e != null);
e.Route = RoutingStrategies.Tunnel;
@ -173,7 +173,7 @@ namespace Perspex.Interactivity
/// <param name="e">The event args.</param>
private void RaiseEventImpl(RoutedEventArgs e)
{
Contract.Requires<NullReferenceException>(e != null);
Contract.Requires<ArgumentNullException>(e != null);
e.RoutedEvent.InvokeClassHandlers(this, e);

14
src/Perspex.Interactivity/RoutedEvent.cs

@ -26,9 +26,9 @@ namespace Perspex.Interactivity
Type eventArgsType,
Type ownerType)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(eventArgsType != null);
Contract.Requires<NullReferenceException>(ownerType != null);
Contract.Requires<ArgumentNullException>(name != null);
Contract.Requires<ArgumentNullException>(eventArgsType != null);
Contract.Requires<ArgumentNullException>(ownerType != null);
Contract.Requires<InvalidCastException>(typeof(RoutedEventArgs).GetTypeInfo().IsAssignableFrom(eventArgsType.GetTypeInfo()));
EventArgsType = eventArgsType;
@ -66,7 +66,7 @@ namespace Perspex.Interactivity
RoutingStrategies routingStrategy)
where TEventArgs : RoutedEventArgs
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
return new RoutedEvent<TEventArgs>(name, routingStrategy, typeof(TOwner));
}
@ -77,7 +77,7 @@ namespace Perspex.Interactivity
Type ownerType)
where TEventArgs : RoutedEventArgs
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<ArgumentNullException>(name != null);
return new RoutedEvent<TEventArgs>(name, routingStrategy, ownerType);
}
@ -117,8 +117,8 @@ namespace Perspex.Interactivity
public RoutedEvent(string name, RoutingStrategies routingStrategies, Type ownerType)
: base(name, routingStrategies, typeof(TEventArgs), ownerType)
{
Contract.Requires<NullReferenceException>(name != null);
Contract.Requires<NullReferenceException>(ownerType != null);
Contract.Requires<ArgumentNullException>(name != null);
Contract.Requires<ArgumentNullException>(ownerType != null);
}
public void AddClassHandler<TTarget>(

8
src/Perspex.SceneGraph/VisualTree/VisualExtensions.cs

@ -19,7 +19,7 @@ namespace Perspex.VisualTree
/// <returns>The visual's ancestors.</returns>
public static IEnumerable<IVisual> GetVisualAncestors(this IVisual visual)
{
Contract.Requires<NullReferenceException>(visual != null);
Contract.Requires<ArgumentNullException>(visual != null);
visual = visual.VisualParent;
@ -53,7 +53,7 @@ namespace Perspex.VisualTree
/// <returns>The visuals at the requested point.</returns>
public static IVisual GetVisualAt(this IVisual visual, Point p)
{
Contract.Requires<NullReferenceException>(visual != null);
Contract.Requires<ArgumentNullException>(visual != null);
return visual.GetVisualsAt(p).FirstOrDefault();
}
@ -66,7 +66,7 @@ namespace Perspex.VisualTree
/// <returns>The visuals at the requested point.</returns>
public static IEnumerable<IVisual> GetVisualsAt(this IVisual visual, Point p)
{
Contract.Requires<NullReferenceException>(visual != null);
Contract.Requires<ArgumentNullException>(visual != null);
if (visual.Bounds.Contains(p))
{
@ -162,7 +162,7 @@ namespace Perspex.VisualTree
/// </returns>
public static IVisual GetVisualRoot(this IVisual visual)
{
Contract.Requires<NullReferenceException>(visual != null);
Contract.Requires<ArgumentNullException>(visual != null);
var parent = visual.VisualParent;

2
src/Perspex.Styling/LogicalTree/LogicalExtensions.cs

@ -11,7 +11,7 @@ namespace Perspex.LogicalTree
{
public static IEnumerable<ILogical> GetLogicalAncestors(this ILogical logical)
{
Contract.Requires<NullReferenceException>(logical != null);
Contract.Requires<ArgumentNullException>(logical != null);
logical = logical.LogicalParent;

2
src/Perspex.Styling/Styling/StyleBinding.cs

@ -86,7 +86,7 @@ namespace Perspex.Styling
/// <returns>IDisposable object used to unsubscribe from the observable sequence.</returns>
protected override IDisposable SubscribeCore(IObserver<object> observer)
{
Contract.Requires<NullReferenceException>(observer != null);
Contract.Requires<ArgumentNullException>(observer != null);
if (Source == null)
{

Loading…
Cancel
Save