Skip to content

Instantly share code, notes, and snippets.

@stdray
Created November 18, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stdray/355cfbed30419dd0fd69efbbd1e91700 to your computer and use it in GitHub Desktop.
Save stdray/355cfbed30419dd0fd69efbbd1e91700 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using StreamExtensions;
module Program
{
Main() : void
{
def stream = MemoryStream();
ignore(stream << 108 << 111 << 108);
stream.Position = 0;
def reader = StreamReader(stream);
Console.WriteLine(reader.ReadToEnd());
stream.Position = 0;
def x = Ref(); def y = Ref(); def z = Ref();
ignore(stream >> x >> y >> z);
Console.WriteLine($"$x $y $z");
_ = Console.ReadLine();
}
}
public class Ref[T]
{
public Value : T { get; set }
public override ToString() : string
{
if(Object.ReferenceEquals(Value, null))
"null"
else
Value.ToString()
}
}
module StreamExtensions
{
public @<<(stream : Stream, v : byte) : Stream
{
stream.WriteByte(v);
stream
}
public @>>(stream : Stream, v : Ref[int]) : Stream
{
v.Value = stream.ReadByte();
stream
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment