Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PrimitiveDescriptor.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 primitive (bool, char, sbyte, byte, int, uint, long, ulong, float, double, decimal, string, DateTime).
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 PrimitiveDescriptor(ITypeDescriptorFactory factory, Type type) : base(factory, type)
22  {
23  if (!IsPrimitive(type))
24  throw new ArgumentException("Type [{0}] is not a primitive");
25 
26  Category = DescriptorCategory.Primitive;
27  }
28 
29  /// <summary>
30  /// Determines whether the specified type is a primitive.
31  /// </summary>
32  /// <param name="type">The type.</param>
33  /// <returns><c>true</c> if the specified type is primitive; otherwise, <c>false</c>.</returns>
34  public static bool IsPrimitive(Type type)
35  {
36  switch (Type.GetTypeCode(type))
37  {
38  case TypeCode.Object:
39  case TypeCode.Empty:
40  return type == typeof(string) || type == typeof(TimeSpan) || type == typeof(DateTime);
41  }
42  return true;
43  }
44 
45  protected override System.Collections.Generic.List<IMemberDescriptor> PrepareMembers()
46  {
47  return EmptyMembers;
48  }
49  }
50 }
Default implementation of a ITypeDescriptor.
Describes a descriptor for a primitive (bool, char, sbyte, byte, int, uint, long, ulong...
override System.Collections.Generic.List< IMemberDescriptor > PrepareMembers()
PrimitiveDescriptor(ITypeDescriptorFactory factory, Type type)
Initializes a new instance of the ObjectDescriptor class.
static bool IsPrimitive(Type type)
Determines whether the specified type is a primitive.
A factory to create an instance of a ITypeDescriptor