• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Serialization.XmlSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Xml.Serialization.XmlSerializer的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.Serialization.XmlSerializer类的具体用法?C# System.Xml.Serialization.XmlSerializer怎么用?C# System.Xml.Serialization.XmlSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



System.Xml.Serialization.XmlSerializer类属于命名空间,在下文中一共展示了System.Xml.Serialization.XmlSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ObjetoSerializado

 public static string ObjetoSerializado(Object Objeto)
 {
     System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(Objeto.GetType());
     System.IO.StringWriter textWriter = new System.IO.StringWriter();
     x.Serialize(textWriter, Objeto);
     return textWriter.ToString();
 }
开发者ID:pjeconde,项目名称:CedServicios,代码行数:7,代码来源:Funciones.cs


示例2: Save

 public void Save()
 {
     var reader = new System.Xml.Serialization.XmlSerializer(typeof(List<Words>));
     var file = new FileStream("words.xml", FileMode.Create);
     reader.Serialize(file, LocalWords._words);
     file.Close();
 }
开发者ID:kapa76,项目名称:price_checker,代码行数:7,代码来源:MainForm.cs


示例3: Serialize

        public static void Serialize(object instance, out string xmlContent, out string serializerType)
        {
            SerializerTypes serializerTypeValue = SerializerTypes.Primitive;
            xmlContent = string.Empty;
            Type instanceType = typeof(object);
            if (instance != null)
            {
                if (instanceType.IsPrimitive || instanceType == typeof(string))
                {
                    xmlContent = string.Format("<{0}>{1}</{0}>", instanceType.Name, instance);
                }
                else if (instanceType.GetCustomAttributes(typeof(SerializableAttribute), true).FirstOrDefault() != null)
                {
                    serializerTypeValue = SerializerTypes.XmlSerializer;
                    StringWriter sww = new StringWriter();
                    XmlWriter writer = XmlWriter.Create(sww);
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(instanceType);
                    serializer.Serialize(sww, instanceType);
                    xmlContent = sww.ToString();
                }
                else
                {
                    serializerTypeValue = SerializerTypes.XmlObjectSerializer;
                    XmlObjectSerializer serializer = new XmlObjectSerializer();
                    xmlContent = serializer.Serialize(instance, instanceType).OuterXml;
                }
            }

            serializerType = string.Format(SerializerTypeFormat, serializerTypeValue, instanceType.AssemblyQualifiedName);
        }
开发者ID:priestofpsi,项目名称:theDiary-Common-Framework,代码行数:30,代码来源:SerializationHelper.cs


示例4: LoadTestCredential

        private void LoadTestCredential()
        {
            string path = @"C:\Temp\AmazonAwsS3Test.xml";
            Models.AwsCredential credential;
            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Models.AwsCredential));

            if (!System.IO.File.Exists(path))
            {
                //Cria um arquivo xml novo, se já não existir um
                credential = new Models.AwsCredential();
                credential.User = string.Empty;
                credential.AccessKeyId = string.Empty;
                credential.SecretAccessKey = string.Empty;
                credential.Region = string.Empty;

                using (var streamWriter = new System.IO.StreamWriter(path))
                {
                    xmlSerializer.Serialize(streamWriter, credential);
                }
            }

            //Carrega o xml
            using (var streamReader = new System.IO.StreamReader(path))
            {
                credential = (Models.AwsCredential)xmlSerializer.Deserialize(streamReader);
            }

            txtAccessKeyId.Text = credential.AccessKeyId;
            txtSecretAccessKey.Text = credential.SecretAccessKey;
            txtRegion.Text = credential.Region;
        }
开发者ID:educoutinho,项目名称:AmazonAwsS3Test,代码行数:31,代码来源:MainForm.cs


示例5: btnSubmit_Click

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //string xml;
               Contact contact = new Contact();

            contact.companyName = txtCompany.Text;
            contact.firstName = txtFName.Text;
            contact.middleName = txtMName.Text;
            contact.lastName = txtLName.Text;
            contact.liscence = txtLicense.Text;
            contact.phone = txtPhone.Text;
            contact.cell = txtCell.Text;
            contact.email = txtEmail.Text;
            contact.buildingLiscence = txtBuildingLicense.Text;
            contact.streetNumber = txtStreetNumber.Text;
            contact.streetName = txtStreetName.Text;
            contact.type = txtType.Text;
            contact.streetName2 = txtStreetName2.Text;
            contact.city = txtCity.Text;
            contact.state = txtState.Text;
            contact.zip = txtZip.Text;
            System.IO.StreamWriter file = new System.IO.StreamWriter(@"Contact.xml");
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(contact.GetType());
            x.Serialize(file, contact);
            file.Close();
        }
