ArrrrgggH!

My blog has moved.
You can view this post at the following address:
http://www.osherove.com/blog/2003/3/26/arrrrgggh.html
Published Wednesday, March 26, 2003 8:47 AM by RoyOsherove

Comments

Tuesday, March 25, 2003 7:24 PM by Jan Tielens

# re: ArrrrgggH!

Hi

You can use the StringBuilder to create a stream.

I use it with CodeDom too, like this:
Private Function GetVBCode(ByVal code As CodeTypeDeclaration) As String
Dim gen As New VBCodeProvider

Dim sb As New System.Text.StringBuilder
Dim stream As New IO.StringWriter(sb)
gen.CreateGenerator().GenerateCodeFromType(code, stream, Nothing)
stream.Close()

Return sb.ToString
End Function

Greetz
Jan
Tuesday, March 25, 2003 7:28 PM by Christian Weyer

# re: ArrrrgggH!

This works for me:

[...]
string xmlString = @"<?xml version='1.0' encoding='utf-8' ?><TestType><Number>42</Number><Value>Christian</Value></TestType>";

System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.TextWriter writer = new System.IO.StreamWriter( ms );
writer.Write(xmlString);
writer.Flush();

ms.Seek(0, System.IO.SeekOrigin.Begin);
XmlSerializer serializer = new XmlSerializer(typeof(TestType));
TestType tt = (TestType)serializer.Deserialize(ms);
[...]

public class TestType
{
public int Number;
public string Value;
}


Cheers,
Christian
Tuesday, March 25, 2003 7:33 PM by Royo

# re: ArrrrgggH!

Thanks for the input guys!
That was darn quick :)
I new it was something as easy as a memoryStream, but i just couldn't find the damn thing !
Tuesday, March 25, 2003 7:34 PM by Royo

# re: ArrrrgggH!

Thanks Jen! that looks like a marvelous way do do lotas of stuff!