-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve reflection & lazy references
- Loading branch information
1 parent
88dedc1
commit 602f37c
Showing
14 changed files
with
126 additions
and
51 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
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
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
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
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
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
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,25 @@ | ||
using System.Reflection; | ||
|
||
namespace Osu.Stubs.Utils; | ||
|
||
public static class ReflectionExtensions | ||
{ | ||
/// <summary> | ||
/// Reflectively get a field's value and cast it to a specific type. | ||
/// </summary> | ||
/// <param name="field">The target field.</param> | ||
/// <param name="instance">Instance of the enclosing class, if any.</param> | ||
/// <typeparam name="T">Field type to cast to.</typeparam> | ||
public static T GetValue<T>(this FieldInfo field, object? instance) | ||
=> (T)field.GetValue(instance); | ||
|
||
/// <summary> | ||
/// Reflectively invoke a method and cast the return value to a specific type. | ||
/// </summary> | ||
/// <param name="method">The target method.</param> | ||
/// <param name="instance">Instance of the enclosing class, if any.</param> | ||
/// <param name="parameters">Parameters to pass to the method, if any.</param> | ||
/// <typeparam name="T">Return type to cast to.</typeparam> | ||
public static T Invoke<T>(this MethodBase method, object? instance, object?[]? parameters) | ||
=> (T)method.Invoke(instance, parameters); | ||
} |
Oops, something went wrong.