/// <summary> /// Creates the combinator. /// </summary> public virtual BinaryCombinator CreateCombinator(Type combinatorType, CombinatorBase left, CombinatorBase right) { Assume.NotNull(combinatorType, nameof(combinatorType)); Assume.NotNull(left, nameof(left)); Assume.NotNull(right, nameof(right)); /*var constructors = combinatorType.GetConstructors(); // get constructor with two CombinatorBase parameters to instantiate the object var constructor = constructors.FirstOrDefault(ctor => { var parameters = ctor.GetParameters(); return parameters.Length == 2 && parameters.Select(param => param.ParameterType) .All(type => typeof (CombinatorBase).IsAssignableFrom(type)); }); if (constructor == null) throw new Exception(String.Format("Cannot find Combinator constructor with two CombinatorBase type: {0}", combinatorType.FullName)); return constructor.Invoke(new Object[] {left, right}) as BinaryCombinator;*/ var combinator = (BinaryCombinator)objectCreator.Create(combinatorType, left, right); if (combinator == null) throw new Exception(String.Format("Cannot find Combinator constructor with two CombinatorBase type: {0}", combinatorType.FullName)); return combinator; }
/// <summary> /// Initializes a new instance of the <see cref="BinaryCombinator"/> class. /// </summary> protected BinaryCombinator(CombinatorBase left, CombinatorBase right) { Assume.NotNull(left, nameof(left)); Assume.NotNull(right, nameof(right)); Left = left; Right = right; }
/// <summary> /// Initializes a new instance of the <see cref="RelativeNodeCombinator"/> class. /// </summary> public RelativeNodeCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Initializes a new instance of the <see cref="ConcatCombinator"/> class. /// </summary> public ConcatCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Initializes a new instance of the <see cref="ChildrenCombinator"/> class. /// </summary> public ChildrenCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Initializes a new instance of the <see cref="ParentCombinator"/> class. /// </summary> public ParentCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Initializes a new instance of the <see cref="RelativeSyntaxNodeCombinator"/> class. /// </summary> public RelativeSyntaxNodeCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Initializes a new instance of the <see cref="HasModifier"/> class. /// </summary> public HasModifier(Object combinator) { this.combinator = combinator as CombinatorBase; }
/// <summary> /// Initializes a new instance of the <see cref="HasModifier"/> class. /// </summary> public ContainsModifier(Object combinator) { var rightCombinator = combinator as CombinatorBase; this.combinator = new RelativeNodeCombinator(new UniversalCombinator(), rightCombinator); }
/// <summary> /// Resolves the CombinatorElement. /// </summary> private BinaryCombinator resolveCombinator(CombinatorElementBase combinatorElement, CombinatorBase left, CombinatorBase right) { var combinators = DescriptorRepository.GetCombinatorDescriptors() .Where(combinator => NameMatcher.Match(combinator.Value, combinatorElement.Value)) .ToArray(); if (combinators.Count() > 1) { throw new Exception($"Ambiguity of combinator element: {combinatorElement.Value}"); } if (!combinators.Any()) { throw new Exception($"Combinator is not found: {combinatorElement.Value}"); } return(SelectorFactory.CreateCombinator(combinators[0].CombinatorType, left, right)); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryCombinator"/> class. /// </summary> public TextCombinator(CombinatorBase left, CombinatorBase right) : base(left, right) { }
/// <summary> /// Resolves the CombinatorElement. /// </summary> private BinaryCombinator resolveCombinator(CombinatorElementBase combinatorElement, CombinatorBase left, CombinatorBase right) { var combinators = DescriptorRepository.GetCombinatorDescriptors() .Where(combinator => NameMatcher.Match(combinator.Value, combinatorElement.Value)) .ToArray(); if (combinators.Count() > 1) throw new Exception($"Ambiguity of combinator element: {combinatorElement.Value}"); if (!combinators.Any()) throw new Exception($"Combinator is not found: {combinatorElement.Value}"); return SelectorFactory.CreateCombinator(combinators[0].CombinatorType, left, right); }
/// <summary> /// Initializes a new instance of the <see cref="SelectorControlFlow"/> class. /// </summary> public SelectorControlFlow(CombinatorBase combinator) { Assume.NotNull(combinator, nameof(combinator)); Combinator = new RelativeNodeCombinator(new UniversalCombinator(), combinator); }