PairwiseValue(object value, int weight, bool isNegative, PairwiseValueType valueType) { this.optType = valueType; this.weight = weight; if (weight < 1) { throw new ArgumentOutOfRangeException("weight", "Weight cannot be less than 1"); } if (value is PairwiseValue) { throw new ArgumentException("Can't have a nested PairwiseValue"); } this.value = value; this.isNegative = isNegative; this.aliases = new PairwiseAliasCollection(this); if (this.value == null) { this.valueType = typeof(object); } else { this.valueType = this.value.GetType(); } }
// Rule support public PairwiseValue AddValue(PairwiseValue value) { if (!setFirstType) { firstType = value.PairwiseValueType; setFirstType = true; } if (value.PairwiseValueType != firstType) { throw new PairwiseException(string.Format("Type mismatch: {0} != {1}", this.firstType, value.ValueType, firstType)); } valueCollection.Add(value); return(value); }
internal bool IsCompatibleWith(PairwiseComparison operation) { bool isrelative = !(operation == PairwiseComparison.Equal || operation == PairwiseComparison.NotEqual); PairwiseValueType t = this.PairwiseValueType; if (isrelative) { if (t == PairwiseValueType.Enum || t == PairwiseValueType.ComplexObject) { // throw new NotSupportedException("Not supported: " + operation + " on " + t + "; might be possible, though!"); return(false); } } return(true); }
public PairwiseParameterConstraint(PairwiseParameter first, PairwiseComparison op, PairwiseParameter second) : base(first) { this.op = op; this.second = second; // only allow between the same strong-ish-types if (!this.First.IsCompatibleWith(second)) { throw new ArgumentException(string.Format("{0} != {1}", this.First.PairwiseValueType, this.second.PairwiseValueType)); } bool isrelative = !(op == PairwiseComparison.Equal || op == PairwiseComparison.NotEqual); PairwiseValueType t = this.First.PairwiseValueType; if (isrelative) { if (t == PairwiseValueType.Enum || t == PairwiseValueType.ComplexObject) { throw new NotSupportedException("Not supported: " + op + " on " + t + "; might be possible, though!"); } } }
PairwiseValue(object value, bool isNegative, PairwiseValueType valueType) : this(value, PictConstants.DefaultWeight, isNegative, valueType) { }