.net syntax - mkol/il2js GitHub Wiki
Following .NET OOP features are supported:
- class inheritance
- interfaces (user-defined only)
- virtual and/or abstract methods
- static constructors
ref and out parameters are supported:
void refExample(ref int param0, out int param1) {
// do something here, set param1 value
}
foreach loop for arrays and lists is supported:
void foreachExample(int[] ints, List<string> strings, IEnumerable<double> doubles) {
foreach(var item in ints) {
// do something
}
foreach(var item in strings)
// do something
}
foreach(var item in doubles)
// do something
}
}
Non generic IEnumerable
and IEnumerator
are not supported in the Framework. Use IEnumerable<object>
and IEnumerator<object>
instead.
LINQ syntax is supported as most of Enumerable
methods are supported.
In following example compiler generates the same IL code for both methods
void LINQTest0(IEnumerable<string> strings){
foreach(var data in from s in strings
where s.Length>2
select new {
First=s.Substring(0,2),
Second=s.Substring(2),
}){
// do something
}
}
void LINQTest1(IEnumerable<string> strings){
foreach(var data in strings
.Where(s=>s.Length>2)
.Select(s=> new {
First=s.Substring(0,2),
Second=s.Substring(2),
}){
// do something
}
}
lock
block is supported:
void lockExample() {
lock(this){
// do something
}
}
yield
is supported as a way to create IEnumerable<>
and IEnumerator<>
.
static IEnumerator<string> YieldEnumerator() {
for (char c = 'a'; c <= 'c'; ++c) {
yield return c.ToString();
}
}
static IEnumerable<string> YieldEnumerable() {
for (char c = 'a'; c <= 'c'; ++c) {
yield return c.ToString();
}
}
Non generic IEnumerable
and IEnumerator
are not supported in the Framework. Use IEnumerable<object>
and IEnumerator<object>
instead.
[.net methods] [threads]