Silverfrost Forums

Welcome to our forums

use of MemoryStream

20 May 2009 8:57 #4635

I am wondering how to use .NET's MemoryStream. I know you can use StreamReader similar to this:

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:

OBJECT('System.IO.MemoryStream') MemoryStream

but how do I turn this part of it into Fortran.Net?

MemoryStream mStream = new MemoryStream(ASCIIEncoding.Default.GetBytes('Your string here'))
21 May 2009 11:10 #4637

Something like this:

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:

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.

22 May 2009 2:51 #4640

That worked perfectly. Thanks!

Please login to reply.