public void RunOneLoop(IEnumerable <IDom> blockContents, IDetailBlockStart blockStart, MetadataContextStack contextStack, List <IDom> newList) { var expansionFirstRunner = contextStack.GetValue(Constants.ExpansionFirstRunner) as ExpansionFirstTemplate; var member = blockContents.FirstOrDefault(); var i = 0; while (member != null && blockContents.Contains(member)) { i++; if (i > 1000) { throw new InvalidOperationException("Infinite loop detected"); } var lastMember = member; var copiedMember = member.GetType().GetMethod("Copy").Invoke(member, null) as IDom; var newMembers = expansionFirstRunner.Update(copiedMember, contextStack, ref lastMember); // don't store the end region that matches this block start, because it's being removed newMembers = newMembers .Where(x => { var block = x as IDetailBlockEnd; if (block == null) { return(true); } return(block.GroupGuid != blockStart.GroupGuid); }); newList.AddRange(newMembers); member = lastMember.NextSibling(); } }
private static IEnumerable GetPropList(MetadataContextStack contextStack, string loopOver) { // TODO: Work out multi-part naming var metaVar = loopOver.SubstringBefore("."); var metaProp = loopOver.SubstringAfter("."); var metaVarValue = contextStack.GetValue(metaVar); var metaPropValue = metaVarValue.GetType().GetProperty(metaProp).GetValue(metaVarValue); var propAsIEnumerable = metaPropValue as IEnumerable; return(propAsIEnumerable); }
private static string GetNewString(string input, MetadataContextStack contextStack, Match match) { if (!match.Success) { return(input); } var format = ""; var replaceWith = match.Groups[1].Value; List <string> replaceParts = replaceWith .Split(new string[] { "_dot_" }, StringSplitOptions.None) .ToList(); if (replaceParts.Last().Contains("_as_")) { var lastPart = replaceParts.Last(); format = lastPart.SubstringAfter("_as_"); lastPart = lastPart.SubstringBefore("_as_"); replaceParts.Remove(replaceParts.Last()); replaceParts.Add(lastPart); } var lookup = contextStack.GetValue(replaceParts.First()); if (lookup == null) { return(input); } replaceParts = replaceParts.Skip(1).ToList(); // get tail foreach (var part in replaceParts) { var lookupProperty = lookup.GetType().GetProperty(part); if (lookupProperty == null) { return(input); } lookup = lookupProperty.GetValue(lookup); if (lookup == null) { return(input); } } return(GetWithFormat(lookup.ToString(), format)); }
public T GetBestMetadata <T>(IAttribute attribute, MetadataContextStack contextStack) where T : class { var attributeValue = attribute.AttributeValues.FirstOrDefault(); T value = null; if (attributeValue != null) { var metaName = attributeValue.Value.ToString(); value = contextStack.GetValue(metaName) as T; } else { // Convention var tuple = contextStack.RecentOfType <T>(); if (tuple != null) { value = contextStack.RecentOfType <T>().Item2; } } return(value); }