Пример #1
0
        internal void OnChildValueSet(ValueDrawer child, ValueAccessResult result)
        {
            if (Parent == null)
            {
                return;
            }
            if (!Parent.ValueEntry.TypeOfValue.IsValueType)
            {
                return;
            }
            if (GetMapped(child) == null)
            {
                return;
            }

            var ownerValue = child.ValueEntry.Owner;

            Parent.SetValue(ownerValue, true, true);

            foreach (var otherChild in MappedChildren)
            {
                if (otherChild != child)
                {
                    otherChild.ValueEntry.Owner = ownerValue;
                }
            }
        }
Пример #2
0
        private void SetChildrenImpl(IEnumerable <MemberInfo> members, bool verifyReflectedType)
        {
            foreach (var member in members)
            {
                if (verifyReflectedType && !member.ReflectedType.IsAssignableFrom(ValueType))
                {
                    var msg = string.Format(
                        @"Member of ""{0}"" expected, got ""{1}"".",
                        ValueType, member.ReflectedType);
                    throw new ArgumentException(msg, "members");
                }

                var child = GetChild(member);
                if (child != null)
                {
                    continue;
                }

                var childName  = member.Name;
                var childState = DrawerStates.Get(HierarchicalName + '.' + childName);
                child = ValueDrawer.Create(
                    member.DeclaringType, MemberInfoUtil.MemberTypeOf(member), childName, null, childState);
                Assert.IsTrue(AddMapping(member, child), string.Format(
                                  @"Failed to add member mapping from ""{0}"" to ""{1}"".", member, child.HierarchicalName));
            }
        }
Пример #3
0
        protected bool AddMapping(T toMap, ValueDrawer child, bool replaceIfExisted = false)
        {
            ValueDrawer existedChild;

            if (mappedToChild.TryGetValue(toMap, out existedChild))
            {
                if (child == existedChild)
                {
                    return(false);
                }

                if (!replaceIfExisted)
                {
                    throw new InvalidOperationException(string.Format(
                                                            @"Member ""{0}"" mapping to child ""{1}"" already existed.",
                                                            toMap, child.HierarchicalName));
                }
            }

            child.Parent         = this;
            mappedToChild[toMap] = child;
            childToMapped[child] = toMap;

            return(true);
        }
Пример #4
0
        protected void UpdateReferencedParent()
        {
            var value = DrawingValue;

            if (value != null)
            {
                foreach (var parent in ParentValueDrawers)
                {
                    var pve = parent.ValueEntry;
                    if (pve == null)
                    {
                        continue;
                    }

                    if (ReferenceEquals(value, parent.DrawingValue) && DrawType == parent.DrawType)
                    {
                        ReferencedParent = parent;
                        break;
                    }
                }
            }
            else
            {
                ReferencedParent = null;
            }
        }
Пример #5
0
        private ValueDrawer CreateDrawer(UObject[] objects, UObject obj, int index)
        {
            var valueEntry = SelectionEntryFactory.Create(obj.GetType(), objects, index);
            var drawer     = ValueDrawer.Create(valueEntry.TypeOfOwner, valueEntry.TypeOfValue, objects[index].name);

            drawer.ValueEntry      = valueEntry;
            drawer.SelfVisible     = true;
            drawer.ChildrenVisible = true;
            return(drawer);
        }
Пример #6
0
 protected bool RemoveMapping(ValueDrawer child)
 {
     // Maybe the child is added from parent without mapping to a member, so reverse mapping is not required.
     return(RemoveMapping(childToMapped, mappedToChild, child, false));
 }
Пример #7
0
 public T GetMapped(ValueDrawer child)
 {
     Ensure.Argument.NotNull(child, "child");
     return(childToMapped.GetValue(child));
 }