protected EntryProperty GetEntryProperty(bool createIfN = false)
		{
			var result = Entry.GetProperty(PropertyName);
			if (result == null && createIfN)
			{
				result = new EntryProperty(PropertyName);
				Entry.Properties.Add(result);
			}
			return result;
		}
Esempio n. 2
0
 public EntryProperty GetPropertyAndCreateIfN(string name)
 {
     var result = GetProperty(name);
     if (result == null)
     {
         result = new EntryProperty(name);
         Properties.Add(result);
     }
     return result;
 }
	    /// <summary>
	    /// Initializes a new instance of the PropertyItemViewModel class.
	    /// </summary>
	    public PropertyItemViewModel(DescriptorProperty descriptorProperty, EntryItemViewModel parent,
	        ManifestEditorViewModel editor)
	        : base(parent)
	    {
	        if (descriptorProperty == null)
	            throw new ArgumentNullException("descriptorProperty", "descriptorProperty is null.");
	        if (parent == null)
	            throw new ArgumentNullException("parent", "parent is null.");
	        if (editor == null)
	            throw new ArgumentNullException("editor", "editor is null.");

	        var referencedType = descriptorProperty.ReferencedType;
	        if (!descriptorProperty.AsContainment || string.IsNullOrWhiteSpace(referencedType))
	        {
	            throw new ArgumentException("Invalid descriptor property");
	        }

	        _descriptorProperty = descriptorProperty;
	        _editor = editor;
	        TreeItemLabel = descriptorProperty.Label;

	        var childDescriptors = new List<Descriptor>(
	            _editor.AllDescriptors.Values.Where(
	                d => !d.IsVirtual && (
	                    d.Type == referencedType
	                    || d.Supertypes.Contains(referencedType)
	                    || d.Interfaces.Contains(referencedType))));

	        _entryProperty = parent.Entry.GetPropertyAndCreateIfN(descriptorProperty.Name);

	        IsExpanded = true;

	        MenuItems = new List<MenuItemViewModel>
	        {
	            new MenuItemViewModel(Properties.Resources.EDITOR_NEW_CI, null, new List<MenuItemViewModel>(
	                from descriptor in childDescriptors
	                select new MenuItemViewModel(descriptor.Type, new DelegateCommand(() => DoAdd(descriptor)), null)
	                ))
	        };
	    }