当前位置: 首页>>代码示例>>C#>>正文


C# NetDataContractSerializer.ReadObject方法代码示例

本文整理汇总了C#中System.Runtime.Serialization.NetDataContractSerializer.ReadObject方法的典型用法代码示例。如果您正苦于以下问题:C# NetDataContractSerializer.ReadObject方法的具体用法?C# NetDataContractSerializer.ReadObject怎么用?C# NetDataContractSerializer.ReadObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Serialization.NetDataContractSerializer的用法示例。


在下文中一共展示了NetDataContractSerializer.ReadObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize

 public static object Deserialize(byte[] buffer)
 {
     using (MemoryStream memStream = new MemoryStream(buffer))
     using (GZipStream zipStream = new GZipStream(memStream, CompressionMode.Decompress))
     using (XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateBinaryReader(zipStream, XmlDictionaryReaderQuotas.Max))
     {
         NetDataContractSerializer serializer = new NetDataContractSerializer();
         return serializer.ReadObject(xmlDictionaryReader);
     }
 }
开发者ID:lmagyar,项目名称:Orleans.Activities,代码行数:10,代码来源:InstanceValueDictionarySerializer.cs

示例2: Deserialize

        private object Deserialize(string value, Type type)
        {
            using (var m = new MemoryStream(Encoding.Unicode.GetBytes(value)))
            {
                var r = XmlDictionaryReader.CreateTextReader(m, Encoding.Unicode, XmlDictionaryReaderQuotas.Max, null);

                //var s = new DataContractSerializer(type, null, Int32.MaxValue, false, false, null, new PluginDataContractResolver());
                var s = new NetDataContractSerializer();

                return s.ReadObject(r);
            }
        }
开发者ID:skyquery,项目名称:graywulf,代码行数:12,代码来源:PluginDataContractResolverTest.cs

示例3: DeserializeMethodBase

        static KeyValuePair<string, MethodBase> DeserializeMethodBase(XmlReader reader)
        {
            var sb = new StringBuilder();
            sb.Append(reader.ReadOuterXml());

            var s = sb.ToString();
            var ndcs = new NetDataContractSerializer();
            using (var sr = new StringReader(s))
            using (var xr = new XmlTextReader(sr))
            {
                return new KeyValuePair<string, MethodBase>(s, (MethodBase)ndcs.ReadObject(xr));
            }
        }
开发者ID:umaranis,项目名称:Prig,代码行数:13,代码来源:StubElement.cs

示例4: SholdSerializeOperator

        public void SholdSerializeOperator()
        {
            // Given
            var entity = new FilterTestEntity { StringField = "Abc", IntField = 5 };

            // Какое-то сложное логическое выражение
            var specification = new FilterSpecification<FilterTestEntity>(
                b => b.Or(
                    c => c
                             .And(a => a.Or(o => o
                                                     .Null(i => i.StringField)
                                                     .Equal(i => i.StringField, string.Empty))
                                           .Equal(i => i.IntField, 0))
                             .And(a => a
                                           .NotNull(i => i.StringField)
                                           .NotEqual(i => i.StringField, string.Empty)
                                           .Or(o => o
                                                        .In(i => i.StringField.ToLower(), new[] { "a", "b", "c" })
                                                        .Contains(i => i.StringField.ToLower(), "abc")
                                                        .StartsWith(i => i.StringField, "1")
                                                        .EndsWith(i => i.StringField, "5"))
                                           .Or(o => o
                                                        .And(a2 => a2
                                                                       .GreaterOrEqual(i => i.IntField, 0)
                                                                       .LessOrEqual(i => i.IntField, 10))
                                                        .And(a2 => a2
                                                                       .Greater(i => i.IntField, 10)
                                                                       .Less(i => i.IntField, 20))
                                                        .Between(i => i.IntField, 20, 30)))));

            IFilterOperator operatorFromStream;
            IFilterOperator operatorToStream = specification.Operator;

            // When
            using (var stream = new MemoryStream())
            {
                // Сериализация
                var serializer = new NetDataContractSerializer();
                serializer.Serialize(stream, operatorToStream);
                stream.Position = 0;

                // Десериализация
                operatorFromStream = (IFilterOperator)serializer.ReadObject(stream);
            }

            // Then
            Assert.IsNotNull(operatorFromStream);
            Assert.AreEqual(operatorToStream.IsSatisfiedBy(entity), operatorFromStream.IsSatisfiedBy(entity));
        }
