예제 #1
0
        public void TestSetValue()
        {
            DummyClass c = new DummyClass {
                b1 = false
            };

            wrapper.SetValue(c, true);
            Assert.Equal(true, c.b1);
        }
예제 #2
0
        public void TestSetValue()
        {
            DummyClass c = new DummyClass {
                B1 = false
            };

            wrapper.SetValue(c, true);
            Assert.True(c.B1);
        }
예제 #3
0
        public void TestSetValue__Private()
        {
            PropertyInfo    property = typeof(DummyClass).GetProperty(nameof(DummyClass.b3));
            PropertyWrapper wrapper2 = new PropertyWrapper(property);
            DummyClass      c        = new DummyClass();

            wrapper2.SetValue(c, true);
            Assert.Equal(true, c.b3);
        }
예제 #4
0
        /// <summary>
        /// copy property value from source to target. Deep cloning used if necessary
        /// </summary>
        private static void CopyPropertyValue(object source, object target, PropertyWrapper propertyWrapper, Dictionary <object, object> clonedObjects)
        {
            var value = propertyWrapper.GetValue(source);

            if (value == null)
            {
                return;
            }

            if (propertyWrapper.CloningMode == CloningMode.Deep)
            {
                value = Clone(propertyWrapper.TypeWrapper, value, clonedObjects);
            }

            propertyWrapper.SetValue(target, value);
        }
예제 #5
0
        private void FillObject(TypeWrapper wrapper, object target, IDataAdapter data)
        {
            if (wrapper.IsSelfSerializable)
            {
                ((INanoSerializable)target).Deserialize(data, this);
                return;
            }

            // read properties
            for (int i = 0; i < wrapper.Properties.Count; i++)
            {
                PropertyWrapper property = wrapper.Properties[i];

                // should be already loaded at this time
                if (property.ConstructorArg != -1 && property.State != NanoState.SerializeSet)
                {
                    continue;
                }

                if (property.Info.GetMethod.IsPrivate && property.Info.SetMethod.IsPrivate &&
                    (flags & OptimizationFlags.PrivateProperties) == 0)
                {
                    continue;
                }

                if (property.TypeCategory == TypeCategory.Primitive ||
                    property.TypeCategory == TypeCategory.Enum)
                {
                    if (!property.Info.CanWrite)
                    {
                        continue;
                    }

                    property.SetValue(
                        target,
                        DeserializePrimitive(
                            property.MemberType,
                            data,
                            property.Name,
                            property.Location != NanoLocation.SubNode,
                            (flags & OptimizationFlags.EnumAsValue) != 0
                            )
                        );
                }
                else
                {
                    IDataAdapter subnode = data.GetChild(property.Name);
                    if (subnode != null)
                    {
                        object currentValue = property.GetValue(target);
                        if (currentValue == null)
                        {
                            property.SetValue(target, DeserializeObject(property.MemberType, subnode, null));
                        }
                        else
                        {
                            DeserializeObject(property.MemberType, subnode, currentValue);
                        }
                    }
                }
            }

            // read fields
            for (int i = 0; i < wrapper.Fields.Count; i++)
            {
                FieldWrapper field = wrapper.Fields[i];

                // should be already loaded at this time
                if (field.ConstructorArg != -1 && field.State != NanoState.SerializeSet)
                {
                    continue;
                }

                if (field.TypeCategory == TypeCategory.Primitive ||
                    field.TypeCategory == TypeCategory.Enum)
                {
                    field.SetValue(
                        target,
                        DeserializePrimitive(
                            field.MemberType,
                            data,
                            field.Name,
                            field.Location != NanoLocation.SubNode,
                            (flags & OptimizationFlags.EnumAsValue) != 0
                            )
                        );
                }
                else
                {
                    IDataAdapter subnode = data.GetChild(field.Name);
                    if (subnode != null)
                    {
                        object value = DeserializeObject(field.MemberType, subnode, null);
                        if (value != null)
                        {
                            field.SetValue(target, value);
                        }
                    }
                }
            }
        }