forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to .NET Core 1.1 and latest Roslyn packages
- Loading branch information
1 parent
d3eec44
commit 1a8fe13
Showing
30 changed files
with
331 additions
and
254 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
162 changes: 162 additions & 0 deletions
162
src/OmniSharp.Abstractions/Extensions/ReflectionExtensions.cs
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,162 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace OmniSharp.Services | ||
{ | ||
public static class ReflectionExtensions | ||
{ | ||
public static Lazy<Type> LazyGetType(this Lazy<Assembly> lazyAssembly, string typeName) | ||
{ | ||
if (lazyAssembly == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyAssembly)); | ||
} | ||
|
||
return new Lazy<Type>(() => | ||
{ | ||
var type = lazyAssembly.Value.GetType(typeName); | ||
if (type == null) | ||
{ | ||
throw new InvalidOperationException($"Could not get type '{typeName}'"); | ||
} | ||
return type; | ||
}); | ||
} | ||
|
||
public static Lazy<MethodInfo> LazyGetMethod(this Lazy<Type> lazyType, string methodName) | ||
{ | ||
if (lazyType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyType)); | ||
} | ||
|
||
return new Lazy<MethodInfo>(() => | ||
{ | ||
var methodInfo = lazyType.Value.GetMethod(methodName); | ||
if (methodInfo == null) | ||
{ | ||
throw new InvalidOperationException($"Could not get type '{methodName}'"); | ||
} | ||
return methodInfo; | ||
}); | ||
} | ||
|
||
public static Lazy<MethodInfo> LazyGetMethod(this Lazy<Type> lazyType, string methodName, BindingFlags bindingFlags) | ||
{ | ||
if (lazyType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyType)); | ||
} | ||
|
||
return new Lazy<MethodInfo>(() => | ||
{ | ||
var methodInfo = lazyType.Value.GetMethod(methodName, bindingFlags); | ||
if (methodInfo == null) | ||
{ | ||
throw new InvalidOperationException($"Could not get type '{methodName}'"); | ||
} | ||
return methodInfo; | ||
}); | ||
} | ||
|
||
public static MethodInfo GetMethod(this Lazy<Type> lazyType, string methodName) | ||
{ | ||
if (lazyType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyType)); | ||
} | ||
|
||
var methodInfo = lazyType.Value.GetMethod(methodName); | ||
|
||
if (methodInfo == null) | ||
{ | ||
throw new InvalidOperationException($"Could not get type '{methodName}'"); | ||
} | ||
|
||
return methodInfo; | ||
} | ||
|
||
public static MethodInfo GetMethod(this Lazy<Type> lazyType, string methodName, BindingFlags bindingFlags) | ||
{ | ||
if (lazyType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyType)); | ||
} | ||
|
||
var methodInfo = lazyType.Value.GetMethod(methodName, bindingFlags); | ||
|
||
if (methodInfo == null) | ||
{ | ||
throw new InvalidOperationException($"Could not get type '{methodName}'"); | ||
} | ||
|
||
return methodInfo; | ||
} | ||
|
||
public static object CreateInstance(this Lazy<Type> lazyType, params object[] args) | ||
{ | ||
if (lazyType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyType)); | ||
} | ||
|
||
return Activator.CreateInstance(lazyType.Value, args); | ||
} | ||
|
||
public static T Invoke<T>(this MethodInfo methodInfo, object obj, object[] args) | ||
{ | ||
if (methodInfo == null) | ||
{ | ||
throw new ArgumentNullException(nameof(methodInfo)); | ||
} | ||
|
||
return (T)methodInfo.Invoke(obj, args); | ||
} | ||
|
||
public static T Invoke<T>(this Lazy<MethodInfo> lazyMethodInfo, object obj, object[] args) | ||
{ | ||
if (lazyMethodInfo == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyMethodInfo)); | ||
} | ||
|
||
return (T)lazyMethodInfo.Value.Invoke(obj, args); | ||
} | ||
|
||
public static T InvokeStatic<T>(this MethodInfo methodInfo, object[] args) | ||
{ | ||
if (methodInfo == null) | ||
{ | ||
throw new ArgumentNullException(nameof(methodInfo)); | ||
} | ||
|
||
return (T)methodInfo.Invoke(null, args); | ||
} | ||
|
||
public static T InvokeStatic<T>(this Lazy<MethodInfo> lazyMethodInfo, object[] args) | ||
{ | ||
if (lazyMethodInfo == null) | ||
{ | ||
throw new ArgumentNullException(nameof(lazyMethodInfo)); | ||
} | ||
|
||
return lazyMethodInfo.Value.InvokeStatic<T>(args); | ||
} | ||
|
||
public static object InvokeStatic(this MethodInfo methodInfo, object[] args) | ||
{ | ||
return methodInfo.Invoke(null, args); | ||
} | ||
|
||
public static object InvokeStatic(this Lazy<MethodInfo> lazyMethodInfo, object[] args) | ||
{ | ||
return lazyMethodInfo.InvokeStatic(args); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.