本文整理汇总了C#中System.Runtime.Serialization.DataContractSerializer类的典型用法代码示例。如果您正苦于以下问题:C# System.Runtime.Serialization.DataContractSerializer类的具体用法?C# System.Runtime.Serialization.DataContractSerializer怎么用?C# System.Runtime.Serialization.DataContractSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Runtime.Serialization.DataContractSerializer类属于命名空间,在下文中一共展示了System.Runtime.Serialization.DataContractSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TranslateMethod
private string TranslateMethod(string authToken, string text)
{
string translation = string.Empty;
string from = "en";
string to = "ja";
string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text="
+ System.Web.HttpUtility.UrlEncode(text) + "&from=" + from + "&to=" + to;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Headers.Add("Authorization", authToken);
WebResponse response = null;
try
{
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
System.Runtime.Serialization.DataContractSerializer dcs =
new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
translation = (string)dcs.ReadObject(stream);
}
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
}
return translation;
}
开发者ID:moyoron64,项目名称:eyeX,代码行数:33,代码来源:TranslatorApi.cs
示例2: TranslateMethod
public static string TranslateMethod(string authToken, string originalS, string from, string to)
{
string text = originalS; //"你能听见我";
//string from = "en";
//string to = "zh-CHS";
//string from = Constants.from;// "zh-CHS";
//string to = Constants.to; // "en";
string transuri = ConstantParam.ApiUri + System.Net.WebUtility.UrlEncode(text) + "&from=" + from + "&to=" + to;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(transuri);
// httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Headers["Authorization"] = authToken;
//httpWebRequest.Method = "GET";
string trans;
Task<WebResponse> response = httpWebRequest.GetResponseAsync();
using (Stream stream = response.Result.GetResponseStream())
{
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
//DataContractJsonSerializer dcs = new DataContractJsonSerializer(Type.GetType("System.String"));
trans = (string)dcs.ReadObject(stream);
return trans;
}
}
开发者ID:WinkeyWang,项目名称:SRTranslator,代码行数:27,代码来源:Translator.cs
示例3: Translate
public override string Translate(string text)
{
string result = "nothing yet...";
Stream stream = null;
try
{
using (stream = GetResponse(text).GetResponseStream())
{
var dataContractSerializer
= new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
result = (string) dataContractSerializer.ReadObject(stream);
}
}
catch (WebException e)
{
result = e.Message;
}
finally
{
if (stream != null)
{
stream.Dispose();
}
}
return result;
}
开发者ID:mauriliofilho,项目名称:SelectAndTranslate,代码行数:29,代码来源:BingTranslator.cs
示例4: Deserialize
public object Deserialize(string serializedObject, Type type)
{
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(serializedObject)))
{
var serializer = new System.Runtime.Serialization.DataContractSerializer(type, null, Int32.MaxValue, false, false, null, _dataContractResolver);
return serializer.ReadObject(memoryStream);
}
}
开发者ID:AtmosphereMessaging,项目名称:Cumulus,代码行数:9,代码来源:DataContractSerializer.cs
示例5: using
/// <summary>
/// Creates a new object that is a copy of the current instance.
/// </summary>
/// <returns>
/// A new object that is a copy of this instance.
/// </returns>
object ICloneable.Clone()
{
var serializer = new System.Runtime.Serialization.DataContractSerializer(GetType());
using (var ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, this);
ms.Position = 0;
return serializer.ReadObject(ms);
}
}
开发者ID:Tony-Liang,项目名称:RBAC,代码行数:16,代码来源:EntityBase.cs
示例6: GetXml
internal static string GetXml(object o) {
var formatter = new System.Runtime.Serialization.DataContractSerializer(o.GetType());
using (var stringWriter = new StringWriter())
using (var xmlWriter = new XmlTextWriter(stringWriter)) {
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.QuoteChar = '\'';
formatter.WriteObject(xmlWriter, o);
return stringWriter.ToString();
}
}
开发者ID:Prover,项目名称:Prover.SpecWriter,代码行数:10,代码来源:DataContractFormatter.cs
示例7: TestSer
public void TestSer()
{
var f = new SomeTestingViewModel() { Result="hahahaha"};
var dx = new System.Runtime.Serialization.DataContractSerializer(typeof(SomeTestingViewModel));
var s = new MemoryStream();
dx.WriteObject(s, f);
s.Position = 0;
var s2 = dx.ReadObject(s) as SomeTestingViewModel;
Assert.AreEqual(s2.Result, f.Result);
}
开发者ID:taojunfeng,项目名称:MVVM-Sidekick,代码行数:11,代码来源:SerTest.cs
示例8: InternalLoadSnapshotAsync
internal async Task<IEnumerable> InternalLoadSnapshotAsync()
{
var f = await workingFile;
var sl = new System.Runtime.Serialization.DataContractSerializer(typeof(PicLibFolder[]));
var ms = new MemoryStream();
using (var inps = (await f.OpenReadAsync()).GetInputStreamAt(0).AsStreamForRead())
{
await inps.CopyToAsync(ms);
ms.Position = 0;
}
var r = sl.ReadObject(ms) as PicLibFolder[];
return r;
}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:13,代码来源:PicLibFolderScanService.cs
示例9: ToBinary
/// <summary>
/// Returns a byte array that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>A byte array that represents the current <see cref="T:System.Object"/>.</returns>
public virtual byte[] ToBinary()
{
byte[] buffer;
using (var ms = new System.IO.MemoryStream())
using (var writer = System.Xml.XmlDictionaryWriter.CreateBinaryWriter(ms))
{
var serializer = new System.Runtime.Serialization.DataContractSerializer(GetType());
serializer.WriteObject(writer, this);
writer.Flush();
buffer = ms.ToArray();
}
return buffer;
}
开发者ID:Tony-Liang,项目名称:RBAC,代码行数:17,代码来源:EntityBase.cs
示例10: DataContractDeserialize
public static object DataContractDeserialize(string buffer, bool compress)
{
if (!string.IsNullOrEmpty(buffer))
{
int idx = buffer.IndexOf('@');
string assemblyQualifiedName = buffer.Substring(0, idx);
string objBuffer = buffer.Substring(idx + 1);
Type objType = Type.GetType(assemblyQualifiedName, true);
System.Runtime.Serialization.DataContractSerializer aa = new System.Runtime.Serialization.DataContractSerializer(objType);
XmlReader reader = XmlReader.Create(new StringReader(objBuffer));
return aa.ReadObject(reader);
}
else
return null;
}
开发者ID:shelgaerel,项目名称:MobileApplication,代码行数:16,代码来源:Utility.cs
示例11: TranslateString
/// <summary>
/// Used to perform the actual translation
/// </summary>
/// <param name="InputString"></param>
/// <returns></returns>
public override string TranslateString(string InputString)
{
Console.WriteLine("Processing: " + InputString);
string result = "";
using (WebClient client = new WebClient())
{
using (Stream data = client.OpenRead(this.BuildRequestString(InputString)))
{
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
result = (string)dcs.ReadObject(data);
data.Close();
}
}
return result;
}
开发者ID:chrislbennett,项目名称:AndroidTranslator,代码行数:23,代码来源:MicrosoftAPI.cs
示例12: GetLanguageNames
public static string[] GetLanguageNames(string[] languageCodes)
{
string uri = "http://api.microsofttranslator.com/v2/Http.svc/GetLanguageNames?locale=" + languageCodes[0] + "&appId=" + appId;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.ContentType = "text/xml";
httpWebRequest.Method = "POST";
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String[]"));
using (System.IO.Stream stream = httpWebRequest.GetRequestStream())
{
dcs.WriteObject(stream, languageCodes);
}
WebResponse response = null;
try
{
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
return (string[])dcs.ReadObject(stream);
}
}
catch (WebException)
{
if (languageCodes.Length == 1 && languageCodes[0] == "en")
return new string[] { "English" };
else
throw;
}
catch
{
throw;
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
}
}
开发者ID:cchitsiang,项目名称:Multi-Lingual-Chat,代码行数:41,代码来源:BingServicesClient.cs
示例13: Serialize
public string Serialize(object serializableObject)
{
using (var memoryStream = new MemoryStream())
{
var serializer = new System.Runtime.Serialization.DataContractSerializer(serializableObject.GetType(),
null,
Int32.MaxValue,
false,
false,
null,
_dataContractResolver);
serializer.WriteObject(memoryStream, serializableObject);
memoryStream.Seek(0, SeekOrigin.Begin);
using (var streamReader = new StreamReader(memoryStream))
{
return streamReader.ReadToEnd();
}
}
}
开发者ID:AtmosphereMessaging,项目名称:Cumulus,代码行数:21,代码来源:DataContractSerializer.cs
示例14: DataContractSerialize
public static string DataContractSerialize(Object obj, bool compress)
{
if (obj != null)
{
Type objType = obj.GetType();
System.Runtime.Serialization.DataContractSerializer aa = new System.Runtime.Serialization.DataContractSerializer(objType);
StringBuilder sb = new StringBuilder();
// Inserisce l'assembly qualified name nello stream del buffer come primo elemento separato dalla @
sb.Append(objType.AssemblyQualifiedName);
sb.Append('@');
XmlWriter writer = XmlWriter.Create(sb);
aa.WriteObject(writer, obj);
writer.Close();
return sb.ToString();
}
else
return null;
}
开发者ID:shelgaerel,项目名称:MobileApplication,代码行数:21,代码来源:Utility.cs
示例15: TranslateMethod
public static string TranslateMethod(string authToken, string originalS, string from, string to)
{
string text = originalS;
string transuri = ConstantParam.ApiUri + System.Net.WebUtility.UrlEncode(text) + "&from=" + from + "&to=" + to;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(transuri);
httpWebRequest.Headers["Authorization"] = authToken;
string trans;
Task<WebResponse> response = httpWebRequest.GetResponseAsync();
using (Stream stream = response.Result.GetResponseStream())
{
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
trans = (string)dcs.ReadObject(stream);
return trans;
}
}
开发者ID:abhaybagai,项目名称:DataCultureSeries,代码行数:21,代码来源:Translator.cs
示例16: GetObjectByType
/// <summary> Get object from isolated storage file.</summary>
/// <param name="fullpath"> file name to retreive</param>
/// <param name="type"> type of object to read</param>
/// <returns> a <c>object</c> instance, or null if the operation failed.</returns>
private async Task<object> GetObjectByType(string filepath, Type type)
{
object retVal = null;
try
{
using (var releaser = await internalManifestDiskLock.ReaderLockAsync())
{
System.Diagnostics.Debug.WriteLine(string.Format("{0:d/M/yyyy HH:mm:ss.fff}", DateTime.Now) + " internalManifestDiskLock Reader Enter for Uri: " + filepath.ToString());
byte[] bytes = await Restore(filepath);
if (bytes != null)
{
try
{
using (MemoryStream ms = new MemoryStream(bytes))
{
if (ms != null)
{
System.Runtime.Serialization.DataContractSerializer ser = new System.Runtime.Serialization.DataContractSerializer(type);
retVal = ser.ReadObject(ms);
}
}
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine(string.Format("{0:d/M/yyyy HH:mm:ss.fff}", DateTime.Now) + " internalManifestDiskLock Reader Exception for Uri: " + filepath.ToString() + " Exception: " + e.Message);
}
}
System.Diagnostics.Debug.WriteLine(string.Format("{0:d/M/yyyy HH:mm:ss.fff}", DateTime.Now) + " internalManifestDiskLock Reader Exit for Uri: " + filepath.ToString());
}
}
catch(Exception)
{
}
return retVal;
}
开发者ID:flecoqui,项目名称:Windows10,代码行数:43,代码来源:DiskCache.cs
示例17: Search1Delegate
public void Search1Delegate(object frpair)
{
FederateRecord fr = ((SearchStart)frpair).fed;
List<SearchResult> results = ((SearchStart)frpair).results;
string terms = ((SearchStart)frpair).terms;
System.Net.WebClient wc = GetWebClient();
wc.Headers["Authorization"] = ((SearchStart)frpair).Authorization;
System.Runtime.Serialization.DataContractSerializer xmls = new System.Runtime.Serialization.DataContractSerializer(typeof(List<SearchResult>));
if (fr.ActivationState == FederateState.Active && fr.AllowFederatedSearch == true)
{
try
{
byte[] data = wc.DownloadData(fr.RESTAPI + "/Search/" + terms + "/xml?ID=00-00-00");
List<SearchResult> fed_results = (List<SearchResult>)xmls.ReadObject(new MemoryStream(data));
lock (((System.Collections.IList)results).SyncRoot)
{
foreach (SearchResult sr in fed_results)
results.Add(sr);
}
}
catch (System.Exception e)
{
// throw e;
fr.ActivationState = FederateState.Offline;
mFederateRegister.UpdateFederateRecord(fr);
return;
}
}
}
开发者ID:jamjr,项目名称:3D-Repository,代码行数:34,代码来源:3DR_Federation_Impl.cs
示例18: DataContractSerializerWorker
public DataContractSerializerWorker(Type t)
{
Serializer = new DCSerializer(t);
}
开发者ID:JornWildt,项目名称:Xyperico,代码行数:4,代码来源:DataContractSerializerWorker.cs
示例19: OnSaveAs
private void OnSaveAs(object sender, ExecuteEventArgs e)
{
using (SaveFileDialog dialog = new SaveFileDialog())
{
dialog.Filter = "Shader file (*.sh)|*.sh|All files (*.*)|*.*";
dialog.FilterIndex = 0;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
using (var stream = dialog.OpenFile())
{
using (var xmlStream = new System.IO.MemoryStream())
{
var nodeGraph = ModelConversion.ToShaderPatcherLayer(graphControl);
var serializer = new System.Runtime.Serialization.DataContractSerializer(
typeof(ShaderPatcherLayer.NodeGraph));
var settings = new System.Xml.XmlWriterSettings()
{
Indent = true,
IndentChars = "\t",
Encoding = System.Text.Encoding.ASCII
};
// write the xml to a memory stream to begin with
using (var writer = System.Xml.XmlWriter.Create(xmlStream, settings))
{
serializer.WriteObject(writer, nodeGraph);
}
// we hide the memory stream within a comment, and write
// out a hlsl shader file
// The HLSL compiler doesn't like UTF files... It just wants plain ASCII encoding
using (var sw = new System.IO.StreamWriter(stream, System.Text.Encoding.ASCII))
{
var shader = ShaderPatcherLayer.NodeGraph.GenerateShader(nodeGraph, System.IO.Path.GetFileNameWithoutExtension(dialog.FileName));
sw.Write(shader);
sw.Write("/* **** **** NodeEditor **** **** \r\nNEStart{");
sw.Flush();
xmlStream.WriteTo(stream);
sw.Write("}NEEnd\r\n **** **** */\r\n");
}
}
}
}
}
}
开发者ID:ldh9451,项目名称:XLE,代码行数:50,代码来源:ExampleForm.cs
示例20: RestoreMediaFilesAsync
async private Task RestoreMediaFilesAsync()
{
string fullPath = "mediafiles.xml";
ulong size = 0;
try
{
Windows.Storage.StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fullPath);
if (file != null)
{
var prop = await file.GetBasicPropertiesAsync();
if (prop != null)
size = prop.Size;
}
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
if (stream != null)
{
using (var inputStream = stream.GetInputStreamAt(0))
{
System.Runtime.Serialization.DataContractSerializer sessionSerializer = new System.Runtime.Serialization.DataContractSerializer(typeof(Dictionary<string, MediaLibraryItem>));
defaultMediaDictionary = (Dictionary<string, MediaLibraryItem>)sessionSerializer.ReadObject(inputStream.AsStreamForRead());
fileDiscovered = (uint)defaultMediaDictionary.Count();
}
}
}
catch (Exception e)
{
LogMessage("Exception while restoring mediafiles:" + e.Message);
}
}
开发者ID:flecoqui,项目名称:Windows10,代码行数:29,代码来源:MainPage.xaml.cs
注:本文中的System.Runtime.Serialization.DataContractSerializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论