generated from dotnet/new-repo
-
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 the database by adding a new JSON Column
- Loading branch information
Showing
12 changed files
with
248 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Reflection; | ||
using System.Text.Json; | ||
|
||
namespace OData.WebApi.Extensions | ||
{ | ||
public static class MethodInfoHelpers | ||
{ | ||
private static MethodInfo _JsonDeserializeMi; | ||
private static MethodInfo _EnumerableSelectMi; | ||
private static MethodInfo _EnumerableLongCountMi; | ||
|
||
public static MethodInfo JsonDeserializeMi | ||
{ | ||
get | ||
{ | ||
if (_JsonDeserializeMi == null) | ||
{ | ||
_JsonDeserializeMi = GetJsonSerializer(); | ||
} | ||
|
||
return _JsonDeserializeMi; | ||
} | ||
} | ||
|
||
public static MethodInfo EnumerableSelectMi | ||
{ | ||
get | ||
{ | ||
if (_EnumerableSelectMi == null) | ||
{ | ||
_EnumerableSelectMi = GetEnumerableSelect(); | ||
} | ||
|
||
return _EnumerableSelectMi; | ||
} | ||
} | ||
|
||
public static MethodInfo EnumerableLongCountMi | ||
{ | ||
get | ||
{ | ||
if (_EnumerableLongCountMi == null) | ||
{ | ||
_EnumerableLongCountMi = GetLongCountMethodInfo(); | ||
} | ||
|
||
return _EnumerableLongCountMi; | ||
} | ||
} | ||
|
||
private static MethodInfo GetEnumerableSelect() | ||
{ | ||
// public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector); | ||
var selects = typeof(Enumerable).GetMethods().Where(x => x.Name == "Select"); | ||
foreach (var select in selects) | ||
{ | ||
ParameterInfo[] parameters = select.GetParameters(); | ||
if (parameters.Length != 2) | ||
{ | ||
continue; | ||
} | ||
|
||
if (parameters[1].ParameterType.GetGenericArguments().Length == 2) | ||
{ | ||
return select; | ||
} | ||
} | ||
|
||
throw new NotSupportedException(); | ||
} | ||
|
||
private static MethodInfo GetJsonSerializer() | ||
{ | ||
// public static TValue? Deserialize<TValue>(string json, JsonSerializerOptions? options = null); | ||
var deses = typeof(JsonSerializer).GetMethods().Where(x => x.Name == "Deserialize"); | ||
|
||
foreach (var deserializeMethodInfo in deses) | ||
{ | ||
ParameterInfo[] parameters = deserializeMethodInfo.GetParameters(); | ||
if (parameters.Length != 2) | ||
{ | ||
continue; | ||
} | ||
|
||
if (parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(JsonSerializerOptions)) | ||
{ | ||
return deserializeMethodInfo; | ||
} | ||
} | ||
|
||
throw new NotSupportedException(); | ||
} | ||
|
||
private static MethodInfo GetLongCountMethodInfo() | ||
{ | ||
var longCountMethods = typeof(Enumerable).GetMethods().Where(x => x.Name == "LongCount"); | ||
|
||
return longCountMethods.First(x => x.GetParameters().Length == 1); | ||
} | ||
} | ||
} |
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,35 @@ | ||
namespace OData.WebApi.Extensions | ||
{ | ||
public static class TypeHelpers | ||
{ | ||
public static bool IsCollection(this Type clrType, out Type elementType) | ||
{ | ||
elementType = clrType; | ||
if (clrType == null) | ||
{ | ||
return false; | ||
} | ||
|
||
// see if this type should be ignored. | ||
if (clrType == typeof(string)) | ||
{ | ||
return false; | ||
} | ||
|
||
Type collectionInterface | ||
= clrType.GetInterfaces() | ||
.Union(new[] { clrType }) | ||
.FirstOrDefault( | ||
t => t.IsGenericType | ||
&& t.GetGenericTypeDefinition() == typeof(IEnumerable<>)); | ||
|
||
if (collectionInterface != null) | ||
{ | ||
elementType = collectionInterface.GetGenericArguments().Single(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
Empty file.