5 using SiliconStudio.ActionStack;
6 using SiliconStudio.Core.Reflection;
7 using SiliconStudio.Quantum.Attributes;
20 public string Name {
get {
return "AddNewItem"; } }
28 if (memberDescriptor != null)
30 var attrib = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<
SealedCollectionAttribute>(memberDescriptor.MemberInfo);
31 if (attrib != null && attrib.CollectionSealed)
36 if (collectionDescriptor == null)
39 var elementType = collectionDescriptor.ElementType;
40 return collectionDescriptor.HasAdd && (!elementType.IsClass || elementType.GetConstructor(Type.EmptyTypes) != null || elementType.IsAbstract || elementType.IsNullable() || elementType == typeof(
string));
47 if (collectionDescriptor.ElementType.IsAbstract || collectionDescriptor.ElementType.IsNullable())
49 undoToken =
new UndoToken(
true, collectionDescriptor.GetCollectionCount(currentValue));
50 collectionDescriptor.Add(currentValue, parameter);
52 else if (collectionDescriptor.ElementType == typeof(
string))
54 undoToken =
new UndoToken(
true, collectionDescriptor.GetCollectionCount(currentValue));
55 collectionDescriptor.Add(currentValue, parameter ??
"");
59 var newItem = Activator.CreateInstance(collectionDescriptor.ElementType);
60 undoToken =
new UndoToken(
true, collectionDescriptor.GetCollectionCount(currentValue));
61 collectionDescriptor.Add(currentValue, parameter ?? newItem);
71 collectionDescriptor.RemoveAt(currentValue, index);
Provides a descriptor for a System.Collections.ICollection.
object Invoke(object currentValue, ITypeDescriptor descriptor, object parameter, out UndoToken undoToken)
Invokes the node command. The current value of the associated object or member.The type descriptor of...
This command construct a new item and add it to the list contained in the value of the node...
CombineMode
An enum that describes what to do with a node or a command when combining view models.
Base interface for node commands.
object Undo(object currentValue, ITypeDescriptor descriptor, UndoToken undoToken)
Undoes an invoke of the node command. The current value of the associated object or member...
bool CanAttach(ITypeDescriptor typeDescriptor, MemberDescriptorBase memberDescriptor)
Indicates whether this command can be attached to an object or a member with the given descriptors...
Provides access members of a type.
object TokenValue
Gets a user-defined object hosted by the token that should store all information needed to undo a com...
Base class for IMemberDescriptor for a MemberInfo
Represents a token that stores an unique identifier and an object. This token should be generated by ...