public Type ResolveComponentTypeForObject(object Context, object Model, params Type[] AssignableFrom) { Type result = null; Type[] assignableFrom = new Type[] { typeof(IComponent) }; if (AssignableFrom?.Any() ?? false) { assignableFrom = AssignableFrom.Union(assignableFrom).Distinct().ToArray(); } if (Context is object) { if (Model is object) { var componentMap = ObjectComponentMaps?.LastOrDefault(m => object.Equals(m, Context) && m.ModelType == Model.GetType() && assignableFrom.All(t => t.IsAssignableFrom(m.ComponentType))); if (componentMap is IContextualComponentMap) { result = componentMap.ComponentType; } } if (result is null) { result = ResolveComponentTypeForContext(Context.GetType(), Model.GetType(), AssignableFrom); } } if (result is null) { result = ResolveComponentTypeFor(Model, AssignableFrom); } return(result); }
public Type ResolveComponentTypeFor(Type ModelType, params Type[] AssignableFrom) { Type[] assignableFrom = new Type[] { typeof(IComponent) }; if (AssignableFrom?.Any() ?? false) { assignableFrom = AssignableFrom.Union(assignableFrom).Distinct().ToArray(); } return(ModelType is Type?ComponentMaps?.LastOrDefault(m => m.ModelType.IsAssignableFrom(ModelType) && assignableFrom.All(t => t.IsAssignableFrom(m.ComponentType)))?.ComponentType : null); }
public Type ResolveComponentTypeForContext(Type ContextType, Type ModelType, params Type[] AssignableFrom) { Type result = null; Type[] assignableFrom = new Type[] { typeof(IComponent) }; if (AssignableFrom?.Any() ?? false) { assignableFrom = AssignableFrom.Union(assignableFrom).Distinct().ToArray(); } if (ContextType is Type && ModelType is Type) { var componentMap = ContextualComponentMaps?.Where(m => m.ContextType == ContextType).LastOrDefault(m => m.ModelType == ModelType && assignableFrom.All(t => t.IsAssignableFrom(m.ComponentType))); if (componentMap is IContextualComponentMap) { result = componentMap.ComponentType; } } if (result is null) { result = ResolveComponentTypeFor(ModelType, AssignableFrom); } return(result); }