private static SourceNode buildNode(ISourceNode node, bool recursive, IEnumerable <Type> annotationsToCopy) { var me = new SourceNode(node.Name, node.Text); var rts = node.Annotation <IResourceTypeSupplier>(); if (rts != null) { me.ResourceType = rts.ResourceType; } foreach (var t in annotationsToCopy ?? Enumerable.Empty <Type>()) { foreach (var ann in node.Annotations(t)) { me.AddAnnotation(ann); } } if (recursive) { me.AddRange(node.Children().Select(c => buildNode(c, recursive: true, annotationsToCopy: annotationsToCopy))); } return(me); }
private IEnumerable <ITypedElement> runAdditionalRules(IEnumerable <ITypedElement> children) { #pragma warning disable 612, 618 var additionalRules = _source.Annotations(typeof(AdditionalStructuralRule)); var stateBag = new Dictionary <AdditionalStructuralRule, object>(); foreach (var child in children) { foreach (var rule in additionalRules.Cast <AdditionalStructuralRule>()) { stateBag.TryGetValue(rule, out object state); state = rule(child, this, state); if (state != null) { stateBag[rule] = state; } } yield return(child); } #pragma warning restore 612, 618 }
IEnumerable <object> IAnnotated.Annotations(Type type) => Current.Annotations(type);