本文整理汇总了C#中ObjectWriter类的典型用法代码示例。如果您正苦于以下问题:C# ObjectWriter类的具体用法?C# ObjectWriter怎么用?C# ObjectWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectWriter类属于命名空间,在下文中一共展示了ObjectWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WriteChild
protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
{
if (writer.Format == FileFormat.Glade || Type == ButtonType.Custom)
return base.WriteChild (writer, wrapper);
else
return null;
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:Button.cs
示例2: WriteChild
protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
{
XmlElement child_elem = base.WriteChild (writer, wrapper);
if (tabs.Contains (wrapper.Wrapped))
GladeUtils.SetChildProperty (child_elem, "type", "tab");
return child_elem;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:7,代码来源:Notebook.cs
示例3: WriteTo
public override void WriteTo(Encoding encoding, ObjectWriter writer, CancellationToken cancellationToken)
{
if (encoding == null)
{
base.WriteTo(encoding, writer, cancellationToken);
return;
}
cancellationToken.ThrowIfCancellationRequested();
writer.WriteByte(EncodingSerialization);
byte[] value;
if (!s_encodingCache.TryGetValue(encoding, out value))
{
// we don't have cache, cache it
var formatter = new BinaryFormatter();
using (var stream = SerializableBytes.CreateWritableStream())
{
// unfortunately, this is only way to properly clone encoding
formatter.Serialize(stream, encoding);
value = stream.ToArray();
// add if not already exist. otherwise, noop
s_encodingCache.TryAdd(encoding, value);
}
}
// write data out
writer.WriteValue(value);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:31,代码来源:DesktopReferenceSerializationServiceFactory.cs
示例4: WriteChild
protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
{
XmlElement child_elem = base.WriteChild (writer, wrapper);
if (wrapper.Wrapped == expander.LabelWidget)
GladeUtils.SetChildProperty (child_elem, "type", "label_item");
return child_elem;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:7,代码来源:Expander.cs
示例5: TestStringFragment
/// <exception cref="System.Exception"></exception>
public virtual void TestStringFragment()
{
string fragment = "01234567890";
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(fragment, jsdoc.JsonObject());
}
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:9,代码来源:JsonDocumentTest.cs
示例6: WriteProperties
protected override XmlElement WriteProperties (ObjectWriter writer)
{
XmlElement elem = base.WriteProperties (writer);
string group = GroupManager.GladeGroupName (Wrapped);
if (group != Wrapped.Name)
GladeUtils.SetProperty (elem, "group", group);
return elem;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:8,代码来源:RadioToolButton.cs
示例7: Write
public void Write(ObjectWriter writer)
{
writer.PrimitiveWriter.Write(Name);
writer.PrimitiveWriter.Write(Version);
writer.PrimitiveWriter.Write(CultureName);
writer.PrimitiveWriter.Write((byte)Token.Length);
writer.PrimitiveWriter.Write(Token);
}
开发者ID:StepWoodProductions,项目名称:Migrant,代码行数:8,代码来源:AssemblyDescriptor.cs
示例8: Main
static void Main(string[] args)
{
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Loopback, 4040);
Socket ss = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var productos = new ObservableCollection<Producto>();
for (int i = 0; i < 20; i++)
{
productos.Add(new Producto()
{
ProductId = i,
Nombre = "Producto servidor" + i,
Precio = (decimal)i,
CantidadDisponible = i * 10,
Descripcion = "The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. Usually it is best to"
});
}
try
{
ss.Bind(localEndPoint);
ss.Listen(10);
while (true)
{
Console.WriteLine("Servidor escuchando por conexiones");
Socket cliente = ss.Accept();
string descCliente = cliente.LocalEndPoint.ToString();
Console.WriteLine("Conexion aceptada " + descCliente);
ObjectWriter w = new ObjectWriter(cliente);
ObjectReader r = new ObjectReader(cliente);
Transacciones transaccion = (Transacciones)r.ReadInt32();
switch (transaccion)
{
case Transacciones.SolicitarCarrito:
Console.WriteLine("\tSolicitud de carrito por: " + descCliente);
w.WriteInt32(productos.Count);
for (int i = 0; i < productos.Count; i++)
{
w.WriteObject<Producto>(productos[i]);
}
break;
case Transacciones.RealizarCompra:
Console.WriteLine("\tOrden de compra de " + descCliente);
Orden o = r.ReadObject<Orden>();
productos[o.ProductId].CantidadDisponible -= o.Cantidad;
break;
}
Console.WriteLine("Conexion terminada " + descCliente);
cliente.Shutdown(SocketShutdown.Both);
cliente.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
开发者ID:rokerdan,项目名称:aplicaciones-redes,代码行数:58,代码来源:Program.cs
示例9: WriteProperties
protected override XmlElement WriteProperties (ObjectWriter writer)
{
XmlElement elem = base.WriteProperties (writer);
if (menuInfo != null)
elem.AppendChild (writer.XmlDocument.ImportNode (menuInfo, true));
else
elem.AppendChild (actionTree.Write (writer.XmlDocument, writer.Format));
return elem;
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:9,代码来源:MenuBar.cs
示例10: Write
public override XmlElement Write (ObjectWriter writer)
{
XmlElement group = writer.XmlDocument.CreateElement ("action-group");
group.SetAttribute ("name", name);
if (writer.CreateUndoInfo)
group.SetAttribute ("undoId", UndoId);
foreach (Action ac in actions) {
if (ac.Name.Length > 0)
group.AppendChild (writer.WriteObject (ac));
}
return group;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:12,代码来源:ActionGroup.cs
示例11: Load
private object Load(XamlXmlReader reader)
{
XamlObjectWriter writer = new ObjectWriter();
while (reader.Read())
{
writer.WriteNode(reader);
}
writer.Close();
reader.Close();
if (writer.Result is DependencyObject && !(writer is INameScope))
((DependencyObject)writer.Result).SetValue(NameScope.NameScopeProperty, writer.RootNameScope);
return writer.Result;
}
开发者ID:Kation,项目名称:WebPresentation,代码行数:13,代码来源:XamlReader.cs
示例12: TestJsonArray
/// <exception cref="System.Exception"></exception>
public virtual void TestJsonArray()
{
IList<object> array = new AList<object>();
array.AddItem("01234567890");
array.AddItem("bar");
array.AddItem(5);
array.AddItem(3.5);
array.AddItem(true);
array.AddItem(new DateTime().ToString());
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(array);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(array, jsdoc.JsonObject());
}
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:15,代码来源:JsonDocumentTest.cs
示例13: TestJsonObject
/// <exception cref="System.Exception"></exception>
public virtual void TestJsonObject()
{
IDictionary<string, object> dict = new Dictionary<string, object>();
dict.Put("id", "01234567890");
dict.Put("foo", "bar");
dict.Put("int", 5);
dict.Put("double", 3.5);
dict.Put("bool", true);
dict.Put("date", new DateTime().ToString());
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(dict);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(dict, jsdoc.JsonObject());
}
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:15,代码来源:JsonDocumentTest.cs
示例14: Encode
// create the same JSON encoding used by TouchDB
// this lets us test comparisons as they would be encoded
public virtual string Encode(object obj)
{
ObjectWriter mapper = new ObjectWriter();
try
{
byte[] bytes = mapper.WriteValueAsBytes(obj);
string result = Sharpen.Runtime.GetStringForBytes(bytes);
return result;
}
catch (Exception e)
{
Log.E(Tag, "Error encoding JSON", e);
return null;
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:17,代码来源:CollationTest.cs
示例15: RealizaCompra
public int RealizaCompra(int productId, int cantidad)
{
IPEndPoint remotePoint = new IPEndPoint(IPAddress.Loopback, 4040);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Connect(remotePoint);
ObjectReader r = new ObjectReader(s);
ObjectWriter w = new ObjectWriter(s);
w.WriteInt32((int)Transacciones.RealizarCompra);
Orden o = new Orden { ProductId = productId, Cantidad = cantidad };
w.WriteObject<Orden>(o);
s.Shutdown(SocketShutdown.Both);
s.Close();
return 1;
}
开发者ID:rokerdan,项目名称:aplicaciones-redes,代码行数:15,代码来源:CarritoModel.cs
示例16: ShouldHandleTwoWritesAndReads
public void ShouldHandleTwoWritesAndReads()
{
var strings = new [] { "One", "Two" };
var stream = new MemoryStream();
var writer = new ObjectWriter(stream);
writer.WriteObject(strings[0]);
writer.WriteObject(strings[1]);
var position = stream.Position;
stream.Seek(0, SeekOrigin.Begin);
var reader = new ObjectReader(stream);
Assert.AreEqual(strings[0], reader.ReadObject<string>());
Assert.AreEqual(strings[1], reader.ReadObject<string>());
Assert.AreEqual(position, stream.Position);
}
开发者ID:jpierson,项目名称:Migrant,代码行数:16,代码来源:ObjectReaderWriterTests.cs
示例17: Write
public void Write(ObjectWriter writer)
{
writer.TouchAndWriteTypeId(UnderlyingMethod.ReflectedType);
var methodParameters = UnderlyingMethod.GetParameters();
if(UnderlyingMethod.IsGenericMethod)
{
var genericDefinition = UnderlyingMethod.GetGenericMethodDefinition();
var genericArguments = UnderlyingMethod.GetGenericArguments();
var genericMethodParamters = genericDefinition.GetParameters();
writer.PrimitiveWriter.Write(genericDefinition.Name);
writer.PrimitiveWriter.Write(genericArguments.Length);
for(int i = 0; i < genericArguments.Length; i++)
{
writer.TouchAndWriteTypeId(genericArguments[i]);
}
writer.PrimitiveWriter.Write(genericMethodParamters.Length);
for(int i = 0; i < genericMethodParamters.Length; i++)
{
writer.PrimitiveWriter.Write(genericMethodParamters[i].ParameterType.IsGenericParameter);
if(genericMethodParamters[i].ParameterType.IsGenericParameter)
{
writer.PrimitiveWriter.Write(genericMethodParamters[i].ParameterType.GenericParameterPosition);
}
else
{
writer.TouchAndWriteTypeId(methodParameters[i].ParameterType);
}
}
}
else
{
writer.PrimitiveWriter.Write(UnderlyingMethod.Name);
writer.PrimitiveWriter.Write(0); // no generic arguments
writer.PrimitiveWriter.Write(methodParameters.Length);
foreach(var p in methodParameters)
{
writer.TouchAndWriteTypeId(p.ParameterType);
}
}
}
开发者ID:StepWoodProductions,项目名称:Migrant,代码行数:44,代码来源:MethodDescriptor.cs
示例18: ShouldHandleTwoWritesAndReads
public void ShouldHandleTwoWritesAndReads()
{
var strings = new [] { "One", "Two" };
var stream = new MemoryStream();
var writer = new ObjectWriter(stream, Serializer.GetReflectionBasedWriteMethods());
writer.WriteObject(strings[0]);
writer.WriteObject(strings[1]);
writer.Flush();
var position = stream.Position;
stream.Seek(0, SeekOrigin.Begin);
var reader = new ObjectReader(stream, Serializer.GetReflectionBasedReadMethods(false));
Assert.AreEqual(strings[0], reader.ReadObject<string>());
Assert.AreEqual(strings[1], reader.ReadObject<string>());
reader.Flush();
Assert.AreEqual(position, stream.Position);
}
开发者ID:antmicro,项目名称:Migrant,代码行数:19,代码来源:ObjectReaderWriterTests.cs
示例19: WriteProperties
protected override XmlElement WriteProperties (ObjectWriter writer)
{
XmlElement elem = base.WriteProperties (writer);
if (type != ButtonType.StockItem && imageInfo != null) {
if (writer.Format == FileFormat.Glade) {
switch (imageInfo.Source) {
case ImageSource.File:
GladeUtils.SetProperty (elem, "icon", imageInfo.Name);
break;
case ImageSource.Theme:
GladeUtils.SetProperty (elem, "stock_id", imageInfo.Name);
break;
default:
throw new System.NotSupportedException ("Image source not supported by Glade.");
}
}
}
return elem;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:19,代码来源:ToolButton.cs
示例20: ShouldHandleTwoWritesAndReads
public void ShouldHandleTwoWritesAndReads()
{
var strings = new [] { "One", "Two" };
var typeIndices = new List<Type>
{
typeof(string)
};
var stream = new MemoryStream();
var writer = new ObjectWriter(stream, typeIndices);
writer.WriteObject(strings[0]);
writer.WriteObject(strings[1]);
var position = stream.Position;
stream.Seek(0, SeekOrigin.Begin);
var types = typeIndices.ToArray();
var reader = new ObjectReader(stream, types, false);
Assert.AreEqual(strings[0], reader.ReadObject<string>());
Assert.AreEqual(strings[1], reader.ReadObject<string>());
Assert.AreEqual(position, stream.Position);
}
开发者ID:PiotrZierhoffer,项目名称:Migrant,代码行数:21,代码来源:ObjectReaderWriterTests.cs
注:本文中的ObjectWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论