Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TypeMatchTemplateProvider.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.Presentation.Quantum.View
6 {
7  /// <summary>
8  /// An implementation of the <see cref="ObservableNodeTemplateProvider"/> that matches <see cref="IObservableNode"/> of a specific type.
9  /// </summary>
11  {
12  /// <summary>
13  /// Initializes a new instance of the <see cref="TypeMatchTemplateProvider"/> class.
14  /// </summary>
16  {
17  AcceptNullable = true;
18  }
19 
20  /// <summary>
21  /// Gets or sets the <see cref="Type"/> to match. This provider will accept any node that has either a <see cref="IObservableNode.Type"/>
22  /// or a <see cref="IObservableNode.Value"/> with a type that is assignable to the type represented in this property.
23  /// </summary>
24  public Type Type { get; set; }
25 
26  /// <summary>
27  /// Gets or sets whether to match nullable instances of the <see cref="Type"/>, when it represents a value type.
28  /// </summary>
29  public bool AcceptNullable { get; set; }
30 
31  /// <inheritdoc/>
32  public override string Name { get { return Type.Name; } }
33 
34  /// <inheritdoc/>
35  public override bool MatchNode(IObservableNode node)
36  {
37  if (Type == null)
38  return false;
39 
40  if (MatchType(node, Type))
41  return true;
42 
43  if (AcceptNullable && Type.IsValueType)
44  {
45  var nullableType = typeof(Nullable<>).MakeGenericType(new[] { Type });
46  return MatchType(node, nullableType);
47  }
48 
49  return false;
50  }
51  }
52 }
An implementation of the ObservableNodeTemplateProvider that matches IObservableNode of a specific ty...
A base class for implementations of ITemplateProvider that can provide templates for IObservableNode ...
override bool MatchNode(IObservableNode node)
Indicates whether this instance of ITemplateProvider can provide a template for the given IObservable...
TypeMatchTemplateProvider()
Initializes a new instance of the TypeMatchTemplateProvider class.