开发者ID:AlexMAS,项目名称:Specifications,代码行数:49,代码来源:FilterSpecificationTest.cs

示例5: GetSerializedVersion

 private static Response GetSerializedVersion(object response)
 {
     try
     {
         using (var stream = new MemoryStream())
         {
             var serializer = new NetDataContractSerializer();
             serializer.WriteObject(stream, response);
             stream.Position = 0;
             return (Response)serializer.ReadObject(stream);
         }
     }
     catch (Exception ex)
     {
         throw new ColomboSerializationException(string.Format("{0} could not be serialized.", response), ex);
     }
 }
开发者ID:julienblin,项目名称:Colombo,代码行数:17,代码来源:StubRequestHandleInvocation.cs

示例6: ReadFaultDetail

        private static object ReadFaultDetail(Message reply)
        {
            const string DetailElementName = "Detail";

            using (XmlDictionaryReader reader = reply.GetReaderAtBodyContents())
            {
                // Find <soap:Detail>
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.LocalName == DetailElementName)
                    {
                        break;
                    }
                }

                // Did we find it?
                if (reader.NodeType != XmlNodeType.Element || reader.LocalName != DetailElementName)
                {
                    return null;
                }

                // Move to the contents of <soap:Detail>
                if (!reader.Read())
                {
                    return null;
                }

                // Deserialize the fault
                NetDataContractSerializer serializer = new NetDataContractSerializer();
                try
                {
                    return serializer.ReadObject(reader);
                }
                catch (FileNotFoundException)
                {
                    // Serializer was unable to find assembly where exception is defined
                    return null;
                }
                catch (SerializationException)
                {
                    // Error during deserialization
                    return null;
                }
            }
        }
开发者ID:jandppw,项目名称:ppwcode-recovered-from-google-code,代码行数:45,代码来源:ExceptionMarshallingMessageInspector.cs

示例7: Commit

 public override void Commit(IDictionary savedState)
 {
     this.PrintStartText(System.Configuration.Install.Res.GetString("InstallActivityCommitting"));
     if (!this.initialized)
     {
         this.InitializeFromAssembly();
     }
     string installStatePath = this.GetInstallStatePath(this.Path);
     FileStream input = new FileStream(installStatePath, FileMode.Open, FileAccess.Read);
     XmlReaderSettings settings = new XmlReaderSettings {
         CheckCharacters = false,
         CloseInput = false
     };
     XmlReader reader = null;
     if (input != null)
     {
         reader = XmlReader.Create(input, settings);
     }
     try
     {
         if (reader != null)
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             savedState = (Hashtable) serializer.ReadObject(reader);
         }
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
         if (input != null)
         {
             input.Close();
         }
         if (base.Installers.Count == 0)
         {
             base.Context.LogMessage(System.Configuration.Install.Res.GetString("RemovingInstallState"));
             File.Delete(installStatePath);
         }
     }
     base.Commit(savedState);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:44,代码来源:AssemblyInstaller.cs

示例8: DeserializeUsingNetDataContract

        public static object DeserializeUsingNetDataContract(string filename)
        {
            object theObject = null;
            int maxDepth = 10000;
            bool maxDepthExceeded = true;

            while (maxDepthExceeded)
            {
                try
                {
                    using (FileStream fs = new FileStream(filename, FileMode.Open))
                    {
                        XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
                        quotas.MaxDepth = maxDepth;

                        using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, quotas))
                        {
                            NetDataContractSerializer ser = new NetDataContractSerializer();
                            //ser.Binder = new Version2SerializationBinder();
                            theObject = (List<ArchAngel.Providers.Database.Model.Database>)ser.ReadObject(reader, true);
                        }
                        fs.Close();
                        maxDepthExceeded = false;
                    }
                }
                catch (SerializationException ex)
                {
                    if (ex.Message.IndexOf("more levels of nesting than is allowed by the quota") >= 0)
                    {
                        // We need to increase the maxDepth
                        maxDepth += 1000;
                        maxDepthExceeded = true;
                    }
                    else
                    {
                        // We have another kind of error
                        throw;
                    }
                }
            }
            return theObject;
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:42,代码来源:Helper.cs