开发者ID:sunelaitisd088,项目名称:AberdeenPermitting,代码行数:26,代码来源:ContactInfo.cs


示例6: Init

        //[DebuggerHidden]
        public override bool Init()
        {
            loopratehz = 1;

            if (File.Exists(statsfile))
            {
                try
                {
                    System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(statsoverall.GetType());

                    var file = new System.IO.StreamReader(statsfile);

                    statsoverall = (whattostat)reader.Deserialize(file);

                    file.Close();
                }
                catch { }
            }

            MainV2.instance.Invoke((Action)
                delegate
                {

            System.Windows.Forms.ToolStripMenuItem men = new System.Windows.Forms.ToolStripMenuItem() { Text = "Stats" };
            men.Click += men_Click;
            Host.FDMenuMap.Items.Add(men);
            });

            statsoverall.appstarts++;

            return true;
        }
开发者ID:klonage,项目名称:nlt-gcs,代码行数:33,代码来源:StatsPlugin.cs


示例7: GetHigtscore

 private List<Record> GetHigtscore()
 {
     System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(List<Record>));
     System.IO.StreamReader file = new System.IO.StreamReader("Records.xml");
     _records = (List<Record>)reader.Deserialize(file);
     return _records;
 }
开发者ID:Confirmit,项目名称:Students,代码行数:7,代码来源:Records.cs


示例8: Chomper

        public Chomper(RoomNew room, ContentManager Content, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.TileType NextTileType__1)
        {
            base.room = room;

            nextTileType = NextTileType__1;
            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(tileSequence.GetType());

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");

            tileSequence = (List<Sequence>)ax.Deserialize(txtReader);

            foreach (Sequence s in tileSequence)
            {
                s.Initialize(Content);
            }

            //Search in the sequence the right type
            //Sequence result = tileSequence.Find((Sequence s) => s.name.ToUpper() == state.ToString().ToUpper());
            Sequence result = tileSequence.Find((Sequence s) => s.name == state.ToString().ToUpper());

            if (result != null)
            {
                result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_TILES[0] + result.frames[0].value));

                collision = result.collision;
                Texture = result.frames[0].texture;
            }
            Type = tileType;

            //change statetile element
            tileState.Value().state = state;
            tileAnimation.PlayAnimation(tileSequence, tileState.Value());
        }
开发者ID:salvadorc17,项目名称:Prince-Monogame,代码行数:33,代码来源:Chomper.cs


示例9: OnCreate

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            //
            // Get the person object from the intent
            //
            Person person;
            if (Intent.HasExtra ("Person")) {
                var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Person));
                var personBytes = Intent.GetByteArrayExtra ("Person");
                person = (Person)serializer.Deserialize (new MemoryStream (personBytes));
            } else {
                person = new Person ();
            }

            //
            // Load the View Model
            //
            viewModel = new PersonViewModel (person, Android.Application.SharedFavoritesRepository);
            viewModel.PropertyChanged += HandleViewModelPropertyChanged;

            //
            // Setup the UI
            //
            ListView.Divider = null;
            ListAdapter = new PersonAdapter (viewModel);

            Title = person.SafeDisplayName;
        }
开发者ID:EminosoftCorp,项目名称:prebuilt-apps,代码行数:30,代码来源:PersonActivity.cs


示例10: SaveXML

 public void SaveXML(ConfigureXml config)
 {
     System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(ConfigureXml));
     System.IO.StreamWriter file = new System.IO.StreamWriter(@"AppConfig.xml");
     writer.Serialize(file, config);
     file.Close();
 }
开发者ID:rnmoge,项目名称:nfce-Sat,代码行数:7,代码来源:XmlConfigure.cs


