コード例 #1
0
        static void Main(string[] args)
        {
            #region StateMaschine
            IServiceCollection serviceCollection = new ServiceCollection();
            serviceCollection.AddTransient <StateOne>();
            serviceCollection.AddTransient <StateTwo>();
            serviceCollection.AddTransient <StateThree>();

            serviceCollection.AddTransient <IHistroyStateMaschine, HistoryStateMaschine>((services) => {
                var stateMaschine = new HistoryStateMaschine();
                stateMaschine.ServiceCollection = serviceCollection.BuildServiceProvider();
                return(stateMaschine);
            });

            IHistroyStateMaschine stateMaschine = serviceCollection.BuildServiceProvider().GetService <IHistroyStateMaschine>();

            bool run = true;

            Task.Run(() =>
            {
                while (run)
                {
                    Console.WriteLine(string.Format("Time: {0} ms, State: {1}", DateTime.Now.ToString("fffff"), stateMaschine.CurrentState?.GetType().Name ?? "Not started yet"));
                }
            }).ConfigureAwait(false);

            stateMaschine.Start();
            run = false;

            foreach (var state in stateMaschine.States)
            {
                Console.WriteLine(string.Format("State {0}", state.GetType().Name));
            }
            #endregion

            var filterprops = new FilterQueryObject <ObjectToFilter>()
            {
                Object = new[] { new ObjectToFilter()
                                 {
                                     Id = 5, MyString = "Hello", MyObjects = new ObjectToFilter()
                                     {
                                         Id = 4, MyString = "World"
                                     }
                                 }, new ObjectToFilter()
                                 {
                                     Id = 7, MyString = "Exclude"
                                 } },
                PropertieFilters = new List <FilterProperty>(new [] {
                    new FilterProperty()
                    {
                        Method   = "Contains",
                        Property = "MyString",
                        Value    = "Hello"
                    },
                    new FilterProperty()
                    {
                        Method   = "Equals",
                        Property = "MyObjects.Id",
                        Value    = 4
                    }
                })
            };

            var where = filterprops.ToDynamicFilter();

            var r = filterprops.Object.AsQueryable().Where(where.where, where.parameters).ToArray();

            Console.ReadKey();
        }
コード例 #2
0
 public static (string where, object[] parameters) ToDynamicFilter <TObject>(this FilterQueryObject <TObject> filterQueryObject)