diff --git a/UmlautAdaptarr/Utilities/ServicesExtensions.cs b/UmlautAdaptarr/Utilities/ServicesExtensions.cs index a12a1b2..06e1b36 100644 --- a/UmlautAdaptarr/Utilities/ServicesExtensions.cs +++ b/UmlautAdaptarr/Utilities/ServicesExtensions.cs @@ -58,19 +58,27 @@ public static class ServicesExtensions (string)typeof(TOptions).GetProperty("Host")?.GetValue(option, null)!); // Dark Magic , we don't know the Property's of TOptions , and we won't cast them for each Options - var paraexpression = Expression.Parameter(option.GetType(), "x"); + // Todo eventuell schönere Lösung finden + var paraexpression = Expression.Parameter(Type.GetType(option.GetType().FullName), "x"); foreach (var prop in option.GetType().GetProperties()) { var val = Expression.Constant(prop.GetValue(option)); var memberexpression = Expression.PropertyOrField(paraexpression, prop.Name); - var assign = Expression.Assign(memberexpression, val); - - var exp = Expression.Lambda>(assign, paraexpression); - builder.Services.Configure(instanceName, exp.Compile()); + if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(string) || prop.PropertyType == typeof(bool)) + { + var assign = Expression.Assign(memberexpression, Expression.Convert(val, prop.PropertyType)); + var exp = Expression.Lambda>(assign, paraexpression); + builder.Services.Configure(instanceName, exp.Compile()); + } + else + { + Console.WriteLine(prop.PropertyType + "No Support"); + } } + builder.Services.AllowResolvingKeyedServicesAsDictionary(); builder.Services.AddKeyedSingleton(instanceName); }