public void OnNext(T value) { var expression = Expression.Invoke(Expression.Parameter(typeof(Action <IQbserver <T>, T>), "rx://builtin/onNext"), Expression, Expression.Constant(value, typeof(T))); var normalized = ExpressionService.Normalize(expression); Provider.Service.Evaluate(normalized); }
public void Dispose() { var expression = Expression.Invoke(Expression.Parameter(typeof(Action <IQubscription>), "rx://builtin/dispose"), Expression); var normalized = ExpressionService.Normalize(expression); Provider.Service.Evaluate(normalized); }
public void SaveFormulasWithTreeGridFormat(string groupId, string json) { Guid id = new Guid(groupId); DataTable dt = TreeGridJsonParser.JsonToDataTable(json.ToString()); ExpressionService.SaveFormulas(id, dt); }
public IBindToExpression <T> Property <T>( Expression <Func <TDescriptor, IVMPropertyDescriptor <T> > > sourcePropertySelector ) { string path = ExpressionService.GetPropertyPathString(sourcePropertySelector); BinderContext context = QueueBuilderExecution(); context.ExtendPropertyPath(path); context.SourcePropertyType = typeof(T); // HACK ATTACK: My collegas needed a quick fix!!!! if (typeof(T) == typeof(ICommand)) { context.Binding.FallbackValue = DelegateCommand.AlwaysDisabled; context.Binding.TargetNullValue = DelegateCommand.AlwaysDisabled; } // TODO: Always necessary? Is there a better place? Binding binding = context.Binding as Binding; if (binding != null) { binding.ValidatesOnDataErrors = true; } return(new PropertyBinderExpression <T>(context)); }
public void BindVM <TDescriptor>(Expression <Func <TScreen, IViewModelExpression <TDescriptor> > > viewModelSelector, Action <IVMBinder <TDescriptor> > bindingConfigurator) where TDescriptor : VMDescriptor { string pathPrefix = ExpressionService.GetPropertyPathString(viewModelSelector); VMPropertyBinder <TDescriptor> binder = new VMPropertyBinder <TDescriptor>(pathPrefix); bindingConfigurator(binder); binder.Execute(); }
public IQubject <T> Create(string id) { var expression = Expression.Invoke(Expression.Parameter(typeof(Func <IQubjectFactory <T>, string, IQubject <T> >), "rx://builtin/createSubject"), Expression, Expression.Constant(id, typeof(string))); var normalized = ExpressionService.Normalize(expression); Provider.Service.Evaluate(normalized); return(new SubjectProxy <T>(Expression.Parameter(typeof(IQubject <T>), id), Provider)); }
public IQubscription Subscribe(string id, IQbserver <T> observer) { var expression = Expression.Invoke(Expression.Parameter(typeof(Func <IQbservable <T>, string, IQbserver <T>, IQubscription>), "rx://builtin/subscribe"), Expression, Expression.Constant(id, typeof(string)), observer.Expression); var normalized = ExpressionService.Normalize(expression); Provider.Service.Evaluate(normalized); return(Provider.CreateSubscription(Expression.Parameter(typeof(IQubscription), id))); }
public void These_are_valid_expressions(string expression, string[] parameterNames, object[] values, object expected) { ExpressionService service = new ExpressionService(); Type[] types = values?.Select(v => v.GetType()).ToArray() ?? new Type[0]; object actual = service.Evaluate(expression, parameterNames, values, types); Assert.Equal(expected, actual); }
public void Compare_constants_versus_native(ExpressionFeatures features, int trials) { ExpressionService service = new ExpressionService(features); // Constants: CompareTests("Constants", features.ToString(), () => service.Evaluate("100", null, null, null), "Native", () => ConstantNative(), trials, service, 100); }
public ActionResult <ExpressionStructureDto> EvaluateExpression(string expression) { try { return(Ok(ExpressionService.EvaluateExpression(expression))); } catch (Exception e) { return(BadRequest()); } }
public IBindToExpression <IViewModel> BindVM(Expression <Func <TScreen, IViewModel> > viewModelSelector) { BinderContext context = QueueBuilderExecution(); context.SourcePropertyType = typeof(IViewModel); // TODO: Clean up how types are assigned, also check if IBindToExpression has to be generic... context.ExtendPropertyPath( ExpressionService.GetPropertyPathString(viewModelSelector) ); return(new PropertyBinderExpression <IViewModel>(context)); }
public IBindCollectionExpression <TItemDescriptor> CollectionManual <TItemDescriptor>( Expression <Func <TDescriptor, IVMPropertyDescriptor <object> > > collectionPropertySelector ) where TItemDescriptor : VMDescriptor { string path = ExpressionService.GetPropertyPathString(collectionPropertySelector); BinderContext context = QueueBuilderExecution(); context.ExtendPropertyPath(path); return(new VMCollectionBinder <TItemDescriptor>(context)); }
public string ValidateExpression(string expression) { string[] result = ExpressionService.ValidateExpression(expression); if (result.Length == 0) { return("success"); } else { return(result[0]); } }
public void GetPropertyName_WorksWithPropertiesWithDerivedTypes() { Expression <Func <Person, object> > exp = x => x.BirthDate; var path = ExpressionService.GetProperties(exp); Assert.AreEqual("BirthDate", ToString(path)); exp = x => x.Department.Name; path = ExpressionService.GetProperties(exp); Assert.AreEqual("Department.Name", ToString(path)); }
[InlineData("100 + a + b + c", new[] { "a", "b", "c" }, new object[] { 50, 5.5, 0.1 }, 155.6)] // 100 + a + b + c => 155.6 public void These_are_valid_expressions(string expression, string[] parameterNames, object[] values, object expected) { var trace = new TraceSource(nameof(ExpressionService)); trace.Switch.Level = SourceLevels.All; trace.Listeners.Add(new XunitTraceListener(_output)); using (ExpressionService service = new ExpressionService(ExpressionFeatures.None, trace)) { Type[] types = values?.Select(v => v.GetType()).ToArray() ?? Type.EmptyTypes; object actual = service.Evaluate(expression, parameterNames, types, values); Assert.Equal(expected, actual); } }
public string GetFormulaName(string groupId) { Guid id = new Guid(groupId); DataTable dt = ExpressionService.GetFormulaGroupInfoByGroupId(id); if (dt.Rows.Count > 0) { return("{\"name\":\"" + dt.Rows[0]["Name"].ToString() + "\"}"); } else { return(""); } }
static void Main(string[] args) { Console.WriteLine("This program counts the number of found words or expressions in comments from a file C# (*.cs)."); ILoadService loadService = new LoadService(); while (true) { Console.WriteLine("Press any key to select file and count."); Console.ReadKey(); var resultLoad = loadService.LoadFile(); if (resultLoad.Result) { Console.WriteLine(); Console.WriteLine("Please enter a word or expression"); string searchWord = Console.ReadLine(); var expressionService = new ExpressionService(); Console.WriteLine(new string ('-', 50)); var resultCount = expressionService.CountNumberExpressionsAsync(searchWord, resultLoad.Data).Result; if (resultCount.Result) { Console.WriteLine($"{resultCount.Message} {resultCount.Data}."); } else { Console.WriteLine(resultCount.Message); } Console.WriteLine(); } else { Console.WriteLine(resultLoad.Message); } Console.WriteLine(new string('-', 50)); Console.WriteLine("Press key 'E' to exit or any key to continue."); var key = Console.ReadKey(); if (key.Key == ConsoleKey.E) { break; } Console.Clear(); } }
public void GetPropertyName() { string name = ExpressionService.GetPropertyName <Person, DateTime>(p => p.BirthDate); Assert.AreEqual("BirthDate", name); name = ExpressionService.GetPropertyName <Person, Department>(p => p.Department); Assert.AreEqual("Department", name); AssertHelper.Throws <ArgumentException>(() => ExpressionService.GetPropertyName <Person, string>(p => p.Department.Name) ).Containing("more"); AssertHelper.Throws <ArgumentException>(() => ExpressionService.GetPropertyName <Person, Person>(p => p) ).Containing("single"); }
public void GetProperties() { PropertyInfo[] path = ExpressionService.GetProperties <Person, DateTime>(p => p.BirthDate); Assert.AreEqual(1, path.Length); Assert.AreEqual("BirthDate", path[0].Name); path = ExpressionService.GetProperties <Person, string>(p => p.Department.Name); Assert.AreEqual(2, path.Length); Assert.AreEqual("Department", path[0].Name); Assert.AreEqual("Name", path[1].Name); path = ExpressionService.GetProperties <Person, Person>(p => p); Assert.AreEqual(0, path.Length); AssertHelper.Throws <ArgumentException>(() => { ExpressionService.GetProperties <Person, DateTime>(p => p.GetBirthDate().Date); }); }
public string GetFormulasWithTreeGridFormat(string groupId) { Guid id = new Guid(groupId); DataTable formulas = ExpressionService.GetFormulasByGroupId(id); DataColumn parentIdColumn = new DataColumn("ParentID"); formulas.Columns.Add(parentIdColumn); foreach (DataRow row in formulas.Rows) { string levelcode = row["LevelCode"].ToString().Trim(); if (levelcode.Length > 3) { row["ParentID"] = levelcode.Substring(0, levelcode.Length - 2); } } return(TreeGridJsonParser.DataTableToJson(formulas, "LevelCode", "ParentID", "Name", "Formula")); }
public void VM <TChildDescriptor>( Expression <Func <TDescriptor, IVMPropertyDescriptor <IViewModelExpression <TChildDescriptor> > > > viewModelPropertySelector, Action <IVMBinder <TChildDescriptor> > viewModelBinder ) where TChildDescriptor : VMDescriptor { string path; // HACK: just a quick fix if (String.IsNullOrEmpty(_pathPrefix)) { path = ExpressionService.GetPropertyPathString(viewModelPropertySelector); } else { path = String.Join(".", _pathPrefix, ExpressionService.GetPropertyPathString(viewModelPropertySelector)); } var binder = new VMPropertyBinder <TChildDescriptor>(pathPrefix: path); viewModelBinder(binder); binder.Execute(); }
public Expression Add(int x, int y) { return(ExpressionService.Add(x, y)); }
private void CompareTests(string task, string usLabel, Func <object> us, string themLabel, Func <object> them, int trials, ExpressionService service, object result) { GC.Collect(); them(); us(); Stopwatch sw = Stopwatch.StartNew(); bool doWork = false; GC.Collect(); sw.Restart(); for (var i = 0; i < trials; i++) { doWork = us() == result; } if (doWork) { throw new Exception("test is not valid"); } double usTime = sw.Elapsed.TotalMilliseconds; GC.Collect(); sw.Restart(); for (var i = 0; i < trials; i++) { doWork = them() == result; } if (doWork) { throw new Exception("test is not valid"); } double themTime = sw.Elapsed.TotalMilliseconds; _output.WriteLine($"{task}: ({usLabel}) @ {trials}x: {usTime}ms, {usTime/themTime:P2}"); _output.WriteLine($"{task}: ({themLabel}) @ {trials}x: {themTime}ms"); }
public Expression Sub(int x, int y) { return(ExpressionService.Subtract(x, y)); }
public Expression Divide(int x, int y) { return(ExpressionService.Divide(x: x, y: y)); }
public void GetPropertyNameParameterless_StaticFieldInExternalClass_Succeeds() { var name = ExpressionService.GetPropertyName(() => Person.DefaultDepartment); Assert.AreEqual("DefaultDepartment", name); }
public Expression Multiply(int x, int y) { return(ExpressionService.Multiply(x, y)); }
public void GetPropertyNameParameterless() { string name = ExpressionService.GetPropertyName(() => BirthDate); Assert.AreEqual("BirthDate", name); }
public Expression Get(long id) { return(ExpressionService.GetById(id)); }
public void GetPropertyNameParameterless_StaticFieldInCallingClass_Succeeds() { var name = ExpressionService.GetPropertyName(() => StaticField); Assert.AreEqual("StaticField", name); }