#25: implement workaround for missing open generic registration possibility
parent
781c6b3c03
commit
a854354e85
5 changed files with 77 additions and 4 deletions
@ -0,0 +1,27 @@ |
||||
// Author: Simon Gockner |
||||
// Created: 2020-09-18 |
||||
// Copyright(c) 2020 SimonG. All Rights Reserved. |
||||
|
||||
using System; |
||||
using GBase.Api; |
||||
|
||||
namespace GBase.Exceptions |
||||
{ |
||||
/// <summary> |
||||
/// <see cref="Exception"/> that the passed table type doesn't implement <see cref="INotifyGBaseEntryChanged"/>"/> |
||||
/// </summary> |
||||
public class InvalidTableTypeException : Exception |
||||
{ |
||||
/// <summary> |
||||
/// <see cref="Exception"/> that the passed table type doesn't implement <see cref="INotifyGBaseEntryChanged"/>"/> |
||||
/// </summary> |
||||
/// <param name="type">The table type</param> |
||||
public InvalidTableTypeException(Type type) |
||||
: base($"Table type ({type}) doesn't implement {nameof(INotifyGBaseEntryChanged)}.") |
||||
{ |
||||
Type = type; |
||||
} |
||||
|
||||
public Type Type { get; } |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
// Author: Simon Gockner |
||||
// Created: 2020-09-18 |
||||
// Copyright(c) 2020 SimonG. All Rights Reserved. |
||||
|
||||
using System; |
||||
using GBase.Api; |
||||
using GBase.Exceptions; |
||||
using GBase.FileHandling.Factories; |
||||
using GBase.Interfaces; |
||||
using GBase.Interfaces.FileHandling; |
||||
|
||||
namespace GBase.Factories |
||||
{ |
||||
/// <summary> |
||||
/// Factory for the <see cref="IGBaseTable"/> |
||||
/// </summary> |
||||
public class GBaseTableFactory : IGBaseTableFactory |
||||
{ |
||||
private readonly IFileHandlerFactory _fileHandlerFactory; |
||||
private readonly IGBaseColumnFactory _gBaseColumnFactory; |
||||
|
||||
/// <summary> |
||||
/// Factory for the <see cref="IGBaseTable"/> |
||||
/// </summary> |
||||
/// <param name="fileHandlerFactory">Factory for the <see cref="IFileHandler"/></param> |
||||
/// <param name="gBaseColumnFactory">Factory for the <see cref="IGBaseColumn"/></param> |
||||
public GBaseTableFactory(IFileHandlerFactory fileHandlerFactory, IGBaseColumnFactory gBaseColumnFactory) |
||||
{ |
||||
_fileHandlerFactory = fileHandlerFactory; |
||||
_gBaseColumnFactory = gBaseColumnFactory; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates an <see cref="IGBaseTable"/> |
||||
/// </summary> |
||||
/// <returns>A newly created instance of the implementation for <see cref="IGBaseTable"/></returns> |
||||
public IGBaseTable Create(Type type) |
||||
{ |
||||
if (!typeof(INotifyGBaseEntryChanged).IsAssignableFrom(type)) |
||||
throw new InvalidTableTypeException(type); |
||||
|
||||
Type gBaseTableType = typeof(GBaseTable<>).MakeGenericType(type); |
||||
return (IGBaseTable) Activator.CreateInstance(gBaseTableType, _fileHandlerFactory, _gBaseColumnFactory); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue