Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CreateNewInstanceCommand.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 using SiliconStudio.Core.Reflection;
6 
7 namespace SiliconStudio.Quantum.Commands
8 {
10  {
11  /// <inheritdoc/>
12  public override string Name { get { return "CreateNewInstance"; } }
13 
14  /// <inheritdoc/>
15  public override CombineMode CombineMode { get { return CombineMode.CombineOnlyForAll; } }
16 
17  /// <inheritdoc/>
18  public override bool CanAttach(ITypeDescriptor typeDescriptor, MemberDescriptorBase memberDescriptor)
19  {
20  return (typeDescriptor.Type.IsNullable() && Nullable.GetUnderlyingType(typeDescriptor.Type).IsStruct())
21  || (typeDescriptor.Type.IsAbstract && !(typeDescriptor is CollectionDescriptor) && !(typeDescriptor is DictionaryDescriptor));
22  }
23 
24  /// <inheritdoc/>
25  protected override object ModifyValue(object currentValue, ITypeDescriptor descriptor, object parameter)
26  {
27  return parameter != null ? Activator.CreateInstance((Type)parameter) : currentValue;
28  }
29  }
30 }
Provides a descriptor for a System.Collections.ICollection.
Type Type
Gets the type described by this instance.
Provides a descriptor for a System.Collections.IDictionary.
CombineMode
An enum that describes what to do with a node or a command when combining view models.
Definition: CombineMode.cs:8
Provides access members of a type.
override object ModifyValue(object currentValue, ITypeDescriptor descriptor, object parameter)
override bool CanAttach(ITypeDescriptor typeDescriptor, MemberDescriptorBase memberDescriptor)
Indicates whether this command can be attached to an object or a member with the given descriptors...
Base class for IMemberDescriptor for a MemberInfo