示例11: Serialize

        public static void Serialize(object obj, TextWriter output)
        {
            Debug.Assert(obj != null);
            Debug.Assert(output != null);

            #if !NET_1_0 && !NET_1_1
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.NewLineOnAttributes = true;
            settings.CheckCharacters = false;
            settings.OmitXmlDeclaration = true;
            XmlWriter writer = XmlWriter.Create(output, settings);
            #else
            XmlTextWriter writer = new XmlTextWriter(output);
            writer.Formatting = Formatting.Indented;
            #endif

            try
            {
                SystemXmlSerializer serializer = new SystemXmlSerializer(obj.GetType());
                serializer.Serialize(writer, obj);
                writer.Flush();
            }
            finally
            {
                writer.Close();
            }
        }
开发者ID:AkosLukacs,项目名称:ElmahMod,代码行数:28,代码来源:XmlSerializer.cs


示例12: Main

        static void Main(string[] args)
        {
            System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config));
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "config.xml"))
            {
                Config config = new Config() {id=1, WirelessComPort = "Com14", TouhPanelComPort = "Com18",IOComPort="Com12" };
            
                sr.Serialize(System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "config.xml"), config);
                Console.WriteLine("please modify the config.xml");
             //   Console.ReadKey();
                Environment.Exit(-1);
            }
            else
            {
                config = sr.Deserialize(System.IO.File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "config.xml")) as Config;

                if (config == null)
                {
                    Console.WriteLine("config.xml  reading error!");
                    Environment.Exit(-1);
                }
            }
            controller = new Controller(config.id,config.WirelessComPort,config.TouhPanelComPort,config.IOComPort);

            
        }
开发者ID:ufjl0683,项目名称:wirelessBrocast,代码行数:26,代码来源:Program.cs


示例13: Deserialize

 public object Deserialize(System.IO.Stream stream, Type type)
 {
     System.Xml.Serialization.XmlSerializer serializer =
         new System.Xml.Serialization.XmlSerializer(type);
     stream.Position = 0;
     return serializer.Deserialize(stream);
 }
开发者ID:scnakandala,项目名称:DoitShareit,代码行数:7,代码来源:XmlSerializer.cs


示例14: Button_ClickSave

        private void Button_ClickSave(object sender, RoutedEventArgs e)
        {
            //WIP
            string CartBox = ArtBox.SelectedItems.ToString();
            string Comboselectedmonth = DateBoxMonth.SelectedItem.ToString();
            string Comboselectedyear = DateBoxYear.SelectedItem.ToString();
            string Agynentxt = GyneBox.Text.ToString();
            string Aworkertxt = WorkerBox.Text.ToString();
            string Asoldiertxt = SoldierBox.Text.ToString();

            Colony ColonyOne = new Colony();
            ColonyOne.Cname = NameBox.Text;
            ColonyOne.Cart = CartBox;
            ColonyOne.Cnote = NoteBox.Text;

            ColonyOne.Cgdatummonth = Comboselectedmonth;
            ColonyOne.Cgdatumyear = Comboselectedyear;

            ColonyOne.Agynen = Agynentxt;
            ColonyOne.Aworker = Aworkertxt;
            ColonyOne.Asoldiers = Asoldiertxt;

            //nn to check if folder exists, "System.IO.Directory.CreateDirectory" does that for us
            string mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            System.IO.Directory.CreateDirectory(mydocs + "/AntManager");

            System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Colony));

            var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/AntManager/AntManagerSaveFile.xml";
            System.IO.FileStream file = System.IO.File.Create(path);

            writer.Serialize(file, ColonyOne);
            file.Close();
        }
开发者ID:Kulu-M,项目名称:Ant-Manager,代码行数:34,代码来源:KolonieNeu.xaml.cs


示例15: Serialize

 public void Serialize(string filename)
 {
     System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(this.GetType());
     StreamWriter writer = new StreamWriter(filename);
     x.Serialize(writer, this);
     writer.Close();
 }
开发者ID:pabloat81,项目名称:MobileNet,代码行数:7,代码来源:MBConfig.cs


