Mapping delegate created from a generic type definition, doesn't work
This is probably a little bit niche, and could just be my code rather than this awesome project, but I've found that if my mapping delegate returns a generic property then it doesn't work. E.g.
public interface IMapClass{
CustomMapping GetCustomMapping();
}
public class GenericTypeDefClass<T> : IMapClass where T is class, new(){
public CustomMapping GetCustomMapping()
{
return MapProperty;
}
public static T MapProperty(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propertyName, bool recursive)
{
return contentToMapFrom.GetPropertyValue<T>(propertyName, recursive, null);
}
}
//Create a type for GenericTypeDefClass<string>
Type newType = typeof(GenericTypeDefClass<T>).MakeGenericType(typeof(string));
//Create an instance of GenericTypeDefClass<string>
IMapClass c = (IMapClass)Activator.CreateInstance(type);
//Get the delegate
var mappingDelegate = c.GetCustomMapping();
//arguments are typeof(string).FullName and the MapProperty delegate where T is string
Mapper.AddCustomMapping(mappingDelegate.Method.ReturnType.FullName, mappingDelegate);
I can imagine this isn't a problem that many people are coming across, but perhaps you can identify if there is a way around this issue?
Of course, this is actually a moot point if my other post has a solution...
See how my suggestions go on the other post. Hopefully they are easier ways built in - that might need an extra step, but simpler ones. As if I'm honest, this approach with generics and reflection is getting a bit outside my comfort zone!
Mapping delegate created from a generic type definition, doesn't work
This is probably a little bit niche, and could just be my code rather than this awesome project, but I've found that if my mapping delegate returns a generic property then it doesn't work. E.g.
public class GenericTypeDefClass<T> : IMapClass where T is class, new(){ public CustomMapping GetCustomMapping() { return MapProperty; } public static T MapProperty(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propertyName, bool recursive) { return contentToMapFrom.GetPropertyValue<T>(propertyName, recursive, null); } }
I can imagine this isn't a problem that many people are coming across, but perhaps you can identify if there is a way around this issue?
Of course, this is actually a moot point if my other post has a solution...
See how my suggestions go on the other post. Hopefully they are easier ways built in - that might need an extra step, but simpler ones. As if I'm honest, this approach with generics and reflection is getting a bit outside my comfort zone!
No problem. Thanks for all your work in the project.
is working on a reply...