示例9: Net_data_contract_serialization_will_not_change_the_type_of_a_collection

        public void Net_data_contract_serialization_will_not_change_the_type_of_a_collection()
        {
            using (var session = DataAccess.OpenSession())
            {
                var forum = session.Get<ForumModel>(1);

                //company.EmployeesList made public for the purpose of
                //this demo
                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());

                var serializer = new NetDataContractSerializer();

                //serialize company to a memory stream
                Stream stream = new MemoryStream();
                serializer.WriteObject(stream, forum);
                Console.WriteLine();
                //deserialize the memory stream back to a company
                stream.Position = 0;
                forum = (ForumModel)serializer.ReadObject(stream);

                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());
            }
        }
开发者ID:michal-franc,项目名称:ElearnServices,代码行数:23,代码来源:DataSerializationTests.cs

示例10: Deserialize

        /// <summary>
        /// Deserialize data.
        /// </summary>
        /// <param name="data">Data to deserialize.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <returns>The deserialized data.</returns>
        public object Deserialize( string data, Encoding encoding = null )
        {
            if ( encoding == null )
             {
            encoding = DefaultEncoding;
             }

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

             var bytes = encoding.GetBytes( data );

             if ( bytes == null || bytes.Length == 0 )
             {
            return null;
             }

             object result;
             using ( var memoryStream = new MemoryStream( bytes ) )
             {
            using ( var xmlDictionaryReader = XmlDictionaryReader.CreateTextReader( memoryStream, encoding, XmlDictionaryReaderQuotas.Max, null ) )
            {
               var netDataContractSerializer = new NetDataContractSerializer();

               result = netDataContractSerializer.ReadObject( xmlDictionaryReader, true );
            }
             }

             if ( result != null && result.GetType() == typeof( NullObject ) )
             {
            return null;
             }

             return result;
        }
开发者ID:Quarterback16,项目名称:GerardGui,代码行数:43,代码来源:XmlSerializer.cs

示例11: Rollback

 public override void Rollback(IDictionary savedState)
 {
     this.PrintStartText(Res.GetString("InstallActivityRollingBack"));
     string installStatePath = this.GetInstallStatePath(this.Path);
     FileStream input = new FileStream(installStatePath, FileMode.Open, FileAccess.Read);
     XmlReaderSettings settings = new XmlReaderSettings
     {
         CheckCharacters = false,
         CloseInput = false
     };
     XmlReader reader = null;
     if (input != null)
     {
         reader = XmlReader.Create(input, settings);
     }
     try
     {
         if (reader != null)
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             savedState = (Hashtable)serializer.ReadObject(reader);
         }
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
         if (input != null)
         {
             input.Close();
         }
     }
     try
     {
         base.Rollback(savedState);
     }
     finally
     {
         File.Delete(installStatePath);
     }
 }
开发者ID:Epitomy,项目名称:CMS,代码行数:43,代码来源:IntegratedInstaller.cs

