private FilterExpression(FilterExpression other) { if (null == other) { throw new ArgumentNullException(nameof(other)); } this.Text = other.Text; this.attributePath = other.attributePath; this.comparisonOperator = other.comparisonOperator; this.filterOperator = other.filterOperator; this.Group = other.Group; this.Level = other.Level; this.logicalOperator = other.logicalOperator; this.value = other.value; if (other.next != null) { this.next = new FilterExpression(other.next); this.next.Previous = this; } }
private void Initialize(Group left, Group @operator, Group right) { if (null == left) { throw new ArgumentNullException(nameof(left)); } if (null == @operator) { throw new ArgumentNullException(nameof(@operator)); } if (null == right) { throw new ArgumentNullException(nameof(right)); } if ( !left.Success || !right.Success || string.IsNullOrEmpty(left.Value) || string.IsNullOrEmpty(right.Value) ) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.attributePath = left.Value; if (!Enum.TryParse <ComparisonOperatorValue>(@operator.Value, out ComparisonOperatorValue comparisonOperatorValue)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.Operator = comparisonOperatorValue; if (!FilterExpression.TryParse(right.Value, out string comparisonValue)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.value = new ComparisonValue(comparisonValue, FilterExpression.Quote == right.Value[0]); int indexRemainder = right.Value.IndexOf(comparisonValue, StringComparison.Ordinal) + comparisonValue.Length; if (indexRemainder >= right.Value.Length) { return; } string remainder = right.Value.Substring(indexRemainder); int indexAnd = remainder.IndexOf(FilterExpression.LogicalOperatorAnd.Value, StringComparison.Ordinal); int indexOr = remainder.IndexOf(FilterExpression.LogicalOperatorOr.Value, StringComparison.Ordinal); int indexNextFilter; int indexLogicalOperator; if (indexAnd >= 0 && (indexOr < 0 || indexAnd < indexOr)) { indexNextFilter = indexAnd + FilterExpression.LogicalOperatorAnd.Value.Length; this.logicalOperator = LogicalOperatorValue.and; indexLogicalOperator = indexAnd; } else if (indexOr >= 0) { indexNextFilter = indexOr + FilterExpression.LogicalOperatorOr.Value.Length; this.logicalOperator = LogicalOperatorValue.or; indexLogicalOperator = indexOr; } else { string tail = remainder.Trim().TrimEnd(FilterExpression.TrailingCharacters.Value); if (!string.IsNullOrWhiteSpace(tail)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } else { return; } } string nextExpression = remainder.Substring(indexNextFilter); int indexClosingBracket = remainder.IndexOf(FilterExpression.BracketClose); int nextExpressionLevel; int nextExpressionGroup; if (indexClosingBracket >= 0 && indexClosingBracket < indexLogicalOperator) { nextExpressionLevel = this.Level - 1; nextExpressionGroup = this.Group - 1; } else { nextExpressionLevel = this.Level; nextExpressionGroup = this.Group; } this.next = new FilterExpression(nextExpression, nextExpressionGroup, nextExpressionLevel); this.next.Previous = this; }