本文整理汇总了C#中ObjectReader.ReadObject方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectReader.ReadObject方法的具体用法?C# ObjectReader.ReadObject怎么用?C# ObjectReader.ReadObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectReader
的用法示例。
在下文中一共展示了ObjectReader.ReadObject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: ReadChild
protected override ObjectWrapper ReadChild (ObjectReader reader, XmlElement child_elem)
{
if ((string)GladeUtils.GetChildProperty (child_elem, "type", "") == "label_item") {
ObjectWrapper wrapper = reader.ReadObject (child_elem["widget"]);
expander.LabelWidget = (Gtk.Widget)wrapper.Wrapped;
return wrapper;
} else
return base.ReadChild (reader, child_elem);
}
示例4: 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);
}
示例5: ReadChild
protected override ObjectWrapper ReadChild (ObjectReader reader, XmlElement child_elem)
{
if ((string)GladeUtils.GetChildProperty (child_elem, "type", "") == "tab") {
ObjectWrapper wrapper = reader.ReadObject (child_elem["widget"], this);
Gtk.Widget widget = (Gtk.Widget)wrapper.Wrapped;
notebook.SetTabLabel (notebook.GetNthPage (notebook.NPages - 1), widget);
tabs.Add (widget);
return wrapper;
} else
return base.ReadChild (reader, child_elem);
}
示例6: 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);
}
示例7: RecuperaProductos
public ObservableCollection<Producto> RecuperaProductos()
{
var resultado = new ObservableCollection<Producto>();
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.SolicitarCarrito);
int cont = r.ReadInt32();
for (int i = 0; i < cont; i++)
{
Producto p = r.ReadObject<Producto>();
if (p != null)
resultado.Add(p);
}
s.Shutdown(SocketShutdown.Both);
s.Close();
return resultado;
}
示例8: ReadChild
protected override ObjectWrapper ReadChild (ObjectReader reader, XmlElement child_elem)
{
ObjectWrapper wrapper = reader.ReadObject (child_elem["widget"]);
menuitem.Submenu = (Gtk.Menu)wrapper.Wrapped;
return wrapper;
}
示例9: ReadInternalChild
protected virtual ObjectWrapper ReadInternalChild (ObjectReader reader, XmlElement child_elem)
{
ClassDescriptor klass = base.ClassDescriptor;
string childId = child_elem.GetAttribute ("internal-child");
foreach (PropertyDescriptor prop in klass.InternalChildren) {
if (reader.Format == FileFormat.Glade && ((TypedPropertyDescriptor)prop).GladeName != childId)
continue;
else if (reader.Format == FileFormat.Native && prop.Name != childId)
continue;
Gtk.Widget child = prop.GetValue (container) as Gtk.Widget;
Widget wrapper = Widget.Lookup (child);
if (wrapper != null) {
reader.ReadObject (wrapper, child_elem["widget"]);
if (reader.Format == FileFormat.Glade)
GladeUtils.SetPacking (ChildWrapper (wrapper), child_elem);
else
WidgetUtils.SetPacking (ChildWrapper (wrapper), child_elem);
return wrapper;
}
}
// In Glade, internal children may not be direct children of the root container. This is handled in a special way.
if (reader.Format == FileFormat.Glade) {
if (!reader.GladeChildStack.Contains (child_elem))
reader.GladeChildStack.Add (child_elem);
return null;
}
else
throw new GladeException ("Unrecognized internal child name", Wrapped.GetType ().FullName, false, "internal-child", childId);
}
示例10: ReadChild
protected virtual ObjectWrapper ReadChild (ObjectReader reader, XmlElement child_elem)
{
ObjectWrapper wrapper = reader.ReadObject (child_elem["widget"]);
Container.ContainerChild childwrapper = null;
try {
wrapper.Loading = true;
Gtk.Widget child = (Gtk.Widget)wrapper.Wrapped;
AutoSize[child] = false;
container.Add (child);
childwrapper = ChildWrapper ((Widget)wrapper);
if (childwrapper != null)
childwrapper.Loading = true;
if (reader.Format == FileFormat.Glade)
GladeUtils.SetPacking (childwrapper, child_elem);
else
WidgetUtils.SetPacking (childwrapper, child_elem);
return wrapper;
} finally {
wrapper.Loading = false;
if (childwrapper != null)
childwrapper.Loading = false;
}
}
示例11: ReadChild
protected override ObjectWrapper ReadChild (ObjectReader reader, XmlElement child_elem)
{
Widget wrapper = Stetic.Wrapper.Widget.Lookup (optionmenu.Menu);
reader.ReadObject (wrapper, child_elem["widget"]);
return wrapper;
}