Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ObjectInvalidationMetadata.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Core
6 {
7  /// <summary>
8  /// Delegate ObjectInvalidatorCallback used by <see cref="ObjectInvalidationMetadata"/>.
9  /// </summary>
10  /// <param name="propertyOwner">The owner of the property that changed.</param>
11  /// <param name="propertyKey">The key of the property that changed.</param>
12  /// <param name="propertyOldValue">The value of the property before its modification.</param>
13  public delegate void ObjectInvalidationCallback<T>(object propertyOwner, PropertyKey<T> propertyKey, T propertyOldValue);
14 
15  public delegate void ObjectInvalidationRefCallback<T>(object propertyOwner, PropertyKey<T> propertyKey, ref T propertyOldValue);
16 
18  {
19  public static ObjectInvalidationMetadata New<T>(ObjectInvalidationCallback<T> invalidationCallback)
20  {
21  return new ObjectInvalidationMetadata<T>(invalidationCallback);
22  }
23 
24  public static ObjectInvalidationMetadata NewRef<T>(ObjectInvalidationRefCallback<T> invalidationRefCallback)
25  {
26  return new ObjectInvalidationMetadata<T>(invalidationRefCallback);
27  }
28 
29  public abstract void Invalidate(object propertyOwner, PropertyKey propertyKey, object propertyOldValue);
30  }
31 
32  /// <summary>
33  /// Metadata used to invalidate an object state after a property value modification.
34  /// </summary>
36  {
37  private readonly ObjectInvalidationCallback<T> objectInvalidationCallback;
38  private readonly ObjectInvalidationRefCallback<T> objectInvalidationRefCallback;
39 
40  /// <summary>
41  /// Initializes a new instance of the <see cref="ValidateValueMetadata"/> class.
42  /// </summary>
43  /// <param name="invalidationCallback">The object invalidation callback.</param>
44  /// <exception cref="System.ArgumentNullException">Parameter <paramref name="invalidationCallback"/> is null.</exception>
46  {
47  if (invalidationCallback == null) throw new ArgumentNullException("invalidationCallback");
48  objectInvalidationCallback = invalidationCallback;
49  }
50 
51  /// <summary>
52  /// Initializes a new instance of the <see cref="ValidateValueMetadata"/> class.
53  /// </summary>
54  /// <param name="invalidationRefCallback">The object invalidation callback.</param>
55  /// <exception cref="System.ArgumentNullException">Parameter <paramref name="invalidationRefCallback"/> is null.</exception>
57  {
58  if (invalidationRefCallback == null) throw new ArgumentNullException("invalidationRefCallback");
59  objectInvalidationRefCallback = invalidationRefCallback;
60  }
61 
62  public void Invalidate(object propertyOwner, PropertyKey<T> propertyKey, ref T propertyOldValue)
63  {
64  if (objectInvalidationCallback != null)
65  objectInvalidationCallback(propertyOwner, propertyKey, propertyOldValue);
66  else
67  objectInvalidationRefCallback(propertyOwner, propertyKey, ref propertyOldValue);
68  }
69 
70  public override void Invalidate(object propertyOwner, PropertyKey propertyKey, object propertyOldValue)
71  {
72  var propertyOldValueT = (T)propertyOldValue;
73 
74  if (objectInvalidationCallback != null)
75  objectInvalidationCallback(propertyOwner, (PropertyKey<T>)propertyKey, propertyOldValueT);
76  else
77  objectInvalidationRefCallback(propertyOwner, (PropertyKey<T>)propertyKey, ref propertyOldValueT);
78  }
79  }
80 }
delegate void ObjectInvalidationRefCallback< T >(object propertyOwner, PropertyKey< T > propertyKey, ref T propertyOldValue)
ObjectInvalidationMetadata(ObjectInvalidationCallback< T > invalidationCallback)
Initializes a new instance of the ValidateValueMetadata class.
override void Invalidate(object propertyOwner, PropertyKey propertyKey, object propertyOldValue)
delegate void ObjectInvalidationCallback< T >(object propertyOwner, PropertyKey< T > propertyKey, T propertyOldValue)
Delegate ObjectInvalidatorCallback used by ObjectInvalidationMetadata.
A class that represents a typed tag propety.
Definition: PropertyKey.cs:138
Specifies metadata for an PropertyKey.
ObjectInvalidationMetadata(ObjectInvalidationRefCallback< T > invalidationRefCallback)
Initializes a new instance of the ValidateValueMetadata class.
Metadata used to invalidate an object state after a property value modification.
A class that represents a tag propety.
Definition: PropertyKey.cs:17
void Invalidate(object propertyOwner, PropertyKey< T > propertyKey, ref T propertyOldValue)