|
|
|
@ -6,6 +6,7 @@ using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using GBase.Exceptions; |
|
|
|
using GBase.Exceptions; |
|
|
|
using GBase.Interfaces; |
|
|
|
using GBase.Interfaces; |
|
|
|
@ -26,7 +27,10 @@ namespace GBase.Helpers |
|
|
|
StringBuilder @string = new StringBuilder(); |
|
|
|
StringBuilder @string = new StringBuilder(); |
|
|
|
foreach (var item in enumerable) |
|
|
|
foreach (var item in enumerable) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@string.Append($"{item}{ENUMERABLE_STRING_DIVIDER}"); |
|
|
|
if (item is IGBaseObject gBaseObject) |
|
|
|
|
|
|
|
@string.Append($"{gBaseObject.Key}{ENUMERABLE_STRING_DIVIDER}"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
@string.Append($"{item}{ENUMERABLE_STRING_DIVIDER}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char lastChar = @string[^1]; |
|
|
|
char lastChar = @string[^1]; |
|
|
|
@ -41,9 +45,10 @@ namespace GBase.Helpers |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <typeparam name="TEnumerable">The <see cref="IEnumerable{T}"/> <see cref="Type"/></typeparam> |
|
|
|
/// <typeparam name="TEnumerable">The <see cref="IEnumerable{T}"/> <see cref="Type"/></typeparam> |
|
|
|
/// <param name="string">The given <see cref="string"/></param> |
|
|
|
/// <param name="string">The given <see cref="string"/></param> |
|
|
|
|
|
|
|
/// <param name="gBase"></param> |
|
|
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Type"/> <typeparamref name="TEnumerable"/></returns> |
|
|
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Type"/> <typeparamref name="TEnumerable"/></returns> |
|
|
|
/// <exception cref="InterfaceEnumerablePassedException">Interface was passed to an <see cref="IEnumerable{T}"/></exception> |
|
|
|
/// <exception cref="InterfaceEnumerablePassedException">Interface was passed to an <see cref="IEnumerable{T}"/></exception> |
|
|
|
public static TEnumerable ConvertToGBaseEnumerable<TEnumerable>(string @string) |
|
|
|
public static TEnumerable ConvertToGBaseEnumerable<TEnumerable>(string @string, IGBase gBase) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//get generic type parameter of TEnumerable |
|
|
|
//get generic type parameter of TEnumerable |
|
|
|
Type genericType = typeof(TEnumerable).GetGenericArguments()[0]; |
|
|
|
Type genericType = typeof(TEnumerable).GetGenericArguments()[0]; |
|
|
|
@ -61,9 +66,16 @@ namespace GBase.Helpers |
|
|
|
if (genericType.IsInterface) |
|
|
|
if (genericType.IsInterface) |
|
|
|
throw new InterfaceEnumerablePassedException(genericType); |
|
|
|
throw new InterfaceEnumerablePassedException(genericType); |
|
|
|
|
|
|
|
|
|
|
|
IGBaseObject gBaseObject = (IGBaseObject) Activator.CreateInstance(genericType); |
|
|
|
if (!int.TryParse(value, out int key)) |
|
|
|
gBaseObject.InitializeFromString(value); |
|
|
|
throw new InvalidKeyException("Key is not an integer."); |
|
|
|
item = gBaseObject; |
|
|
|
|
|
|
|
|
|
|
|
//TODO: What to do when this table isn't initialized yet? |
|
|
|
|
|
|
|
item = GenericMethodCaller.Call(gBase, nameof(IGBase.GetEntryForKey), |
|
|
|
|
|
|
|
BindingFlags.Public | BindingFlags.Instance, genericType, key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IGBaseObject gBaseObject = (IGBaseObject) Activator.CreateInstance(genericType); |
|
|
|
|
|
|
|
// gBaseObject.InitializeFromString(value); |
|
|
|
|
|
|
|
// item = gBaseObject; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
item = Convert.ChangeType(value, genericType); |
|
|
|
item = Convert.ChangeType(value, genericType); |
|
|
|
|