本文整理汇总了C#中IConstraint类的典型用法代码示例。如果您正苦于以下问题:C# IConstraint类的具体用法?C# IConstraint怎么用?C# IConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IConstraint类属于命名空间,在下文中一共展示了IConstraint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And
public virtual IConstraint And(IConstraint andWith)
{
lock (StreamLock())
{
return Join(andWith, true);
}
}
示例2: GetRandomValueCore
protected override object GetRandomValueCore(Type type, IConstraint[] constraints)
{
var valueScaled = _random.NextDouble();
if (type == typeof(float))
return this.ApplyConstraints(
constraints, 0.0f, 1.0f,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(double))
return this.ApplyConstraints(
constraints, 0.0d, 1.0d,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(decimal))
return this.ApplyConstraints(
constraints, 0.0m, 1.0m,
(minValue, maxValue) => minValue + (decimal)valueScaled * (maxValue - minValue)
);
throw new InvalidOperationException(
string.Format("{0} does not support generation of {1}", this.GetType(), type
));
}
示例3: VisitGroup
protected override void VisitGroup(ConstraintGroup node)
{
IConstraint where = null;
for (int i = 0, c = node.Items.Count; i < c; i++)
{
this.Visit(node.Items[i]);
if (i == 0)
{
where = _whereResult;
}
else
{
string op = node.Operators[i - 1];
if (op == Constraint.AndOperator)
{
where = f.And(where, _whereResult);
}
else if (op == Constraint.OrOperator)
{
where = f.Or(where, _whereResult);
}
}
}
_whereResult = where;
}
示例4: FormatDescription
/// <summary>
/// Formats a prefix constraint's description.
/// </summary>
internal static string FormatDescription(string descriptionPrefix, IConstraint baseConstraint)
{
return string.Format(
baseConstraint is EqualConstraint ? "{0} equal to {1}" : "{0} {1}",
descriptionPrefix,
baseConstraint.Description);
}
示例5: Visit
public virtual void Visit(OrExpression expression)
{
expression.Left().Accept(this);
IConstraint left = _constraint;
expression.Right().Accept(this);
left.Or(_constraint);
_constraint = left;
}
示例6: BinaryConstraint
/// <summary>
/// Construct a BinaryConstraint from two other constraints
/// </summary>
/// <param name="left">The first constraint</param>
/// <param name="right">The second constraint</param>
protected BinaryConstraint(IConstraint left, IConstraint right)
: base(left, right)
{
Guard.ArgumentNotNull(left, "left");
this.Left = left;
Guard.ArgumentNotNull(right, "right");
this.Right = right;
}
示例7: BuildMessage
/// <summary>
/// Writes the difference between the constraint and the actual value into a message.
/// </summary>
/// <param name="constraint">The constraint.</param>
public string BuildMessage(IConstraint constraint)
{
this.Message = string.Format("Expected: '{0}' But was : '{1}'"
, constraint.Description
, this.GetString(constraint.Actual));
this.BuildHeader(this.Message, constraint);
return this.Message;
}
示例8: GetRandomValueCore
protected override object GetRandomValueCore(Type type, IConstraint[] constraints)
{
var randomNumber = _random.Next(Int32.MinValue, Int32.MaxValue);
var valueScaled = (decimal)((long)randomNumber - Int32.MinValue) / ((long)Int32.MaxValue - Int32.MinValue);
if (type == typeof(sbyte))
return this.ApplyConstraints(
constraints, sbyte.MinValue, sbyte.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(short))
return this.ApplyConstraints(
constraints, short.MinValue, short.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(int))
return this.ApplyConstraints(
constraints, int.MinValue, int.MaxValue,
(minValue, maxValue) => minValue + valueScaled * ((long)maxValue - minValue)
);
if (type == typeof(long))
return this.ApplyConstraints(
constraints, long.MinValue, long.MaxValue,
(minValue, maxValue) => this.ConstrictToRange(valueScaled, minValue, maxValue)
);
if (type == typeof(byte))
return this.ApplyConstraints(
constraints, byte.MinValue, byte.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(ushort))
return this.ApplyConstraints(
constraints, ushort.MinValue, ushort.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(uint))
return this.ApplyConstraints(
constraints, uint.MinValue, uint.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
if (type == typeof(ulong))
return this.ApplyConstraints(
constraints, ulong.MinValue, ulong.MaxValue,
(minValue, maxValue) => minValue + valueScaled * (maxValue - minValue)
);
throw new InvalidOperationException(
string.Format("{0} does not support generation of {1}", this.GetType(), type
));
}
示例9: InstanceRegistration
public InstanceRegistration(IConstraint constraint, ActionDescriptor actionDescriptor, ControllerDescriptor controllerDescriptor, FilterScope scope1)
: base(actionDescriptor, controllerDescriptor, scope1)
{
if (constraint == null)
{
throw new ArgumentNullException("constraint", "Constraint instance can not be null.");
}
Constraint = constraint;
ConstraintType = Constraint.GetType();
}
示例10: GetRandomValue
public object GetRandomValue(Type type, IConstraint[] constraints)
{
Require.NotNull(type, "type");
Require.That<InvalidOperationException>(
this.IsTypeSupported(type),
"{0} does not support generation of {1}.",
this.GetType(), type
);
return this.GetRandomValueCore(type, constraints);
}
示例11: Constraints
public virtual IConstraints Constraints()
{
lock (_cluster)
{
IConstraint[] constraints = new IConstraint[_queries.Length];
for (int i = 0; i < constraints.Length; i++)
{
constraints[i] = _queries[i].Constraints();
}
return new ClusterConstraints(_cluster, constraints);
}
}
示例12: Constrain
public virtual IConstraint Constrain(object constraint)
{
lock (_cluster)
{
var constraints = new IConstraint[_queries.Length];
for (var i = 0; i < constraints.Length; i++)
{
constraints[i] = _queries[i].Constrain(constraint);
}
return new ClusterConstraint(_cluster, constraints);
}
}
示例13: Pendulum
private Pendulum(Particle point_a_, Particle point_b_, Vector3f equilibrium_position_, Render callback_, params IConstraint[] constraints_)
{
point_a = point_a_;
point_b = point_b_;
callback = callback_;
equilibrium_position = equilibrium_position_;
constraints = new IConstraint[constraints_.Length];
for(int i = 0; i < constraints_.Length; ++i)
{
constraints[i] = constraints_[i];
}
}
示例14: Join
internal override IConstraint Join(IConstraint a_with, bool a_and)
{
lock (StreamLock())
{
if (!(a_with is QCon))
{
return null;
}
// resolving multiple constraints happens in QCon for
// a_with, so we simply turn things around
return ((QCon)a_with).Join1(this, a_and);
}
}
示例15: PrefixConstraint
/// <summary>
/// Construct given a base constraint
/// </summary>
/// <param name="baseConstraint"></param>
protected PrefixConstraint(IResolveConstraint baseConstraint)
: base(baseConstraint)
{
Guard.ArgumentNotNull(baseConstraint, "baseConstraint");
this.baseConstraint = baseConstraint.Resolve();
}