public static bool AllDynamic <T>(List <T> items, T valueToCompare, OperatorTypes operatorType, bool caseSensitive, SetTypes setType) { Expression <Func <T, bool> > myLambda = CollectionProcessingExpressions.GetLambda <T>(valueToCompare, operatorType, caseSensitive, setType); bool retVal = items.AsQueryable <T>().All(myLambda); return(retVal); }
/// <summary> /// Handle click event on the equals button to perform the operation in course /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Equals_Click(object sender, RoutedEventArgs e) { operands.Add(DisplayNumber); switch (currentOperation) { case OperatorTypes.Addition: DisplayNumber = SumOperands(); break; case OperatorTypes.Subtraction: DisplayNumber = SubstractOperands(); break; case OperatorTypes.Multiplication: DisplayNumber = MultiplyOperands(); break; case OperatorTypes.Division: DisplayNumber = DivideOperands(); break; default: break; } isNewNumber = true; currentOperation = OperatorTypes.None; operands.Clear(); }
public Operator(OperatorTypes operatorType, int precidence, SyntaxKind syntaxKind, string text) { this.OperatorType = operatorType; this.Precidence = precidence; this.SyntaxKind = syntaxKind; this.Text = text; }
public Operator(string symbol, OperatorTypes type, int precedence, AssociativityTypes associativity, OperationTypes operationType) { this.Symbol = symbol; this.Type = type; this.Precedence = precedence; this.AssociativityType = associativity; this.OperationType = operationType; }
// Arbitrary binary operation public static object binary_operator(OperatorTypes op, object a, object b) { if (op >= OperatorTypes.add && op <= OperatorTypes.shr) { return(binary_operations[(int)op](a, b)); } throw new ArgumentException(); }
public ActionResult DeleteConfirmed(int id) { OperatorTypes m = db.OperatorTypes.Find(id); db.OperatorTypes.Remove(m); db.SaveChanges(); return(RedirectToAction("Index", "OperatorTypes")); }
// Arbitrary unary operation public static object unary_operator(OperatorTypes op, object a) { if (op >= OperatorTypes.negate && op <= OperatorTypes.logical_not) { return(unary_operations[(int)(op - OperatorTypes.negate)](a)); } throw new ArgumentException(); }
/// <summary> /// Creates a new Operator. /// </summary> private MorestachioOperator(string operatorText, OperatorTypes operatorType, bool isBinaryOperator, OperatorPlacement placement) { OperatorText = operatorText; OperatorType = operatorType; IsBinaryOperator = isBinaryOperator; Placement = placement; }
/// <summary> /// Creates a new Operator. /// </summary> private MorestachioOperator(string operatorText, OperatorTypes operatorType, bool acceptsTwoExpressions, bool isPrefixOperator) { OperatorText = operatorText; OperatorType = operatorType; AcceptsTwoExpressions = acceptsTwoExpressions; IsPrefixOperator = isPrefixOperator; }
public ActionResult Edit([Bind(Include = "OperatorTypeID,Name")] OperatorTypes m) { if (ModelState.IsValid) { db.Entry(m).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "OperatorTypes")); } return(View(m)); }
public ActionResult Create([Bind(Include = "OperatorTypeID,Name")] OperatorTypes m) { if (ModelState.IsValid) { db.OperatorTypes.Add(m); db.SaveChanges(); return(RedirectToAction("Index", "OperatorTypes")); } return(View(m)); }
static void Main(string[] args) { Configuration.RegisterComponents(); List <string> delimiters = new List <string>(); bool allowNegative = true; int? upperBound = null; OperatorTypes mathOperator = OperatorTypes.Add; foreach (string arg in args) { if (arg == "--denyNegative" || arg == "-dn") { allowNegative = false; } else if (arg.StartsWith("--upperBound") || arg.StartsWith("-ub")) { string[] parts = arg.Split('='); if (parts.Length >= 2) { int value; if (int.TryParse(parts[1], out value)) { upperBound = value; } } } else if (arg.StartsWith("--operator") || arg.StartsWith("-op")) { string[] parts = arg.Split('='); if (parts.Length >= 2) { switch (parts[1]) { case "-": mathOperator = OperatorTypes.Subtract; break; case "*": mathOperator = OperatorTypes.Multiply; break; case "/": mathOperator = OperatorTypes.Divide; break; default: mathOperator = OperatorTypes.Add; break; } } } else { delimiters.Add(arg); } } App app = new App(Configuration.StringParser, Configuration.Calculator); app.Run(delimiters.ToArray(), allowNegative, upperBound, mathOperator); }
public static bool IsCompareToOperator(OperatorTypes operatorTypes) { ComparisonType comparisonType = TranslationHelper.CompareToValidEqualityTypes(operatorTypes); if (comparisonType != ComparisonType.NotSupported) { return(true); } else { return(false); } }
public static bool IsStringComparisonOperator(OperatorTypes operatorTypes) { StringComparisonType stringComparisonType = TranslationHelper.StringComparisonValidTypes(operatorTypes); if (stringComparisonType != StringComparisonType.NotSupported) { return(true); } else { return(false); } }
public override bool ShouldAddProperty(DesignerPropertyInfo property) { if (_obj != null) { DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); DesignerPropertyInfo opr1Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr1"); DesignerPropertyInfo operatorProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Operator"); DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (oplProp.Property != null) { RightValueDef rv = oplProp.GetValue(_obj) as RightValueDef; if (rv != null && rv.IsMethod && rv.Method != null) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } } OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); // action if (this.isAction()) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } // assign else if (operatorType == OperatorTypes.Assign) { return(property.Property != opr1Prop.Property); } // compute else if (operatorType >= OperatorTypes.Add && operatorType <= OperatorTypes.Div) { } // compare else if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { return(property.Property != opr1Prop.Property); } } return(base.ShouldAddProperty(property)); }
/// <summary> /// only the types of equality operators you can use with CompareTo /// </summary> /// <param name="operatorTypes"></param> /// <returns></returns> public static ComparisonType CompareToValidEqualityTypes(OperatorTypes operatorTypes) { switch (operatorTypes) { case OperatorTypes.Is: { return(ComparisonType.Equal); } case OperatorTypes.Less: { return(ComparisonType.LessThan); } case OperatorTypes.LessIs: { return(ComparisonType.LessThanOrEqual); } case OperatorTypes.More: { return(ComparisonType.GreaterThan); } case OperatorTypes.MoreIs: { return(ComparisonType.GreaterThanOrEqual); } case OperatorTypes.Not: { return(ComparisonType.NotEqual); } case OperatorTypes.In: { return(ComparisonType.In); } case OperatorTypes.NotIn: { return(ComparisonType.NotIn); } default: { return(ComparisonType.NotSupported); } } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OperatorTypes operatorTypes = db.OperatorTypes.Find(id); if (operatorTypes == null) { return(HttpNotFound()); } return(View(operatorTypes)); }
private void Operate(ICalculationResult result, OperatorTypes mathOperator, int nextNumber) { string text = nextNumber < 0 ? "(" + nextNumber.ToString() + ")" : nextNumber.ToString(); if (result.Text == "") { result.Numeric = nextNumber; result.Text = text; return; } switch (mathOperator) { case OperatorTypes.Add: result.Numeric += nextNumber; if (!string.IsNullOrEmpty(result.Text)) { result.Text += "+"; } break; case OperatorTypes.Subtract: result.Numeric -= nextNumber; if (!string.IsNullOrEmpty(result.Text)) { result.Text += "-"; } break; case OperatorTypes.Multiply: result.Numeric *= nextNumber; if (!string.IsNullOrEmpty(result.Text)) { result.Text += "*"; } break; case OperatorTypes.Divide: result.Numeric /= nextNumber; if (!string.IsNullOrEmpty(result.Text)) { result.Text += "/"; } break; } result.Text += text; }
public override string GetLabel(DesignerPropertyInfo property) { OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); // compare if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (property.Property == opr2Prop.Property) { return(Resources.Right); } } return(base.GetLabel(property)); }
private OperatorTypes DetectGreaterOrLess() { if (InputLine.Contains(">=")) { this.OperatorType = OperatorTypes.Greater; } else if (InputLine.Contains("<=")) { this.OperatorType = OperatorTypes.Less; } else { this.OperatorType = OperatorTypes.none; } return(this.OperatorType); }
public override string GetLabel(DesignerPropertyInfo property) { OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); // action if (this.isAction()) { DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); if (property.Property == oplProp.Property) { return(Resources.Method); } } // assign else if (operatorType == OperatorTypes.Assign) { DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (property.Property == opr2Prop.Property) { return(Resources.Right); } } // compute else if (operatorType >= OperatorTypes.Add && operatorType <= OperatorTypes.Div) { } // compare else if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (property.Property == opr2Prop.Property) { return(Resources.Right); } } return(base.GetLabel(property)); }
/// <summary> /// Applies a specific math operator on a list of numbers. /// </summary> /// <param name="numbers"></param> /// <param name="mathOperator"></param> /// <returns></returns> public ICalculationResult Calculate(List <int> numbers, OperatorTypes mathOperator) { ICalculationResult result = new Result { Numeric = 0, Text = "" }; foreach (int number in numbers) { Operate(result, mathOperator, number); } if (!string.IsNullOrEmpty(result.Text)) { result.Text += " = " + result.Numeric.ToString(); } return(result); }
public override bool ShouldAddProperty(DesignerPropertyInfo property) { if (_obj != null) { OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); DesignerPropertyInfo opr1Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr1"); DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); DesignerPropertyInfo operatorProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Operator"); DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); // compare if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { return(property.Property != opr1Prop.Property); } } return(true); }
public static StringComparisonType StringComparisonValidTypes(OperatorTypes operatorTypes) { switch (operatorTypes) { case OperatorTypes.Contains: { return(StringComparisonType.Contains); } case OperatorTypes.NoContains: { return(StringComparisonType.NotContains); } case OperatorTypes.Ends: { return(StringComparisonType.EndsWith); } case OperatorTypes.NoEnds: { return(StringComparisonType.NotEndsWith); } case OperatorTypes.Starts: { return(StringComparisonType.StartsWith); } case OperatorTypes.NoStarts: { return(StringComparisonType.NotStartsWith); } default: { return(StringComparisonType.NotSupported); } } }
public override bool ShouldAddProperty(DesignerPropertyInfo property) { if (_obj != null) { OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); DesignerPropertyInfo opr1Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr1"); DesignerPropertyInfo operatorProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Operator"); DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); // action if (this.isAction()) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } // assign else if (operatorType == OperatorTypes.Assign) { return(property.Property != opr1Prop.Property); } // compute else if (operatorType >= OperatorTypes.Add && operatorType <= OperatorTypes.Div) { } // compare else if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { return(property.Property != opr1Prop.Property); } } return(true); }
public Operator(OperatorTypes operatorType) { OperatorType = operatorType; }
/// <summary> /// Handle click event on the division button to perform an division operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Divide_Click(object sender, RoutedEventArgs e) { currentOperation = OperatorTypes.Division; isNewNumber = true; }
/// <summary> /// Handle click event on the multiplication button to perform an multiplication operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Multiply_Click(object sender, RoutedEventArgs e) { currentOperation = OperatorTypes.Multiplication; isNewNumber = true; }
/// <summary> /// Handle click event on the substraction button to perform an substraction operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Subtract_Click(object sender, RoutedEventArgs e) { currentOperation = OperatorTypes.Subtraction; isNewNumber = true; }
/// <summary> /// Handle click event on the addition button to perform an addition operation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Click(object sender, RoutedEventArgs e) { currentOperation = OperatorTypes.Addition; isNewNumber = true; }
//if there is a 'Predicate' attachment, convert it to a Condition node and attach it to the '_custom_condition' connector. private void AutoRestruct(List <Node.ErrorCheck> result, int version, Behaviac.Design.Attachments.Attachment a, Node node) { if (version <= 1) { string attachClass = a.GetType().FullName; if (attachClass.IndexOf("PluginBehaviac.Events.Predicate") >= 0) { DesignerPropertyInfo propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opl"); RightValueDef opl = propInfo.GetValue(a) as RightValueDef; propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opr"); RightValueDef opr = propInfo.GetValue(a) as RightValueDef; propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Operator"); OperatorType oprr = (OperatorType)propInfo.GetValue(a); OperatorTypes oprType = (OperatorTypes)((int)OperatorTypes.Equal - (int)OperatorType.Equal + (int)oprr); propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "BinaryOperator"); Behaviac.Design.Attachments.BinaryOperator binaryOpr = (Behaviac.Design.Attachments.BinaryOperator)propInfo.GetValue(a); string clss = node.GetType().FullName; bool bIsSeqSel = (node.GetType().IsSubclassOf(typeof(Sequence)) || node.GetType().IsSubclassOf(typeof(Selector))); bool bCare = (bIsSeqSel || node.GetType().IsSubclassOf(typeof(Impulse)) ); if (bCare || clss == "PluginBehaviac.Nodes.Query" || clss == "PluginBehaviac.Nodes.DecoratorCountLimit") { node.RemoveAttachment(a); node.Behavior.TriggerWasModified(node); Type newType = Plugin.GetType("PluginBehaviac.Nodes.Condition"); Behaviac.Design.Nodes.Node newNode = Behaviac.Design.Nodes.Node.Create(newType); Behaviac.Design.Nodes.Node.Connector connector = node.GetConnector(Node.Connector.kInterupt); if (connector != null && connector.Identifier == Node.Connector.kInterupt && connector.ChildCount > 0) { //it has multiple Predicates, so insert all of them to a newly created Sequence Node oldOne = (Node)connector.GetChild(0); if (oldOne.GetType().IsSubclassOf(typeof(Condition))) { AddAfterConditions(node, binaryOpr, newNode, connector, oldOne); } else { if (bIsSeqSel) { Debug.Check(oldOne.GetType().IsSubclassOf(typeof(Decorator))); Decorator d = oldOne as Decorator; node = oldOne; connector = node.GetConnector(BaseNode.Connector.kGeneric); oldOne = (Node)d.Children[0]; } if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.And)) { if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or) { node.RemoveChild(connector, oldOne); Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.Or"); Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1); sel.AddChild(BaseNode.Connector.kGeneric, oldOne); sel.AddChild(BaseNode.Connector.kGeneric, newNode); node.AddChild(BaseNode.Connector.kInterupt, sel); } else { oldOne.AddChild(BaseNode.Connector.kGeneric, newNode); } } else if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.Or)) { if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.And) { node.RemoveChild(connector, oldOne); Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.And"); Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1); sel.AddChild(BaseNode.Connector.kGeneric, oldOne); sel.AddChild(BaseNode.Connector.kGeneric, newNode); node.AddChild(BaseNode.Connector.kInterupt, sel); } else { oldOne.AddChild(BaseNode.Connector.kGeneric, newNode); } } else if (oldOne.GetType().IsSubclassOf(typeof(Condition))) { AddAfterConditions(node, binaryOpr, newNode, connector, oldOne); } else { Debug.Check(false); } } } else { //the first condition Behaviac.Design.Nodes.Node notNode = null; if (bIsSeqSel) { //for sequence/selector, it is reverted Type notType = Plugin.GetType("PluginBehaviac.Nodes.DecoratorNot"); notNode = Behaviac.Design.Nodes.Node.Create(notType); node.AddChild(BaseNode.Connector.kInterupt, notNode); notNode.AddChild(BaseNode.Connector.kGeneric, newNode); } else { node.AddChild(BaseNode.Connector.kInterupt, newNode); } } // initialise the attachments properties IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties(); for (int p = 0; p < lp.Count; ++p) { if (lp[p].Property.Name == "Opl") { lp[p].Property.SetValue(newNode, opl, null); } else if (lp[p].Property.Name == "Opr") { lp[p].Property.SetValue(newNode, opr, null); } else if (lp[p].Property.Name == "Operator") { lp[p].Property.SetValue(newNode, oprr, null); } } // update attacheent with attributes newNode.OnPropertyValueChanged(false); } else if (clss == "PluginBehaviac.Nodes.Action") { Type newType = Plugin.GetType("PluginBehaviac.Events.Precondition"); Behaviac.Design.Attachments.Attachment newNode = Behaviac.Design.Attachments.Attachment.Create(newType, node); node.AddAttachment(newNode); node.RemoveAttachment(a); node.Behavior.TriggerWasModified(node); // initialise the attachments properties IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties(); for (int p = 0; p < lp.Count; ++p) { if (lp[p].Property.Name == "BinaryOperator") { lp[p].Property.SetValue(newNode, binaryOpr, null); } else if (lp[p].Property.Name == "Opl") { lp[p].Property.SetValue(newNode, opl, null); } else if (lp[p].Property.Name == "Opr2") { lp[p].Property.SetValue(newNode, opr, null); } else if (lp[p].Property.Name == "Operator") { lp[p].Property.SetValue(newNode, oprType, null); } else if (lp[p].Property.Name == "IsAlive") { lp[p].SetValueFromString(result, newNode, "true"); } } // update attacheent with attributes newNode.OnPropertyValueChanged(false); } else { Debug.Check(false); } } } // if (version <= 1) }
private static MorestachioOperator UnaryOperator(string operatorText, OperatorTypes type, OperatorPlacement placement = OperatorPlacement.Right) { return(new MorestachioOperator(operatorText, type, false, placement)); }
public Operator(OperatorTypes type, string value) { this.Type = type; this.Value = value; }
/// <summary> /// 运算符优先级比较 /// </summary> /// <param name="optA">运算符类型A</param> /// <param name="optB">运算符类型B</param> /// <returns>A与B相比,-1,低;0,相等;1,高</returns> public static int ComparePriority(OperatorTypes optA, OperatorTypes optB) { if (optA == optB) { //A、B优先级相等 return 0; } //乘,除,余(*,/,%) if ((optA >= OperatorTypes.MUL && optA <= OperatorTypes.MOD) && (optB >= OperatorTypes.MUL && optB <= OperatorTypes.MOD)) { return 0; } //加,减(+,-) if ((optA >= OperatorTypes.ADD && optA <= OperatorTypes.SUB) && (optB >= OperatorTypes.ADD && optB <= OperatorTypes.SUB)) { return 0; } //小于,小于或等于,大于,大于或等于(<,<=,>,>=) if ((optA >= OperatorTypes.LT && optA <= OperatorTypes.GE) && (optB >= OperatorTypes.LT && optB <= OperatorTypes.GE)) { return 0; } //等于,不等于(=,<>) if ((optA >= OperatorTypes.ET && optA <= OperatorTypes.UT) && (optB >= OperatorTypes.ET && optB <= OperatorTypes.UT)) { return 0; } //三角函数 if ((optA >= OperatorTypes.TAN && optA <= OperatorTypes.ATAN) && (optB >= OperatorTypes.TAN && optB <= OperatorTypes.ATAN)) { return 0; } if (optA < optB) { //A优先级高于B return 1; } //A优先级低于B return -1; }
private static MorestachioOperator UnaryOperator(string operatorText, OperatorTypes type, bool leftHandOperator) { return(new MorestachioOperator(operatorText, type, false, leftHandOperator)); }
private static MorestachioOperator BinaryOperator(string operatorText, OperatorTypes type) { return(new MorestachioOperator(operatorText, type, true, false)); }