471,330 Members | 1,041 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Binary serialization and generic class


I like to know if there is a way to perform a binary serialization of
the member variables of a generic class.

The code that follow is a my attempt.


using System;

namespace TemplateSerialization
public class GenericType<T>
where T : struct
T val_;

public void Store(System.IO.BinaryWriter bw)
bw.Write(val_); // ERROR: Argument'1': cannot convert from 'T'
to 'bool'

class Program
static void Main(string[] args)
GenericType<int> MyVal = new GenericType<int>();

System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms);
Jan 4 '06 #1
0 1002

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ching-Lung | last post: by
15 posts views Thread by Jacques | last post: by
reply views Thread by crazyone | last post: by
2 posts views Thread by shapper | last post: by
12 posts views Thread by =?Utf-8?B?enRSb24=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.