本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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();
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}