Click here to Skip to main content
15,881,248 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why changing the CurrentCulture.DateTimeFormat.ShortTimePattern doesn't affect the DateTime.now format Pin
Member 372226114-Oct-09 20:21
Member 372226114-Oct-09 20:21 
GeneralRe: Why changing the CurrentCulture.DateTimeFormat.ShortTimePattern doesn't affect the DateTime.now format Pin
DaveyM6914-Oct-09 22:33
professionalDaveyM6914-Oct-09 22:33 
GeneralRe: Why changing the CurrentCulture.DateTimeFormat.ShortTimePattern doesn't affect the DateTime.now format Pin
Richard MacCutchan14-Oct-09 22:36
mveRichard MacCutchan14-Oct-09 22:36 
QuestionList Objects to Xml Method Pin
AndyASPVB14-Oct-09 9:08
AndyASPVB14-Oct-09 9:08 
AnswerRe: List Objects to Xml Method Pin
DaveyM6914-Oct-09 9:22
professionalDaveyM6914-Oct-09 9:22 
GeneralRe: List Objects to Xml Method Pin
AndyASPVB14-Oct-09 9:41
AndyASPVB14-Oct-09 9:41 
GeneralRe: List Objects to Xml Method Pin
Not Active14-Oct-09 10:18
mentorNot Active14-Oct-09 10:18 
GeneralRe: List Objects to Xml Method Pin
DaveyM6914-Oct-09 10:20
professionalDaveyM6914-Oct-09 10:20 
I get you but the approach suggested should work...

I tried these two methods (serializing to file but it could be a memory stream or whatever) and it works
C#
public void Serialize<T>(List<T> list)
{
    XmlSerializer xs = new XmlSerializer(typeof(ListHolder<T>));
    using (StreamWriter writer = new StreamWriter(@"c:\test.xml"))
    {
        xs.Serialize(writer, new ListHolder<T>(list));
    }
}
public List<T> DeSerialize<T>()
{
    List<T> result = null;
    XmlSerializer xs = new XmlSerializer(typeof(ListHolder<T>));
    using (FileStream fs = new FileStream(@"c:\test.xml", FileMode.Open))
    {
        XmlReader reader = new XmlTextReader(fs);
        ListHolder<T> listHolder = (ListHolder<T>)xs.Deserialize(reader);
        fs.Close();
        result = listHolder.List;
    }
    return result;
}
Using this supporting class...
C#
public class ListHolder<T>
{
    public ListHolder()
    {
        list = new List<T>();
    }
    public ListHolder(List<T> list)
    {
        this.list = list;
    }

    private List<T> list;

    public List<T> List { get { return list; } }
}
To test I used this code:
C#
List<int> toSerialize = new List<int>(3) { 1, 2, 3 };
Serialize<int>(toSerialize);
List<int> deSerialized = DeSerialize<int>();
The xml file is created perfectly and the list is deserialized perfectly from it too.

Dave

Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

Questionerror sending email using Networkcredential Pin
Jassim Rahma14-Oct-09 8:32
Jassim Rahma14-Oct-09 8:32 
AnswerRe: error sending email using Networkcredential Pin
Abhijit Jana14-Oct-09 8:42
professionalAbhijit Jana14-Oct-09 8:42 
GeneralRe: error sending email using Networkcredential Pin
Jassim Rahma14-Oct-09 9:41
Jassim Rahma14-Oct-09 9:41 
GeneralRe: error sending email using Networkcredential Pin
Abhijit Jana14-Oct-09 17:18
professionalAbhijit Jana14-Oct-09 17:18 
QuestionXML VALIDATION Pin
waqasm14-Oct-09 8:23
waqasm14-Oct-09 8:23 
QuestionC# console application to dll and register..... Pin
greendragons14-Oct-09 8:20
greendragons14-Oct-09 8:20 
AnswerRe: C# console application to dll and register..... Pin
Dave Kreskowiak14-Oct-09 8:28
mveDave Kreskowiak14-Oct-09 8:28 
GeneralRe: C# console application to dll and register..... Pin
greendragons14-Oct-09 8:31
greendragons14-Oct-09 8:31 
GeneralRe: C# console application to dll and register..... Pin
DaveyM6914-Oct-09 8:38
professionalDaveyM6914-Oct-09 8:38 
GeneralRe: C# console application to dll and register..... Pin
greendragons14-Oct-09 8:46
greendragons14-Oct-09 8:46 
GeneralRe: C# console application to dll and register..... Pin
Dave Kreskowiak14-Oct-09 8:59
mveDave Kreskowiak14-Oct-09 8:59 
GeneralRe: C# console application to dll and register..... Pin
greendragons14-Oct-09 9:04
greendragons14-Oct-09 9:04 
QuestionProblem changing text on from lable from another class [modified] Pin
yogi_bear_7914-Oct-09 6:20
yogi_bear_7914-Oct-09 6:20 
AnswerRe: Problem changing text on from lable from another class Pin
Dave Kreskowiak14-Oct-09 6:38
mveDave Kreskowiak14-Oct-09 6:38 
GeneralRe: Problem changing text on from lable from another class Pin
yogi_bear_7914-Oct-09 8:02
yogi_bear_7914-Oct-09 8:02 
GeneralRe: Problem changing text on from lable from another class Pin
DaveyM6914-Oct-09 8:05
professionalDaveyM6914-Oct-09 8:05 
GeneralRe: Problem changing text on from lable from another class Pin
yogi_bear_7914-Oct-09 8:42
yogi_bear_7914-Oct-09 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.