示例16: Read

        public static AltaCache Read(string file)
        {
            if (!File.Exists(file))
            {
                Write(file, new AltaCache());
                return new AltaCache();
            }
            else
            {
                FileInfo inf = new FileInfo(file);
                while (inf.IsFileLocked()) { Console.WriteLine("Wait..."); };
                try
                {
                    using (Stream s = File.Open(file, FileMode.Open))
                    {
                        System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(AltaCache));
                        return (AltaCache)reader.Deserialize(s);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetBaseException().ToString());
                    return new AltaCache();
                }

            }
        }
开发者ID:iceriver102,项目名称:alta-mtc-version-2,代码行数:27,代码来源:AltaCache.cs


示例17: load

        //Loads a environment from an XML file and initializes it
        public static ExperimentWrapper load(string name)
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(ExperimentWrapper));
            TextReader infile = new StreamReader(name);
            ExperimentWrapper e = (ExperimentWrapper)x.Deserialize(infile);
            infile.Close();

            //TODO include LEO

            //Determine the number of CPPN inputs and outputs automatically
            //if (e.experiment.homogeneousTeam)
            //    e.experiment.inputs = 4;
            //else
            //    e.experiment.inputs = 5;

            //if (e.experiment.adaptableANN)
            //{
            //    if (e.experiment.modulatoryANN) e.experiment.outputs = 8; else e.experiment.outputs = 7;
            //}
            //else
            //    e.experiment.outputs = 2;

            //TODO maybe include			e.experiment.initialize();
            return e;
        }
开发者ID:jtglaze,项目名称:IndependentWork2013,代码行数:26,代码来源:ExperimentWrapper.cs


示例18: Write

 public static void Write(string file, AltaCache overview)
 {
     if (string.IsNullOrEmpty(file))
         throw new Exception("File Not Empty");
     System.Xml.Serialization.XmlSerializer writer =
     new System.Xml.Serialization.XmlSerializer(typeof(AltaCache));
     System.Xml.XmlWriterSettings setting = new System.Xml.XmlWriterSettings();
     setting.Encoding = Encoding.UTF8;
     setting.CloseOutput = true;
     setting.NewLineChars = "\r\n";
     setting.Indent = true;
     if (!File.Exists(file))
     {
         using (Stream s = File.Open(file, FileMode.OpenOrCreate))
         {
             System.Xml.XmlWriter tmp = System.Xml.XmlWriter.Create(s, setting);
             writer.Serialize(tmp, overview);
         }
     }
     else
     {
         using (Stream s = File.Open(file, FileMode.Truncate))
         {
             System.Xml.XmlWriter tmp = System.Xml.XmlWriter.Create(s, setting);
             writer.Serialize(tmp, overview);
         }
     }
 }
开发者ID:iceriver102,项目名称:alta-mtc-version-2,代码行数:28,代码来源:AltaCache.cs


示例19: LoadFromFile

		void LoadFromFile()
		{
			var reader = new System.Xml.Serialization.XmlSerializer(typeof(List<string>));
			var file = new System.IO.StreamReader(@"words.xml");
			words = new List<string>();
			words = (List<string>)reader.Deserialize(file);
		}
开发者ID:ahremenkoartem,项目名称:balda-eip382,代码行数:7,代码来源:WordDictionary.cs


示例20: GetParamValue

        /// <summary>
        /// Gets the value of a parameter
        /// </summary>
        /// <param name="o">the parameter</param>
        /// <returns>string or serialised xml representation of the parameter</returns>
        private static string GetParamValue(object o)
        {
            string paramDetails = String.Empty;
            if (o != null)
            {
                try
                {
                    Type t = o.GetType();
                    if (t.IsValueType || t.IsSerializable == false || t.Name == "String")
                    {
                        paramDetails = String.Format("{0} : {1}", t, o);
                    }
                    else
                    {
                        System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(t);
                        using (System.IO.StringWriter sw = new System.IO.StringWriter())
                        {
                            s.Serialize(sw, o);
                            paramDetails = String.Format("{0} : {1}", t, sw);
                        }
                    }
                }
                catch
                {
                    paramDetails = o.ToString();
                }
            }

            return paramDetails;
        }
开发者ID:ahtisam,项目名称:TechDevelopment,代码行数:35,代码来源:LogUtility.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Xml.XmlDocument类代码示例发布时间:2022-05-24
下一篇:
C# Schema.XmlSchemaSequence类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap