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


C# Serialization.XmlSerializer类代码示例

本文整理汇总了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类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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