I have added a new macro called ‘with-clr-type’, that tags an identifier with a CLR type, and this allows to write shorter syntax.
Given the following class:
public class TestClass
{
public string Source;
public string Message { get; set; }
public TestClass()
{
}
public TestClass(string msg)
{
Message = msg;
}
public void Print(string hello)
{
Console.WriteLine("{0} {1}", hello, Message);
}
public char this[int i]
{
get { return Message[i]; }
set { Message = i.ToString() + value.ToString(); }
}
}
One can do the following:
> (import (ironscheme clr)) > (clr-using IronScheme) > (let ((obj (clr-new TestClass "foo"))) . (with-clr-type ((obj TestClass)) ; can tag multiple ids . (printf "~a\n" (eq? obj 50)) ; normal reference, do nothing . (printf "~a\n" (obj : Message)) ; property get . (obj : Message = "world") ; property set . (printf "~a\n" (obj -> Source)) ; field get . (obj -> Source = "bar") ; field set . (printf "~a\n" (obj -> Source)) ; field get . (obj Print "hello") ; method call . (printf "~a\n" (obj (1))) ; indexer get . (obj (99) = #\a) ; indexer set . (obj : Message) ; property get . )) #f foo () bar hello world o "99a" >
Which is a lot shorter than the normal way.