public static T CopyMixinsFrom <T>(this T newEntity, IModifiableEntity original, params object[] args) where T : IModifiableEntity { var list = (from nm in ((ModifiableEntity)(IModifiableEntity)newEntity).Mixins join om in ((ModifiableEntity)(IModifiableEntity)original).Mixins on nm.GetType() equals om.GetType() select new { nm, om }); foreach (var pair in list) { pair.nm !.CopyFrom(pair.om !, args); /*CSBUG*/ } return(newEntity); }
/// <summary> /// Takes the supplied object and generates a view path based on its Auditable entity properties /// </summary> /// <param name="e">The Auditable entity to generate the view based off of.Uses the ID/Guid and the DateModified to determine if the template needs to be updated</param> /// <param name="toGenerate">Contains the information used to define and generate the object model that will be passed into the view when its rendered</param> /// <param name="TemplateContents">The text string to inject into the template view, the Body of the view beyond what this system generates for injectable model information</param> /// <param name="FieldName">The name of the field of the entity that this view is intended to bind against used during path generation </param> /// <returns></returns> protected GeneratedTemplateInfo GenerateTemplatePath(IModifiableEntity e, IEnumerable <TemplateParameter> toGenerate, string TemplateContents, string FieldName = "") { if (e is null) { throw new ArgumentNullException(nameof(e)); } object model = BuildPageModel(toGenerate); string RelativePath = Path.Combine("Views", "Cache", e.GetType().Name, e.Guid.ToString().Replace("-", ""), FieldName, ((e.DateModified.Value - new DateTime(1970, 1, 1)).TotalMilliseconds.ToString(CultureInfo.CurrentCulture)) + ".cshtml"); string AbsolutePath = Path.Combine(this.HostingEnvironment.ContentRootPath, RelativePath); DirectoryInfo CachePath = new FileInfo(AbsolutePath).Directory; if (!CachePath.Exists) { CachePath.Create(); } lock (TemplateLock) { if (!File.Exists(AbsolutePath)) { string contents = TemplateContents?.ToString(CultureInfo.CurrentCulture) ?? string.Empty; if (!contents.Contains(AUTOGENERATED_TAG)) { List <string> Header = new List <string>() { TUPLE_NOTE, $"@model ({string.Join(", ", PadPageModel(toGenerate).Select(p => $"{p.Type.GetDeclaration()} {p.Name}"))})", AUTOGENERATED_TAG, $"@*{e.Guid}*@" }; contents = string.Join(Environment.NewLine, Header) + Environment.NewLine + Environment.NewLine + Environment.NewLine + contents; } File.WriteAllText(AbsolutePath, contents); } } return(new GeneratedTemplateInfo(AbsolutePath, RelativePath, model)); }