Skip to content

Commit

Permalink
Merge pull request #1497 from STealthy-and-haSTy/1496_cs_ctor_expression
Browse files Browse the repository at this point in the history
[C#] support expression bodied constructor methods
  • Loading branch information
wbond authored Apr 13, 2018
2 parents dab8e45 + 0eb4fa3 commit 7537497
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion C#/C#.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ contexts:
set: [constructor_initializer, arguments]
- match: '(?=\{)'
set: method_body
- match: '(?=\{)'
- match: '(?=\{|=>)'
set: method_body

constructor_initializer:
Expand Down
45 changes: 45 additions & 0 deletions C#/tests/syntax_test_C#7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,48 @@ public ref int Find (int number, int[] numbers)
}
throw new IndexOutOfRangeException ($"{nameof (number)} not found");
}

public class MyClass {
object obj;
public MyClass () => obj = null;
/// ^^^^^^^ meta.method.constructor entity.name.function.constructor
/// ^^^^^^^^^^^^^^^^^ meta.class.body meta.block meta.method
/// ^^ storage.type.function
/// ^^^ variable.other
/// ^ keyword.operator.assignment
/// ^^^^ constant.language
/// ^ punctuation.terminator.statement - meta.method
}
/// <- meta.class.body meta.block punctuation.section.block.end

public class Person // https://stackoverflow.com/a/41974829/4473405
{
public string Name { get; }
public int Age { get; }

public Person(string name, int age) => (Name, Age) = (name, age);
/// ^^^^^^ storage.modifier.access
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.method.constructor
/// ^^^^^^ entity.name.function.constructor
/// ^ punctuation.section.parameters.begin
/// ^^^^^^ storage.type
/// ^^^^ variable.parameter
/// ^ punctuation.separator.parameter.function
/// ^^^ storage.type
/// ^^^ variable.parameter
/// ^ punctuation.section.parameters.end
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.method
/// ^^ storage.type.function
/// ^ meta.group punctuation.section.group.begin
/// ^^^^ meta.group variable.other
/// ^ meta.group punctuation.separator.expression
/// ^^^ meta.group variable.other
/// ^ meta.group punctuation.section.group.end
/// ^ keyword.operator.assignment
/// ^ meta.group punctuation.section.group.begin
/// ^^^^ meta.group variable.other
/// ^ punctuation.separator.expression
/// ^^^ meta.group variable.other
/// ^ meta.group punctuation.section.group.end
/// ^ punctuation.terminator.statement
}

0 comments on commit 7537497

Please sign in to comment.