View previous topic :: View next topic |
Author |
Message |
silverdan
Joined: 14 May 2009 Posts: 29
|
Posted: Wed May 20, 2009 9:57 pm Post subject: use of MemoryStream |
|
|
I am wondering how to use .NET's MemoryStream. I know you can use StreamReader similar to this:
Code: | OBJECT("System.IO.StreamReader") StreamReader
ASSEMBLY_EXTERNAL("System.IO.File.OpenText") FileOpen
ASSEMBLY_EXTERNAL("System.IO.StreamReader.Close") StreamReaderClose
StreamReader = FileOpen("c:\text.txt") |
I have gotten this far:
Code: |
OBJECT("System.IO.MemoryStream") MemoryStream
|
but how do I turn this part of it into Fortran.Net?
Code: | MemoryStream mStream = new MemoryStream(ASCIIEncoding.Default.GetBytes("Your string here")) |
|
|
Back to top |
|
 |
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Thu May 21, 2009 12:10 pm Post subject: |
|
|
Something like this:
Code: | PROGRAM TestMemoryStream
OBJECT("ClassLibrary1.Class1") Class1
OBJECT("System.IO.MemoryStream") MemoryStream
OBJECT("System.Text.ASCIIEncoding") ASCIIEncoding
ASSEMBLY_EXTERNAL("System.Text.ASCIIEncoding.GetBytes") ASCIIEncodingGetBytes
ASSEMBLY_EXTERNAL("ClassLibrary1.Class1.ReadStream") ReadStream
ASCIIEncoding = new@("System.Text.ASCIIEncoding")
MemoryStream = new@("System.IO.MemoryStream", ASCIIEncodingGetBytes(ASCIIEncoding,"string"))
Class1 = new@("ClassLibrary1.Class1")
CALL ReadStream(Class1, MemoryStream)
END |
with C# like:
Code: | namespace ClassLibrary1
{
public class Class1
{
public void ReadStream(MemoryStream memoryStream)
{
string s = "";
StreamReader streamReader = new StreamReader(memoryStream);
while ((s = streamReader.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
} |
I did have to play around to get an instance of the ASCIIEncoding class to call GetBytes with an instance of it (which wasnt clear initially). Its much the same as the previous example in many ways - just have a play creating and passing .NET objects in this way and you should get used to it. |
|
Back to top |
|
 |
silverdan
Joined: 14 May 2009 Posts: 29
|
Posted: Fri May 22, 2009 3:51 pm Post subject: |
|
|
That worked perfectly. Thanks! |
|
Back to top |
|
 |
|