Hi,
I need save to text file a List<type>, but i dont wont serialize.
//
List<mytypemyList = new List<mytype>();
anyone can help me?
--
Best regards,
A.Rocha 6 14424
List<won't serialize. You need to write some code to manually serialize
it.
Something like :
MyList<T: List<T>
{
#region Manual serialization
public virtual void GetObjectData(SerializationInfo info,
StreamingContext context)
{
int i = 0;
info.AddValue("num", this.Count);
foreach (T item in this)
{
info.AddValue("item" + i.ToString(), item);
++i;
}
}
protected MyList(SerializationInfo info, StreamingContext context)
{
int num = info.GetInt32("num");
for (int i = 0; i < num; ++i)
{
T item = (T)info.GetValue("item" + i.ToString(), typeof(T));
base.Add(item);
}
}
#endregion Manual serialization
}
HTH,
Adam,
=========
"A.Rocha" <ar**********@ifthensoftware.comwrote in message
news:89**********************************@microsof t.com...
Hi,
I need save to text file a List<type>, but i dont wont serialize.
//
List<mytypemyList = new List<mytype>();
anyone can help me?
--
Best regards,
A.Rocha
I personally would not serialize the data but rather list it in a text file,
especially if the case assumes that the data can be edited by users outside
the application. The I/O functions would save and read chunks of data (the
List<Trecords).
Some key points we need to know to give an appropriate answer:
- What kind of data does the list store? e.g. proprietary format, text or
binary data
- Do you want the output to be editable by you or your users outside your
program?
--
Stanimir Stoyanov http://stoyanoff.info
"Adam Benson" <Ad*********@NOSPAMMYSPAM.omnibus.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
List<won't serialize. You need to write some code to manually serialize
it.
Something like :
MyList<T: List<T>
{
#region Manual serialization
public virtual void GetObjectData(SerializationInfo info,
StreamingContext context)
{
int i = 0;
info.AddValue("num", this.Count);
foreach (T item in this)
{
info.AddValue("item" + i.ToString(), item);
++i;
}
}
protected MyList(SerializationInfo info, StreamingContext context)
{
int num = info.GetInt32("num");
for (int i = 0; i < num; ++i)
{
T item = (T)info.GetValue("item" + i.ToString(),
typeof(T));
base.Add(item);
}
}
#endregion Manual serialization
}
HTH,
Adam,
=========
"A.Rocha" <ar**********@ifthensoftware.comwrote in message
news:89**********************************@microsof t.com...
>Hi,
I need save to text file a List<type>, but i dont wont serialize.
// List<mytypemyList = new List<mytype>();
anyone can help me?
-- Best regards, A.Rocha
Hi Stanimir ,
//This is my class:
public class Info
{
public long ID;
public string A;
public float B;
public float C;
public int D;
public float E;
public string F;
public float G;
public string H;
public short I;
public Info(){ }
public Info(long ID, string A, float B, float C, int D, float E,
string F, float G, string H, short I)
{
this.ID= ID;
this.A= A;
this.B= B;
this.C= C;
this.D= D;
this.E= E;
this.F= F;
this.G= G;
this.H= H;
this.I= I;
}
}
//this is my List<Info>
List<InfoaInfo= new List<Info>();
//i add several items to List
aInfo.Add(new cInfoPOS(ID, A, B, C, D, E, F, G, H, I));
....
....
Now i want to save this in text file. The output is only edited by the
program.
Thanks for any help.
--
Best regards,
A.Rocha
(Portugal)
"Stanimir Stoyanov" <st******@REMOVETHIS.live.comescreveu na mensagem
news:16**********************************@microsof t.com...
>I personally would not serialize the data but rather list it in a text file, especially if the case assumes that the data can be edited by users outside the application. The I/O functions would save and read chunks of data (the List<Trecords).
Some key points we need to know to give an appropriate answer:
- What kind of data does the list store? e.g. proprietary format, text or
binary data
- Do you want the output to be editable by you or your users outside your
program?
--
Stanimir Stoyanov http://stoyanoff.info
"Adam Benson" <Ad*********@NOSPAMMYSPAM.omnibus.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>List<won't serialize. You need to write some code to manually serialize it.
Something like :
MyList<T: List<T> {
#region Manual serialization public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { int i = 0; info.AddValue("num", this.Count); foreach (T item in this) { info.AddValue("item" + i.ToString(), item); ++i; } }
protected MyList(SerializationInfo info, StreamingContext context) { int num = info.GetInt32("num"); for (int i = 0; i < num; ++i) { T item = (T)info.GetValue("item" + i.ToString(), typeof(T)); base.Add(item); } } #endregion Manual serialization }
HTH,
Adam, =========
"A.Rocha" <ar**********@ifthensoftware.comwrote in message news:89**********************************@microso ft.com...
>>Hi,
I need save to text file a List<type>, but i dont wont serialize.
// List<mytypemyList = new List<mytype>();
anyone can help me?
-- Best regards, A.Rocha
"A.Rocha" <ar**********@ifthensoftware.comwrote in message
news:89**********************************@microsof t.com...
I need save to text file a List<type>, but i dont wont serialize.
The last part of that sentence is unclear. Did you misspell "want," and you
meant to say "I don't want to use serialization"? Or did you mean "it won't
serialize"?
If you don't want to use .NET's serialization then you're going to have to
write the values in your class manually, using either a BinaryWriter or a
StreamWriter. The choice will depend on whether you want all your data to be
in plain text or a more compact binary format.
"Adam Benson" <Ad*********@NOSPAMMYSPAM.omnibus.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
List<won't serialize. You need to write some code to manually serialize
it.
Why wouldn't it serialize? List<Tis marked as Serializable. It should
serialize with no problem, on the condition that the class "T" is itself
marked as Serializable.
Another alternative is to use the XmlSerializer, which will produce a
nicely strutured XML text file from a List<Info>, given the "Info" class
that the OP has shown in a separate message.
Hi,
sorry for only now i tell you that, but i'm working on compact framework 3.5
on windows Mobile 6.0, that's why i can't marke it as Serializable.
Thanks.
--
Best regards,
A.Rocha
(Portugal)
"Jeff Johnson" <i.***@enough.spamescreveu na mensagem
news:%2***************@TK2MSFTNGP05.phx.gbl...
"A.Rocha" <ar**********@ifthensoftware.comwrote in message
news:89**********************************@microsof t.com...
>I need save to text file a List<type>, but i dont wont serialize.
The last part of that sentence is unclear. Did you misspell "want," and
you meant to say "I don't want to use serialization"? Or did you mean "it
won't serialize"?
If you don't want to use .NET's serialization then you're going to have to
write the values in your class manually, using either a BinaryWriter or a
StreamWriter. The choice will depend on whether you want all your data to
be in plain text or a more compact binary format. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rainer Queck |
last post by:
Hi NG,
I have a base class "Telegram". This class , as well as all descants have a
static public field "public static int TelegramNo = <a tlg no>;"
Now I added all descants of Telegram to a...
|
by: Sean |
last post by:
I have been using List(of String) when I could easily be using a string array
instead.
Is it still considered best practice to use Generic list of string rather
then a string array?
Thanks
|
by: Web learner |
last post by:
The following code works fine
private List<double> GetDataFor(string column, int selectedYear) {
-------
-------
return list;
}
foreach (double item in GetDataFor("AirTemp", selectedYear))...
|
by: Rene |
last post by:
According to the documentation, the List<T> type explicitly implements the
non generic IList interface.
The problem is that no matter how hard I look, I am not able to find this
implemetion on...
|
by: Murat Ozgur |
last post by:
Hello,
Is there any difference between ArrayList and List<object? Which
one should I use ?
Thanks.
|
by: daokfella |
last post by:
I have a business object that exposes a collection of other objects
via a List<of Type>. How can I intercept when an item is either added
or removed from this list. Is it possible?
private...
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I have a list of type object. The object has an ID as one of the elements
and I would like to create another list that just has objects with unique IDs.
For example
in the list if I have...
|
by: Berryl Hesh |
last post by:
Converting in the other direction , IEnumerable<Interfaceto
List<ImplInterface>, I can just create a new List<ImplInterface(data)
where data is IEnumerable<Interface>.
How can I convert the...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
| |