#12: fix warnings and add comments

pull/43/head
Simon G 5 years ago
parent 7a22bdaf12
commit 699a852506
  1. 7
      LightweightIocContainer/Exceptions/GenericMethodNotFoundException.cs
  2. 16
      LightweightIocContainer/GenericMethodCaller.cs
  3. 10
      LightweightIocContainer/Interfaces/IIocContainer.cs
  4. 6
      LightweightIocContainer/Interfaces/Registrations/IOpenGenericRegistration.cs
  5. 9
      LightweightIocContainer/IocContainer.cs
  6. 92
      LightweightIocContainer/LightweightIocContainer.xml
  7. 6
      LightweightIocContainer/Properties/AssemblyInfo.cs
  8. 24
      LightweightIocContainer/Registrations/OpenGenericRegistration.cs
  9. 3
      Test.LightweightIocContainer/EnumerableExtensionTest.cs
  10. 1
      Test.LightweightIocContainer/IocContainerRecursionTest.cs
  11. 2
      Test.LightweightIocContainer/OpenGenericRegistrationTest.cs

@ -6,8 +6,15 @@ using System;
namespace LightweightIocContainer.Exceptions
{
/// <summary>
/// Could not find generic method
/// </summary>
public class GenericMethodNotFoundException : Exception
{
/// <summary>
/// Could not find generic method
/// </summary>
/// <param name="functionName">The name of the generic method</param>
public GenericMethodNotFoundException(string functionName)
: base($"Could not find function {functionName}")
{

@ -8,8 +8,22 @@ using LightweightIocContainer.Exceptions;
namespace LightweightIocContainer
{
public static class GenericMethodCaller
/// <summary>
/// Helper class to call a generic method without generic type parameters
/// </summary>
internal static class GenericMethodCaller
{
/// <summary>
/// Call a generic method without generic type parameters
/// </summary>
/// <param name="caller">The caller of the method</param>
/// <param name="functionName">The name of the method to call</param>
/// <param name="genericParameter">The generic parameter as <see cref="Type"/> parameter</param>
/// <param name="bindingFlags">The <see cref="BindingFlags"/> to find the method</param>
/// <param name="parameters">The parameters of the method</param>
/// <returns>The result of invoking the method</returns>
/// <exception cref="GenericMethodNotFoundException">Could not find the generic method</exception>
/// <exception cref="Exception">Any <see cref="Exception"/> thrown after invoking the generic method</exception>
public static object Call(object caller, string functionName, Type genericParameter, BindingFlags bindingFlags, params object[] parameters)
{
MethodInfo method = caller.GetType().GetMethod(functionName, bindingFlags);

@ -29,8 +29,14 @@ namespace LightweightIocContainer.Interfaces
/// <returns>The created <see cref="IRegistration"/></returns>
IDefaultRegistration<TInterface, TImplementation> Register<TInterface, TImplementation>(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface;
IOpenGenericRegistration RegisterOpenGenerics(Type tInterface, Type tImplementation,
Lifestyle lifestyle = Lifestyle.Transient);
/// <summary>
/// Register an open generic Interface with an open generic Type that implements it
/// </summary>
/// <param name="tInterface">The open generic Interface to register</param>
/// <param name="tImplementation">The open generic Type that implements the interface</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IOpenGenericRegistration"/></param>
/// <returns>The created <see cref="IRegistration"/></returns>
IOpenGenericRegistration RegisterOpenGenerics(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient);
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them

@ -6,8 +6,14 @@ using System;
namespace LightweightIocContainer.Interfaces.Registrations
{
/// <summary>
/// <see cref="IRegistration"/> for open generic types
/// </summary>
public interface IOpenGenericRegistration : IRegistration, ILifestyleProvider
{
/// <summary>
/// The <see cref="Type"/> that implements the <see cref="IRegistration.InterfaceType"/> that is registered with this <see cref="IOpenGenericRegistration"/>
/// </summary>
Type ImplementationType { get; }
}
}

@ -68,6 +68,15 @@ namespace LightweightIocContainer
return registration;
}
/// <summary>
/// Register an open generic Interface with an open generic Type that implements it
/// </summary>
/// <param name="tInterface">The open generic Interface to register</param>
/// <param name="tImplementation">The open generic Type that implements the interface</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IOpenGenericRegistration"/></param>
/// <returns>The created <see cref="IRegistration"/></returns>
/// <exception cref="InvalidRegistrationException">Function can only be used to register open generic types</exception>
/// <exception cref="InvalidRegistrationException">Can't register a multiton with open generic registration</exception>
public IOpenGenericRegistration RegisterOpenGenerics(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient)
{
if (!tInterface.ContainsGenericParameters)

@ -86,6 +86,17 @@
The constructor that does not match
</summary>
</member>
<member name="T:LightweightIocContainer.Exceptions.GenericMethodNotFoundException">
<summary>
Could not find generic method
</summary>
</member>
<member name="M:LightweightIocContainer.Exceptions.GenericMethodNotFoundException.#ctor(System.String)">
<summary>
Could not find generic method
</summary>
<param name="functionName">The name of the generic method</param>
</member>
<member name="T:LightweightIocContainer.Exceptions.IllegalAbstractMethodCreationException">
<summary>
The creation of the abstract method is illegal in its current state
@ -274,6 +285,24 @@
The implemented abstract typed factory/>
</summary>
</member>
<member name="T:LightweightIocContainer.GenericMethodCaller">
<summary>
Helper class to call a generic method without generic type parameters
</summary>
</member>
<member name="M:LightweightIocContainer.GenericMethodCaller.Call(System.Object,System.String,System.Type,System.Reflection.BindingFlags,System.Object[])">
<summary>
Call a generic method without generic type parameters
</summary>
<param name="caller">The caller of the method</param>
<param name="functionName">The name of the method to call</param>
<param name="genericParameter">The generic parameter as <see cref="T:System.Type"/> parameter</param>
<param name="bindingFlags">The <see cref="T:System.Reflection.BindingFlags"/> to find the method</param>
<param name="parameters">The parameters of the method</param>
<returns>The result of invoking the method</returns>
<exception cref="T:LightweightIocContainer.Exceptions.GenericMethodNotFoundException">Could not find the generic method</exception>
<exception cref="T:System.Exception">Any <see cref="T:System.Exception"/> thrown after invoking the generic method</exception>
</member>
<member name="T:LightweightIocContainer.Installers.AssemblyInstaller">
<summary>
An <see cref="T:LightweightIocContainer.Interfaces.Installers.IIocInstaller"/> that installs all <see cref="T:LightweightIocContainer.Interfaces.Installers.IIocInstaller"/>s for its given <see cref="T:System.Reflection.Assembly"/>
@ -346,6 +375,15 @@
<param name="lifestyle">The <see cref="T:LightweightIocContainer.Lifestyle"/> for this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase`1"/></param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.Interfaces.IIocContainer.RegisterOpenGenerics(System.Type,System.Type,LightweightIocContainer.Lifestyle)">
<summary>
Register an open generic Interface with an open generic Type that implements it
</summary>
<param name="tInterface">The open generic Interface to register</param>
<param name="tImplementation">The open generic Type that implements the interface</param>
<param name="lifestyle">The <see cref="T:LightweightIocContainer.Lifestyle"/> for this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration"/></param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.Interfaces.IIocContainer.Register``3(LightweightIocContainer.Lifestyle)">
<summary>
Register multiple interfaces for a <see cref="T:System.Type"/> that implements them
@ -609,6 +647,16 @@
<typeparam name="TInterface">The registered interface</typeparam>
<typeparam name="TImplementation">The registered implementation</typeparam>
</member>
<member name="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration">
<summary>
<see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for open generic types
</summary>
</member>
<member name="P:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration.ImplementationType">
<summary>
The <see cref="T:System.Type"/> that implements the <see cref="P:LightweightIocContainer.Interfaces.Registrations.IRegistration.InterfaceType"/> that is registered with this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration"/>
</summary>
</member>
<member name="T:LightweightIocContainer.Interfaces.Registrations.IRegistration">
<summary>
The base registration that is used to register an Interface
@ -705,6 +753,17 @@
<param name="lifestyle">The <see cref="T:LightweightIocContainer.Lifestyle"/> for this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase`1"/></param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.RegisterOpenGenerics(System.Type,System.Type,LightweightIocContainer.Lifestyle)">
<summary>
Register an open generic Interface with an open generic Type that implements it
</summary>
<param name="tInterface">The open generic Interface to register</param>
<param name="tImplementation">The open generic Type that implements the interface</param>
<param name="lifestyle">The <see cref="T:LightweightIocContainer.Lifestyle"/> for this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration"/></param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.InvalidRegistrationException">Function can only be used to register open generic types</exception>
<exception cref="T:LightweightIocContainer.Exceptions.InvalidRegistrationException">Can't register a multiton with open generic registration</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.Register``3(LightweightIocContainer.Lifestyle)">
<summary>
Register multiple interfaces for a <see cref="T:System.Type"/> that implements them
@ -1078,6 +1137,39 @@
The <see cref="T:System.Type"/> of the multiton scope
</summary>
</member>
<member name="T:LightweightIocContainer.Registrations.OpenGenericRegistration">
<summary>
<see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for open generic types
</summary>
</member>
<member name="M:LightweightIocContainer.Registrations.OpenGenericRegistration.#ctor(System.Type,System.Type,LightweightIocContainer.Lifestyle)">
<summary>
<see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for open generic types
</summary>
<param name="interfaceType">The <see cref="T:System.Type"/> of the interface</param>
<param name="implementationType">The <see cref="T:System.Type"/> of the implementation type</param>
<param name="lifestyle">The <see cref="P:LightweightIocContainer.Registrations.OpenGenericRegistration.Lifestyle"/> of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration"/></param>
</member>
<member name="P:LightweightIocContainer.Registrations.OpenGenericRegistration.Name">
<summary>
The name of the <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>
</summary>
</member>
<member name="P:LightweightIocContainer.Registrations.OpenGenericRegistration.InterfaceType">
<summary>
The <see cref="T:System.Type"/> of the Interface that is registered with this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>
</summary>
</member>
<member name="P:LightweightIocContainer.Registrations.OpenGenericRegistration.ImplementationType">
<summary>
The <see cref="T:System.Type"/> that implements the <see cref="P:LightweightIocContainer.Interfaces.Registrations.IRegistration.InterfaceType"/> that is registered with this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IOpenGenericRegistration"/>
</summary>
</member>
<member name="P:LightweightIocContainer.Registrations.OpenGenericRegistration.Lifestyle">
<summary>
The Lifestyle of Instances that are created with this <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>
</summary>
</member>
<member name="T:LightweightIocContainer.Registrations.RegistrationBase`1">
<summary>
The <see cref="T:LightweightIocContainer.Registrations.RegistrationBase`1"/> that is used to register an Interface

@ -4,8 +4,4 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("Test.LightweightIocContainer")]
namespace LightweightIocContainer.Properties
{
}
[assembly:InternalsVisibleTo("Test.LightweightIocContainer")]

@ -7,8 +7,17 @@ using LightweightIocContainer.Interfaces.Registrations;
namespace LightweightIocContainer.Registrations
{
/// <summary>
/// <see cref="IRegistration"/> for open generic types
/// </summary>
public class OpenGenericRegistration : IOpenGenericRegistration
{
/// <summary>
/// <see cref="IRegistration"/> for open generic types
/// </summary>
/// <param name="interfaceType">The <see cref="Type"/> of the interface</param>
/// <param name="implementationType">The <see cref="Type"/> of the implementation type</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> of this <see cref="IOpenGenericRegistration"/></param>
public OpenGenericRegistration(Type interfaceType, Type implementationType, Lifestyle lifestyle)
{
InterfaceType = interfaceType;
@ -18,9 +27,24 @@ namespace LightweightIocContainer.Registrations
Name = $"{InterfaceType.Name}, {ImplementationType.Name}, Lifestyle: {Lifestyle.ToString()}";
}
/// <summary>
/// The name of the <see cref="IRegistration"/>
/// </summary>
public string Name { get; }
/// <summary>
/// The <see cref="Type"/> of the Interface that is registered with this <see cref="IRegistration"/>
/// </summary>
public Type InterfaceType { get; }
/// <summary>
/// The <see cref="Type"/> that implements the <see cref="IRegistration.InterfaceType"/> that is registered with this <see cref="IOpenGenericRegistration"/>
/// </summary>
public Type ImplementationType { get; }
/// <summary>
/// The Lifestyle of Instances that are created with this <see cref="IRegistration"/>
/// </summary>
public Lifestyle Lifestyle { get; }
}
}

@ -3,6 +3,7 @@
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using LightweightIocContainer;
using NUnit.Framework;
@ -27,6 +28,7 @@ namespace Test.LightweightIocContainer
[Test]
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Local")]
public void TestFirstOrGivenNoPredicateEmpty()
{
List<ListObject> list = new List<ListObject>();
@ -51,6 +53,7 @@ namespace Test.LightweightIocContainer
}
[Test]
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Local")]
public void TestFirstOrGivenPredicateEmpty()
{
List<ListObject> list = new List<ListObject>();

@ -141,6 +141,7 @@ namespace Test.LightweightIocContainer
_iocContainer.Register<IC, C>();
IA a = _iocContainer.Resolve<IA>();
Assert.IsNotNull(a);
}
[Test]

@ -2,6 +2,7 @@
// Created: 2020-09-18
// Copyright(c) 2020 SimonG. All Rights Reserved.
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Exceptions;
@ -16,6 +17,7 @@ namespace Test.LightweightIocContainer
private IIocContainer _iocContainer;
[UsedImplicitly]
[SuppressMessage("ReSharper", "UnusedTypeParameter")]
public interface ITest<T>
{

Loading…
Cancel
Save