-
Notifications
You must be signed in to change notification settings - Fork 16
Extension Methods
ikopylov edited this page Jan 15, 2016
·
2 revisions
Useful extension methods:
IEnumerable<int> testEnumberable = Enumerable.Range(0, 100);
// Find the position of element
int index = testEnumberable.FindPosition(elem => elem == 10);
// Get item with maximum key
int valueMax = testEnumerable.MaxBy(elem => elem);
// Get item with minimum key
int valueMin = testEnumerable.MinBy(elem => elem);
Type testType = typeof(int);
// Test can we assign 'null' to variable of this type
bool n1 = testType.IsAssignableFromNull();
// Get type name in C# format
string csName = testType.GetCSName();
// Get full type name in C# format
string csFullName = testType.GetCSFullName();
// Can throw any exception by its type
TurboException.Throw(typeof(ArgumentNullException), "message");
TurboException.Throw<ArgumentNullException>("message");