Пример #1
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));
            }
        }
Пример #2
0
        public static IValueEntry Create(Type ownerType, object owner, MemberInfo memberInfo)
        {
            Ensure.Argument.NotNull(ownerType, "ownerType");
            Ensure.Argument.NotNull(memberInfo, "memberInfo");

            var valueType      = MemberInfoUtil.MemberTypeOf(memberInfo);
            var valueEntryType = MakeEntryType(ownerType, valueType, memberInfo.GetType());

            if (valueEntryType == null)
            {
                return(null);
            }

            return((IValueEntry)Activator.CreateInstance(valueEntryType, owner, memberInfo));
        }