public void Format(IPaperContext context, IObjectFactory factory, Entity entity) { // TODO: deveriamos consultar o catalogo // var paperCatalog = factory.GetInstance<IPaperCatalog>(); // paperCatalog.FindByType(typeof(TPaper)); var paper = (IPaper)Activator.CreateInstance(paperType); var paperDescriptor = new PaperDescriptor(paper); var href = paperDescriptor.PathTemplate.Substring(1); if (paperArgs != null) { foreach (var arg in paperArgs) { var value = Change.To <string>(arg); href = Regex.Replace(href, @"\{[^{}]+\}", value); } } if (Rel?.Any() != true) { this.AddRel(RelNames.Link); } this.Href = href; }
public static object Create(this PaperDescriptor paper, IObjectFactory factory, Type type) { var creator = paper.Factories.FirstOrDefault(x => type.IsAssignableFrom(x.ReturnType)); var instance = creator?.Invoke(paper.Paper, null) ?? factory.CreateObject(type); return(instance); }
public static MethodInfo GetMethod(this PaperDescriptor paper, string methodName) { var method = methodName.EqualsIgnoreCase("Index") ? paper.IndexMethod : paper.Actions.FirstOrDefault(a => a.Name.EqualsIgnoreCase(methodName)); return(method); }