示例12: LoadDefFromStore

		internal static ScheduledJobDefinition LoadDefFromStore(string definitionName, string definitionPath)
		{
			ScheduledJobDefinition scheduledJobDefinition = null;
			FileStream fileForJobDefinition = null;
			try
			{
				if (definitionPath != null)
				{
					fileForJobDefinition = ScheduledJobStore.GetFileForJobDefinition(definitionName, definitionPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				}
				else
				{
					fileForJobDefinition = ScheduledJobStore.GetFileForJobDefinition(definitionName, FileMode.Open, FileAccess.Read, FileShare.Read);
				}
				XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
				scheduledJobDefinition = netDataContractSerializer.ReadObject(fileForJobDefinition) as ScheduledJobDefinition;
			}
			finally
			{
				if (fileForJobDefinition != null)
				{
					fileForJobDefinition.Close();
				}
			}
			return scheduledJobDefinition;
		}
开发者ID:nickchal,项目名称:pash,代码行数:26,代码来源:ScheduledJobDefinition.cs

示例13: Uninstall

 public override void Uninstall(IDictionary savedState)
 {
     this.PrintStartText(System.Configuration.Install.Res.GetString("InstallActivityUninstalling"));
     if (!this.initialized)
     {
         this.InitializeFromAssembly();
     }
     string installStatePath = this.GetInstallStatePath(this.Path);
     if ((installStatePath != null) && File.Exists(installStatePath))
     {
         FileStream input = new FileStream(installStatePath, FileMode.Open, FileAccess.Read);
         XmlReaderSettings settings = new XmlReaderSettings {
             CheckCharacters = false,
             CloseInput = false
         };
         XmlReader reader = null;
         if (input != null)
         {
             reader = XmlReader.Create(input, settings);
         }
         try
         {
             if (reader != null)
             {
                 NetDataContractSerializer serializer = new NetDataContractSerializer();
                 savedState = (Hashtable) serializer.ReadObject(reader);
             }
         }
         catch
         {
             base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallSavedStateFileCorruptedWarning", new object[] { this.Path, installStatePath }));
             savedState = null;
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
             if (input != null)
             {
                 input.Close();
             }
         }
     }
     else
     {
         savedState = null;
     }
     base.Uninstall(savedState);
     if ((installStatePath != null) && (installStatePath.Length != 0))
     {
         try
         {
             File.Delete(installStatePath);
         }
         catch
         {
             throw new InvalidOperationException(System.Configuration.Install.Res.GetString("InstallUnableDeleteFile", new object[] { installStatePath }));
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:62,代码来源:AssemblyInstaller.cs

示例14: Deserialize

 public static object Deserialize(string value)
 {
     if (String.IsNullOrWhiteSpace(value))
     {
         return null;
     }
     else
     {
         using (var m = new MemoryStream(Encoding.Unicode.GetBytes(value)))
         {
             var r = XmlDictionaryReader.CreateTextReader(m, Encoding.Unicode, XmlDictionaryReaderQuotas.Max, null);
             var s = new NetDataContractSerializer();
             return s.ReadObject(r);
         }
     }
 }
开发者ID:horvatferi,项目名称:graywulf,代码行数:16,代码来源:DBHelper.cs

示例15: InitializeWurmServer

        /// <summary>
        /// Init WurmServer with optional dir path to where it should store it's data
        /// </summary>
        /// <param name="dataDir">Absolute directory path, default null uses CodeBase</param>
        /// <exception cref="ArgumentException">Directory path was probably invalid</exception>
        /// <exception cref="InvalidOperationException">WurmServer was already initialized</exception>
        public static void InitializeWurmServer(string dataDir = null)
        {
            if (isInitialized) throw new InvalidOperationException("WurmServer is already initialized");

            if (dataDir == null) _dataFilePath = GeneralHelper.PathCombineWithCodeBasePath("WurmServerData.xml");
            else _dataFilePath = Path.Combine(dataDir, "WurmServerData.xml");

            Logger.LogInfo("Initializing", THIS);
            _initTask = new Task(async () =>
                {
                    try
                    {
                        //get the old data so program can init faster
                        var ds = new NetDataContractSerializer();
                        using (Stream s = File.OpenRead(_dataFilePath))
                        {
                            _serverData = (WurmServerData)ds.ReadObject(s);
                        }
                    }
                    catch (Exception _e)
                    {
                        _serverData = new WurmServerData();
                        Logger.LogInfo("problem while loading cached WurmServer state, recaching", THIS, _e);
                    }
                    var webTask = ExtractFromWebAsync();
                    var logsTask = ExtractFromLogsAsync();
                    await webTask;
                    await logsTask;
                    Logger.LogInfo("Init complete", THIS);
                });
            _initTask.Start();
        }
开发者ID:webba,项目名称:WurmAssistant2,代码行数:38,代码来源:WurmServer.cs


注:本文中的System.Runtime.Serialization.NetDataContractSerializer.ReadObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。