Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addng updated event info with inner fields
- Loading branch information
1 parent
159b8d3
commit 03a0f72
Showing
11 changed files
with
136 additions
and
44 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Enbiso.NLib.EventInfo.Models; | ||
|
||
public class EventInfoListResponse | ||
{ | ||
public List<EventRecord> Records { get; set; } = new(); | ||
public int Count { get; set; } | ||
} |
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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Enbiso.NLib.EventInfo.Models; | ||
|
||
public class EventRecord | ||
{ | ||
public string Name { get; } | ||
public List<EventRecordProp> Props { get; } | ||
|
||
public EventRecord(Type type) | ||
{ | ||
Name = type.Name; | ||
Props = type.GetProperties().Select(EventRecordMapper.Map).ToList(); | ||
} | ||
} |
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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Enbiso.NLib.EventInfo.Models; | ||
|
||
public static class EventRecordMapper | ||
{ | ||
public static EventRecordProp Map(PropertyInfo property) => | ||
new(property) | ||
{ | ||
Props = property.PropertyType.GetProperties() | ||
.Where(p => ShouldExtract(p.PropertyType)) | ||
.Select(p => new EventRecordProp(p)).ToList() | ||
}; | ||
|
||
private static bool ShouldExtract(Type type) | ||
{ | ||
if (IsSimpleType(type)) return false; | ||
var excludeTypes = new List<Type> | ||
{ | ||
typeof(List<>), | ||
typeof(IEnumerable<>), | ||
typeof(Dictionary<,>), | ||
typeof(IDictionary<,>) | ||
}; | ||
return excludeTypes.All(p => p == type); | ||
} | ||
|
||
private static bool IsSimpleType(Type type) | ||
{ | ||
return | ||
type.IsPrimitive || | ||
type.IsValueType || | ||
new[] | ||
{ | ||
typeof(string), | ||
typeof(decimal), | ||
typeof(DateTime), | ||
typeof(DateTimeOffset), | ||
typeof(TimeSpan), | ||
typeof(Guid) | ||
}.Contains(type) || | ||
type.IsEnum || | ||
Convert.GetTypeCode(type) != TypeCode.Object || | ||
(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && | ||
IsSimpleType(type.GetGenericArguments()[0])); | ||
} | ||
} |
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,17 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace Enbiso.NLib.EventInfo.Models; | ||
|
||
public class EventRecordProp | ||
{ | ||
public EventRecordProp(PropertyInfo property) | ||
{ | ||
Name = property.Name; | ||
Type = property.PropertyType.Name; | ||
} | ||
|
||
public string Name { get; } | ||
public string Type { get; } | ||
public List<EventRecordProp> Props { get; set; } | ||
} |
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,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Enbiso.NLib.EventInfo; | ||
|
||
public static class ServiceExtensions | ||
{ | ||
public static IServiceCollection AddEventInfo(this IServiceCollection collection, Action<EventInfoOption> optBuilder = null) | ||
{ | ||
collection.AddOptions(); | ||
optBuilder ??= _ => {}; | ||
collection.Configure(optBuilder); | ||
|
||
collection.AddSingleton<IEventInfoService, EventInfoService>(); | ||
return collection; | ||
} | ||
} | ||
|
||
public class EventInfoOption | ||
{ | ||
public List<Type> SearchTypes { get; set; } = new(); | ||
} |
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