-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new "GetMethodInfo" and "GetPropertyInfo" methods to the "Refle…
…ctionUtils" class The methods allows getting either method info or property info of an expression.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Linq.Expressions; | ||
using Skybrud.Essentials.Reflection; | ||
|
||
namespace TestProject1 { | ||
|
||
[TestClass] | ||
public class ReflectionTests { | ||
|
||
[TestMethod] | ||
public void GetMethodInfo() { | ||
|
||
Expression<Func<MyModel, string>> expression = GetExpression<MyModel, string>(x => x.MyMethod()); | ||
|
||
var method = ReflectionUtils.GetMethodInfo(expression); | ||
|
||
Assert.AreEqual("MyMethod", method.Name); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public void GetPropertyInfo() { | ||
|
||
Expression<Func<MyModel, string>> expression = GetExpression<MyModel, string>(x => x.MyProperty); | ||
|
||
var property = ReflectionUtils.GetPropertyInfo(expression); | ||
|
||
Assert.AreEqual("MyProperty", property.Name); | ||
|
||
} | ||
|
||
private Expression<Func<TModel, TProperty>> GetExpression<TModel, TProperty>(Expression<Func<TModel, TProperty>> expression) { | ||
return expression; | ||
} | ||
|
||
public class MyModel { | ||
|
||
public string MyProperty { get; set; } = "Hello There"; | ||
|
||
public string MyMethod() { | ||
return "Hello Where"; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |