Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NullableDescriptor.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 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Core.Reflection
7 {
8  /// <summary>
9  /// Describes a descriptor for a nullable type <see cref="Nullable{T}"/>.
10  /// </summary>
12  {
13  private static readonly List<IMemberDescriptor> EmptyMembers = new List<IMemberDescriptor>();
14 
15  /// <summary>
16  /// Initializes a new instance of the <see cref="ObjectDescriptor" /> class.
17  /// </summary>
18  /// <param name="factory">The factory.</param>
19  /// <param name="type">The type.</param>
20  /// <exception cref="System.ArgumentException">Type [{0}] is not a primitive</exception>
21  public NullableDescriptor(ITypeDescriptorFactory factory, Type type)
22  : base(factory, type)
23  {
24  if (!IsNullable(type))
25  throw new ArgumentException("Type [{0}] is not a primitive");
26 
27  Category = DescriptorCategory.Nullable;
28  UnderlyingType = Nullable.GetUnderlyingType(type);
29  UnderlyingDescriptor = Factory.Find(UnderlyingType);
30  }
31 
32  /// <summary>
33  /// Gets the type underlying type T of the nullable <see cref="Nullable{T}"/>
34  /// </summary>
35  /// <value>The type of the element.</value>
36  public Type UnderlyingType { get; private set; }
37 
38  /// <summary>
39  /// Gets the type underlying type T of the nullable <see cref="Nullable{T}"/>
40  /// </summary>
41  /// <value>The type of the element.</value>
42  public ITypeDescriptor UnderlyingDescriptor { get; private set; }
43 
44  /// <summary>
45  /// Determines whether the specified type is nullable.
46  /// </summary>
47  /// <param name="type">The type.</param>
48  /// <returns><c>true</c> if the specified type is nullable; otherwise, <c>false</c>.</returns>
49  public static bool IsNullable(Type type)
50  {
51  return type.IsNullable();
52  }
53 
54  protected override System.Collections.Generic.List<IMemberDescriptor> PrepareMembers()
55  {
56  return EmptyMembers;
57  }
58  }
59 }
override System.Collections.Generic.List< IMemberDescriptor > PrepareMembers()
Default implementation of a ITypeDescriptor.
static bool IsNullable(Type type)
Determines whether the specified type is nullable.
NullableDescriptor(ITypeDescriptorFactory factory, Type type)
Initializes a new instance of the ObjectDescriptor class.
Describes a descriptor for a nullable type Nullable{T}.
Provides access members of a type.
A factory to create an instance of a ITypeDescriptor