Пример #1
0
        /// <summary>
        /// Read setting object from stream.
        /// </summary>
        /// <param name="userSettings">Object that should be deserialized.</param>
        /// <param name="stream">Stream object; could be file, memory, other.</param>
        public void Read(IUserSettings userSettings, Stream stream)
        {
            if (stream == null || userSettings == null)
            {
                return;
            }

            using (var reader = new StreamReader(stream))
            {
                try
                {
                    Logger?.Log("Deserialize user settings");

                    var liteUserSettingsType = LiteObjectService.GetLiteObjectType(userSettings);
                    if (liteUserSettingsType == null)
                    {
                        return;
                    }
                    var sourceSettings = (new XmlSerializer(liteUserSettingsType)).Deserialize(reader);
                    LiteObjectService.CopyLiteObjectValues(userSettings, sourceSettings);
                }
                catch (InvalidOperationException)
                { }
            }
        }
Пример #2
0
        public void GetLiteObjectType_Should_ReturnTheSameValue()
        {
            SimpleObject testObject      = null;
            Type         liteObjectType1 = null;
            Type         liteObjectType2 = null;

            var exception = Record.Exception(() =>
            {
                testObject            = new SimpleObject();
                var liteObjectService = new LiteObjectService();
                liteObjectType1       = liteObjectService.GetLiteObjectType(testObject);
                liteObjectType2       = liteObjectService.GetLiteObjectType(testObject);
            });

            exception.Should().BeNull();
            testObject.Should().NotBeNull();
            liteObjectType1.Should().NotBeNull();
            liteObjectType2.Should().NotBeNull();
            liteObjectType1.Should().BeSameAs(liteObjectType2);
        }