コード例 #1
0
        public DictionaryInspector()
        {
            AddElementCommand = new CRelayCommand((arg) =>
            {
                if (m_addKeyValue == null)
                {
                    LogUtility.Log("The dictionary {0}", PropertyInfo.Name);
                    return;
                }

                if (m_displayedList.Any(vm => SafeEquals(m_addKeyValue, vm.Key)))
                {
                    LogUtility.Log("The dictionary {0} already contains an element with a default key! You cannot add a new element as long as the default key exists.", PropertyInfo.Name);
                    return;
                }

                object defaultValueObject = EditorKlaxScriptUtility.GetTypeDefault(m_valueType);
                m_displayedList.Add(new CDictionaryEntryViewModel(m_displayedList.Count, m_addKeyValue, defaultValueObject, m_keyType, m_valueType));


                if (PropertyInfo.Value == null)
                {
                    IDictionary newDictionary = (IDictionary)Activator.CreateInstance(PropertyInfo.ValueType);

                    foreach (var viewModel in m_displayedList)
                    {
                        newDictionary.Add(viewModel.Key, viewModel.Value);
                    }
                    SetInspectorValue(PropertyInfo, null, newDictionary, true);
                }
                else
                {
                    if (m_inspector.DispatchSetter)
                    {
                        CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                        {
                            IDictionary dictionary = PropertyInfo.GetOriginalValue <IDictionary>();
                            dictionary.Add(m_addKeyValue, defaultValueObject);
                        });
                    }
                    else
                    {
                        IDictionary dictionary = PropertyInfo.GetOriginalValue <IDictionary>();
                        dictionary.Add(m_addKeyValue, defaultValueObject);
                    }
                }

                CollectionList.ItemsSource = null;
                CollectionList.ItemsSource = m_displayedList;
                HeaderText = m_displayedList.Count + " Elements";
            });

            ClearCommand = new CRelayCommand(arg =>
            {
                ClearCollection();
            });

            InitializeComponent();
        }
コード例 #2
0
        public ListInspector()
        {
            InitializeComponent();

            AddElementCommand = new CRelayCommand((arg) =>
            {
                object defaultObject = EditorKlaxScriptUtility.GetTypeDefault(m_collectionElementType);
                m_displayedList.Add(new CListEntryViewModel(m_displayedList.Count, defaultObject, m_collectionElementType));

                if (PropertyInfo.Value == null)
                {
                    IList newList = (IList)Activator.CreateInstance(PropertyInfo.ValueType);

                    foreach (var value in m_displayedList)
                    {
                        newList.Add(value.Value);
                    }
                    SetInspectorValue(PropertyInfo, null, newList, true);
                }
                else
                {
                    if (m_inspector.DispatchSetter)
                    {
                        CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                        {
                            IList list = PropertyInfo.GetOriginalValue <IList>();
                            list.Add(defaultObject);
                        });
                    }
                    else
                    {
                        IList list = PropertyInfo.GetOriginalValue <IList>();
                        list.Add(defaultObject);
                    }
                }

                CollectionList.ItemsSource = null;
                CollectionList.ItemsSource = m_displayedList;
                ListExpander.Header        = m_displayedList.Count + " Elements";
            });

            ClearCommand = new CRelayCommand(arg =>
            {
                ClearCollection();
            });
        }