예제 #1
0
 protected virtual void SetElementCount(int size, bool shouldChange = true)
 {
     if (size > children.Count)
     {
         Type elementType = GetElementType();
         //because we know this will be null or a primitive,
         //it is safe to pass the same element to every new index
         //todo maybe make a real instance when we can
         object element = EditorReflector.GetDefaultForType(elementType);
         for (int i = children.Count; i < size; i++)
         {
             children.Add(CreateChild(this, string.Empty, elementType, element));
         }
         if (shouldChange)
         {
             SetChanged(true);
         }
     }
     else if (size < children.Count)
     {
         while (children.Count > size)
         {
             DestroyChild(children.RemoveAndReturnAtIndex(children.Count - 1));
         }
         if (shouldChange)
         {
             SetChanged(true);
         }
     }
 }
예제 #2
0
        protected virtual void ResizeActualValue()
        {
            IList list = actualValue as IList;

            if (children.Count == 0 || (list != null && list.Count == children.Count))
            {
                return;
            }
            list = list ?? EditorReflector.MakeInstance <IList>(declaredType);
            Debug.Assert(list != null, nameof(list) + " != null");
            if (list.Count > children.Count)
            {
                while (list.Count > children.Count)
                {
                    list.RemoveAt(list.Count - 1);
                }
            }
            else if (list.Count < children.Count)
            {
                while (list.Count < children.Count)
                {
                    list.Add(EditorReflector.GetDefaultForType(declaredType.GetGenericArguments()[0]));
                }
            }
            actualValue = list;
        }
예제 #3
0
 public void InsertElement(int index)
 {
     if (index >= 0 && index <= ChildCount)
     {
         Type              elementType  = GetElementType();
         object            defaultValue = EditorReflector.GetDefaultForType(declaredType);
         ReflectedProperty child        = CreateChild(this, string.Empty, elementType, defaultValue);
         if (index == ChildCount)
         {
             AddElement(child);
             return;
         }
         children.Insert(index, child);
         SetChanged(true);
     }
 }
예제 #4
0
        protected virtual void SetValue(object value)
        {
            Type previousType = actualType;

            if (value == null)
            {
                actualType  = declaredType;
                actualValue = EditorReflector.GetDefaultForType(declaredType);
            }
            else
            {
                actualType  = value.GetType();
                actualValue = value;
            }
            if (actualType != previousType)
            {
                this.drawer = EditorReflector.CreateReflectedPropertyDrawer(this);
            }
        }