Open jons-bakerhill opened 5 months ago
I got things to work via the code below, would be nice to know if there's a better way though.
public static IEnumerable<IType> GetClassTypes(object publicProperties)
{
IEnumerable<IProperty> cast = publicProperties as IEnumerable<IProperty>
?? (publicProperties as IEnumerable<object>).Cast<IProperty>();
if (cast == null)
{
System.Diagnostics.Debugger.Launch();
}
return cast
.Select(x => x.Type.Unwrap())
.Where(x => !x.IsPrimitive && !x.IsValueType || x.IsEnum)
.Distinct()
.ToArray();
}
Scriban is a typeless language and its built-in functions do not care about returning the correct type.
As an alternative to what you already got, you could make a custom function to select public properties that will return IEnumerable<IProperty>
, that way you should be able to use the original/typed version of GetClassTypes(IEnumerable<IProperty> publicProperties)
.
I have the following template code
where GetClassTypes is defined as
public static IEnumerable<IType> GetClassTypes(IEnumerable<IProperty> publicProperties)
When rendering I get the error "Unable to convert type
range
toIEnumerable<IProperty>
"Is there a way to join arrays and keep type information?