-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #301
- Loading branch information
Showing
15 changed files
with
214 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
|
||
namespace Unity.BuiltIn | ||
{ | ||
public static class ArrayTypeSelector | ||
|
||
{ | ||
#region Selection | ||
|
||
public static Type Selector(UnityContainer container, Type argType) | ||
{ | ||
Type? next; | ||
Type? type = argType; | ||
|
||
do | ||
{ | ||
if (type.IsGenericType) | ||
{ | ||
if (container.Scope.Contains(type)) return type!; | ||
|
||
var definition = type.GetGenericTypeDefinition(); | ||
if (container.Scope.Contains(definition)) return definition; | ||
|
||
next = type.GenericTypeArguments[0]!; | ||
if (container.Scope.Contains(next)) return next; | ||
} | ||
else if (type.IsArray) | ||
{ | ||
next = type.GetElementType()!; | ||
if (container.Scope.Contains(next)) return next; | ||
} | ||
else | ||
{ | ||
return type!; | ||
} | ||
} | ||
while (null != (type = next)); | ||
|
||
return argType; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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,46 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Unity.BuiltIn | ||
{ | ||
public static class MembersSelector | ||
{ | ||
#region Default Get Members | ||
|
||
/// <summary> | ||
/// Determines constructors selected by default when | ||
/// <see cref="Type.GetConstructors"/> is called | ||
/// </summary> | ||
public static ConstructorInfo[] GetConstructors(Type type) | ||
=> type.GetConstructors(BindingFlags.Public | BindingFlags.Instance); | ||
|
||
|
||
/// <summary> | ||
/// Determines methods selected by default when | ||
/// <see cref="Type.GetMethods"/> is called | ||
/// </summary> | ||
public static MethodInfo[] GetMethods(Type type) | ||
=> type.GetMethods(BindingFlags.Public | | ||
BindingFlags.Instance | | ||
BindingFlags.FlattenHierarchy | | ||
BindingFlags.DeclaredOnly); | ||
|
||
|
||
/// <summary> | ||
/// Determines fields selected by default when | ||
/// <see cref="Type.GetFields"/> is called | ||
/// </summary> | ||
public static FieldInfo[] GetFields(Type type) | ||
=> type.GetFields(BindingFlags.Public | BindingFlags.Instance); | ||
|
||
|
||
/// <summary> | ||
/// Determines properties selected by default when | ||
/// <see cref="Type.GetProperties"/> is called | ||
/// </summary> | ||
public static PropertyInfo[] GetProperties(Type type) | ||
=> type.GetProperties(BindingFlags.Public | BindingFlags.Instance); | ||
|
||
#endregion | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
|
||
namespace Unity.Extension | ||
{ | ||
/// <summary> | ||
/// The delegate to define selection handler that depends on the container's configuration | ||
/// </summary> | ||
/// <typeparam name="TInput"><see cref="Type"/> of the input</typeparam> | ||
/// <typeparam name="TOutput"><see cref="Type"/> of the output</typeparam> | ||
/// <param name="container">Instance of the container</param> | ||
/// <param name="input">Value[s] to select from</param> | ||
/// <returns>Selected value</returns> | ||
public delegate TOutput UnitySelector<in TInput, out TOutput>(UnityContainer container, TInput input); | ||
} | ||
|
Oops, something went wrong.