本文整理汇总了C#中System.Xml.Serialization.XmlSerializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.Serialization.XmlSerializer.Deserialize方法的具体用法?C# System.Xml.Serialization.XmlSerializer.Deserialize怎么用?C# System.Xml.Serialization.XmlSerializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSerializer
的用法示例。
在下文中一共展示了System.Xml.Serialization.XmlSerializer.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeSerialize
public static object DeSerialize(string sXML, Type ObjectType)
{
System.IO.StringReader oStringReader = null;
System.Xml.Serialization.XmlSerializer oXmlSerializer = null;
object oObject = null;
// -----------------------------------------------------------------------------------------------------------------------
// Hvis mangler info, lage tom
// -----------------------------------------------------------------------------------------------------------------------
if (sXML == string.Empty)
{
Type[] types = new Type[-1 + 1];
System.Reflection.ConstructorInfo info = ObjectType.GetConstructor(types);
object targetObject = info.Invoke(null);
if (targetObject == null)
return null;
return targetObject;
}
// -----------------------------------------------------------------------------------------------------------------------
// Gjøre om fra XML til objekt
// -----------------------------------------------------------------------------------------------------------------------
oStringReader = new System.IO.StringReader(sXML);
oXmlSerializer = new System.Xml.Serialization.XmlSerializer(ObjectType);
oObject = oXmlSerializer.Deserialize(oStringReader);
return oObject;
}
示例2: 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;
}
示例3: Deserialize
public static object Deserialize(string xmlContent, string serializerType)
{
object returnValue = null;
SerializerTypes serializerTypeValue;
Type instanceType;
GetSerializerDetails(serializerType, out serializerTypeValue, out instanceType);
if (serializerTypeValue == SerializerTypes.XmlSerializer)
{
StringReader sww = new StringReader(xmlContent);
XmlReader reader = XmlReader.Create(sww);
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(instanceType);
returnValue = serializer.Deserialize(reader);
}
else if (serializerTypeValue == SerializerTypes.XmlObjectSerializer)
{
XmlObjectSerializer serializer = new XmlObjectSerializer();
returnValue = serializer.Deserialize(xmlContent, true);
}
else
{
if (instanceType == typeof(string))
{
returnValue = xmlContent;
}
else
{
var method = instanceType.GetMethod("Parse", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
returnValue = method.Invoke(null, new object[] { xmlContent });
}
}
return returnValue;
}
示例4: 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;
}
示例5: 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;
}
示例6: Install
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<Project>().UsingFactoryMethod<Project>(kernel => {
var args = Environment.GetCommandLineArgs();
var assembler = kernel.Resolve<ProjectAssembler>();
var deserializer = new System.Xml.Serialization.XmlSerializer(typeof(ProjectDTO));
ProjectDTO dto = null;
try
{
using (TextReader reader = new StreamReader(args[1]))
dto = (ProjectDTO)deserializer.Deserialize(reader);
}
catch (Exception ex)
{
// halt application (not currently in a message loop)
// TODO: need to inform the user that we couldn't load the project: this is why
// we shouldn't have this logic in the installer, we need to farm it out to something
// else (plus we'll get a more responsive application as it'll load the UI immediately)
Environment.Exit(-1);
}
return assembler.Restore(dto);
}),
Component.For<IConfiguration>()
.UsingFactoryMethod<IConfiguration>(kernel => kernel.Resolve<Project>().Configuration),
Component.For<IList<ISubject>>()
.UsingFactoryMethod(kernel => kernel.Resolve<IConfiguration>())
);
}
示例7: InitializeTwitter
public void InitializeTwitter()
{
try
{
System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(saveSettings));
System.IO.FileStream fs = new System.IO.FileStream(
@"settings.xml", System.IO.FileMode.Open);
saveSettings setting = (saveSettings)serializer.Deserialize(fs);
fs.Close();
textBox1.Enabled = false;
//accToken = setting.AccToken;
token.AccessToken = setting.AccToken;
//accTokenSec = setting.AccTokenSec;
token.AccessTokenSecret = setting.AccTokenSec;
var Stream = new TwitterStream(token, "Feedertter", null);
StatusCreatedCallback statusCreatedCallback = new StatusCreatedCallback(StatusCreatedCallback);
RawJsonCallback rawJsonCallback = new RawJsonCallback(RawJsonCallback);
Stream.StartUserStream(null, null,
/*(x) => { label1.Text += x.Text; }*/
statusCreatedCallback,
null, null, null, null, rawJsonCallback);
}
catch
{
Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
}
//Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
}
示例8: Evaluate
// called after the authentication stage
public bool Evaluate(EvaluationContext evaluationContext, ref object state)
{
IList<IIdentity> idents;
object identsObject;
if (evaluationContext.Properties.TryGetValue(
"Identities", out identsObject) && (idents =
identsObject as IList<IIdentity>) != null)
{
foreach (IIdentity ident in idents)
{
if (ident.IsAuthenticated &&
ident.AuthenticationType == "BiometricValidator")
{
StringReader reader = new StringReader(ident.Name);
System.Xml.Serialization.XmlSerializer deserializer = new System.Xml.Serialization.XmlSerializer(typeof(SecureContextCredentials));
SecureContextCredentials credentials = (SecureContextCredentials)deserializer.Deserialize(reader);
IdsIdentity i = new IdsIdentity(ident.IsAuthenticated, AuthenticationType.Bioemtrics, credentials.IdentityUid);
IdsPrincipal p = new IdsPrincipal(i, new List<string> { "LoggedIn" });
evaluationContext.Properties["Principal"] = p;
return true;
}
else
{
string userId = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("userId", "http://www.identitystream.com");
IdsIdentity i = new IdsIdentity(ident.IsAuthenticated, AuthenticationType.Certificate, userId);
IdsPrincipal p = new IdsPrincipal(i, new List<string> { "LoggedIn" });
evaluationContext.Properties["Principal"] = p;
return true;
}
}
}
return false;
}
示例9: FromString
public static User FromString(String XmlString, ref string TargetString)
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(User));
MemoryStream memoryStream = new MemoryStream(Serialize.StringToUTF8ByteArray(XmlString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return (User)xs.Deserialize(memoryStream);
}
示例10: GetEntityData
public object GetEntityData(Type entityType, StreamReader reader)
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(entityType);
object obj = serializer.Deserialize(reader);
return obj;
}
示例11: MainWindow
public MainWindow()
{
InitializeComponent();
List<CsvDataTable> myList = new List<CsvDataTable>() { };
///起動時にデータベースがあるかどうか。無ければ作成する
if (System.IO.File.Exists(db_file)){}
else
{
createDataBase();
}
///起動時にXMLがあるかどうか。あれば読み込む
if (System.IO.File.Exists(SaveDataPath))
{
//XmlSerializerオブジェクトを作成
System.Xml.Serialization.XmlSerializer serializer =new System.Xml.Serialization.XmlSerializer(typeof(TreeViewClass));
//読み込むファイルを開く
System.IO.StreamReader sr = new System.IO.StreamReader(SaveDataPath, new System.Text.UTF8Encoding(false));
//XMLファイルから読み込み、逆シリアル化する
root_ = (TreeViewClass)serializer.Deserialize(sr);
//ファイルを閉じる
sr.Close();
///ステータスバーに次の指示を描写
StatusLabel.Content = "TreeViewの項目をクリックすることでCSVDataViewにデータを表示することが出来ます";
}else{
root_ = new TreeViewClass("root");
}
///root_をXAMLから読み込ませるためにDataContextを使用
DataContext = root_;
dataGrid1.ItemsSource = GetDataBaseTable(myList).DefaultView;
}
示例12: Load
public virtual void Load(string filename)
{
System.Xml.Serialization.XmlSerializer serialize = new System.Xml.Serialization.XmlSerializer(this.GetType());
System.IO.StreamReader sr = new System.IO.StreamReader(filename, new System.Text.UTF8Encoding(false));
this.setData((AData)serialize.Deserialize(sr));
sr.Close();
}
示例13: Main
static void Main()
{
/// <summary>
/// XML設定ファイル
/// </summary>
const string FILE_NAME = @"homeAppManager.xml";
try
{
using (System.IO.TextReader reader = new System.IO.StreamReader(FILE_NAME, Encoding.UTF8, false))
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Config));
Config.init = (Config)serializer.Deserialize(reader);
}
}
catch (System.IO.FileNotFoundException ex)
{
//XmlSerializerオブジェクトを作成
using (System.IO.TextWriter writer = new System.IO.StreamWriter(FILE_NAME, false, Encoding.UTF8))
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(Config.init.GetType());
serializer.Serialize(writer, Config.init);
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frm_Main());
}
示例14: deserializeXml
public static object deserializeXml(byte[] xmldata)
{
if (!validateXml(xmldata))
{
return null;
}
MemoryStream ms = new MemoryStream();
ms.Read(xmldata, 0, xmldata.Length);
XDocument doc = XDocument.Load(ms);
string msgtype = doc.Root.Attribute("messageType").Value;
object msg = null;
switch (msgtype)
{
case "register":
msg = new registerMessageType();
break;
case "login":
break;
case "newfile":
break;
case "filepatch":
break;
case "filecontent":
break;
}
StreamReader sr = new StreamReader(ms);
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(msg.GetType());
msg = xs.Deserialize(sr);
return msg;
}
示例15: 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;
}