uknys
uknys
CC#
Created by uknys on 12/9/2023 in #help
Generic XML Node to Class
I have still a GenericReadableRow, but I can cast it dynamicaly using attributes to make it "generic"
9 replies
CC#
Created by uknys on 12/9/2023 in #help
Generic XML Node to Class
found a way :
c#
internal static class MyExtensions
{
internal static T Cast<T>(this GenericReadableRow r) where T : new()
{
var result = new T();

foreach (var prop in typeof(T).GetProperties())
{
if (prop.GetCustomAttribute<ValueAttribute>() is ValueAttribute attr)
{
prop.SetValue(result, r.Values[attr.Index]);
}
}

return result;
}
}
c#
internal static class MyExtensions
{
internal static T Cast<T>(this GenericReadableRow r) where T : new()
{
var result = new T();

foreach (var prop in typeof(T).GetProperties())
{
if (prop.GetCustomAttribute<ValueAttribute>() is ValueAttribute attr)
{
prop.SetValue(result, r.Values[attr.Index]);
}
}

return result;
}
}
9 replies
CC#
Created by uknys on 12/9/2023 in #help
Generic XML Node to Class
around 10
9 replies
CC#
Created by uknys on 12/9/2023 in #help
Generic XML Node to Class
It's already generated using dotnet-svcutil, but still doesn't help the GenericReadableRow (which in the end is a List<Object>) which I need to manually unmarshall sadly
9 replies