コード例 #1
0
        public LikeQuery WithLiker(User value = null,
                                   ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                   EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(l => l.Liker == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(l => l.Liker != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #2
0
        public QueuedEmailQuery WithAccount(EmailAccount value          = null,
                                            ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                            EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(qe => qe.Account == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(qe => qe.Account != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #3
0
        public PollChoiceItemQuery WithChoice(PollChoice value            = null,
                                              ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                              EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(pci => pci.Choice == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(pci => pci.Choice != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #4
0
        public PublisherQuery WithWebsite(Redirector value            = null,
                                          ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                          EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(p => p.Website == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(p => p.Website != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #5
0
        public ResourceValueQuery WithKey(ResourceKey value           = null,
                                          ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                          EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(rv => rv.Key == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(rv => rv.Key != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #6
0
        public TicketResponseQuery WithInResponseTo(Ticket value = null,
                                                    ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                                    EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(tr => tr.InResponseTo == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(tr => tr.InResponseTo != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #7
0
        public void TestCall3()
        {
            //创建动态类实例代理
            var instance = EntityOperator <TestB> .Create();

            instance.New();
            Assert.Equal("111", instance["Name"].Get <string>());

            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());


            var c = instance["InstanceC"].Get <TestC>();

            Assert.Equal("abc", c.Name);


            instance["InstanceC"].Set(new TestC()
            {
                Name = "bbca"
            });
            Assert.Equal("bbca", instance["InstanceC"].Get <TestC>().Name);
        }
コード例 #8
0
        public PhotoAlbumQuery WithArtist(Artist value = null,
                                          ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                          EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(pa => pa.Artist == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(pa => pa.Artist != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #9
0
        public void TestCall1()
        {
            //ScriptComplier.Init();
            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public class Test
    {
        public Test(){
            Name=""111"";
        }

        public string Name;
        public int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            Type type = RuntimeComplier.GetType(text);
            //创建动态类实例代理
            var instance = EntityOperator.Create(type);

            instance.New();
            //Get动态调用
            Assert.Equal("111", instance["Name"].Get <string>());
            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());
        }
コード例 #10
0
        public OrderLineQuery WithDownload(Download value = null,
                                           ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                           EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(ol => ol.Download == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(ol => ol.Download != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #11
0
        public PollVotingRecordQuery WithPoll(Poll value = null,
                                              ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                              EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(pvr => pvr.SelectedItem.Choice.Poll == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(pvr => pvr.SelectedItem.Choice.Poll != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #12
0
ファイル: EntityExtension.cs プロジェクト: iamshen/Natasha
        public static DynamicBase <T> Caller <T>(this T value)
        {
            var caller = (DynamicBase <T>) EntityOperator <T> .Create();

            caller.SetInstance(value);
            return(caller);
        }
コード例 #13
0
        public ToDoQuery WithStatus(ToDoStatus value            = null,
                                    ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
                                    EntityOperator @operator    = EntityOperator.Equal)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case EntityOperator.Equal:
                Entities = Entities.Where(td => td.Status == value);
                return(this);

            case EntityOperator.NotEqual:
                Entities = Entities.Where(td => td.Status != value);
                return(this);

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
コード例 #14
0
        public void TestCall2()
        {
            //创建动态类实例代理
            var instance = EntityOperator <TestB> .Create();

            instance.New();
            Assert.Equal("111", instance["Name"].Get <string>());

            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());
        }
コード例 #15
0
        public virtual async Task <TEntity> UpdatePortionAsync(TKey key, TUpdateInputDto updateInput, bool autoSave = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            await CheckUpdatePolicyAsync().ConfigureAwait(false);

            var entity = await crudRepository.GetAsync(key).ConfigureAwait(false);

            EntityOperator.UpdatePortionToEntity(updateInput, entity);
            var methodDto = updateInput as IMethodDto <TEntity>;

            if (methodDto != null)
            {
                if (methodDto.MethodInput != null)
                {
                    if (methodDto.MethodInput.UpdateEntityAction != null)
                    {
                        methodDto.MethodInput.UpdateEntityAction(entity);
                    }
                }
            }
            return(await crudRepository.UpdateAsync(entity, autoSave, cancellationToken).ConfigureAwait(false));
        }
コード例 #16
0
        static void Main(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            var action = FastMethodOperator.New
                         .MethodBody("return 1+1;")
                         .Return <int>()
                         .Complie <Func <int> >();

            action();

            //FakeMethodOperator.New
            //    .UseMethod<Program>("Main")
            //    .StaticMethodContent($@"Console.WriteLine(""Hello World!"")")
            //    .Complie<Action<string[]>>();

            Console.WriteLine(FakeMethodOperator.New
                              .UseMethod <TestB>("TestMethod")
                              .StaticMethodContent($@"Console.WriteLine(""Hello World!"")")
                              .Builder()
                              );


            /*
             *   在此之前,你需要右键,选择工程文件,在你的.csproj里面
             *
             *   写上这样一句浪漫的话:
             *
             *      <PreserveCompilationContext>true</PreserveCompilationContext>
             */

            OopOperator <TestAbstract> abstractBuilder = new OopOperator <TestAbstract>();

            abstractBuilder.ClassName("UTestClass");
            abstractBuilder["GetName"] = "return Name;";
            abstractBuilder["GetAge"]  = "return Age;";
            abstractBuilder.Compile();
            var test = abstractBuilder.Create("UTestClass");

            var delegate2 = DelegateOperator <GetterDelegate> .Create("return value.ToString();");

            Console.WriteLine(delegate2(1));
            var delegate3     = "return value.ToString();".Create <GetterDelegate>();
            var delegateConvt = FastMethodOperator.New
                                .Param <string>("value")
                                .MethodBody($@"return value==""true"" || value==""mama"";")
                                .Return <bool>()
                                .Complie <Func <string, bool> >();

            Console.WriteLine(delegateConvt("mama"));

            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public class Test
    {
        public Test(){
            Name=""111"";
            Instance = new Test1();
        }

        public string Name;
        public int Age{get;set;}
        public Test1 Instance;
    }
    public class Test1{
         public string Name=""1"";
    }
}";
            //根据脚本创建动态类
            Type type = RuntimeComplier.GetType(text);
            //创建动态类实例代理
            DynamicOperator instance = new DynamicOperator(type);

            if (instance["Name"].StringValue == "111")
            {
                //调用动态委托赋值
                instance["Name"].StringValue = "222";
            }
            Console.WriteLine("===");
            Console.WriteLine(instance["Instance"].OperatorValue["Name"].StringValue);
            //调用动态类
            Console.WriteLine(instance["Name"].StringValue);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            if (instance["Name"].StringValue == "111")
            {
                //调用动态委托赋值
                instance["Name"].StringValue = "222";
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);


            var newInstance = DynamicOperator.GetOperator(type);

            stopwatch.Restart();
            if (newInstance["Name"].StringValue == "111")
            {
                //调用动态委托赋值
                newInstance["Name"].StringValue = "222";
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);


            var entity = EntityOperator.Create(type);

            entity.New();
            stopwatch.Restart();
            if (entity["Name"].Get <string>() == "111")
            {
                //调用动态委托赋值
                entity["Name"].Set("222");
            }
            stopwatch.Stop();
            entity.Get("Instance").Set("Name", "haha");
            Console.WriteLine(entity.Get("Instance").Get <string>("Name"));
            Console.WriteLine(stopwatch.Elapsed);

            entity = EntityOperator.Create(type);
            entity.New();
            stopwatch.Restart();
            if (entity["Name"].Get <string>() == "111")
            {
                //调用动态委托赋值
                entity["Name"].Set("222");
            }
            stopwatch.Stop();
            Console.WriteLine("new:" + stopwatch.Elapsed);


            for (int i = 0; i < 10; i++)
            {
                newInstance = DynamicOperator.GetOperator(type);
                stopwatch.Restart();
                if (newInstance["Name"].StringValue == "111")
                {
                    //调用动态委托赋值
                    newInstance["Name"].StringValue = "222";
                }
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed);
            }



            for (int i = 0; i < 10; i++)
            {
                entity = EntityOperator.Create(type);
                entity.New();
                stopwatch.Restart();
                if (entity["Name"].Get <string>() == "111")
                {
                    //调用动态委托赋值
                    entity["Name"].Set("222");
                }
                stopwatch.Stop();
                Console.WriteLine("new:" + stopwatch.Elapsed);
            }



            for (int i = 0; i < 10; i++)
            {
                newInstance = DynamicOperator.GetOperator(type);
                stopwatch.Restart();
                if (newInstance["Name"].StringValue == "111")
                {
                    //调用动态委托赋值
                    newInstance["Name"].StringValue = "222";
                }
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed);
            }


            for (int i = 0; i < 10; i++)
            {
                entity = EntityOperator.Create(type);
                entity.New();
                stopwatch.Restart();
                if (entity.Get <string>("Name") == "111")
                {
                    //调用动态委托赋值
                    entity.Set("Name", "222");
                }
                stopwatch.Stop();
                Console.WriteLine("new:" + stopwatch.Elapsed);
            }


            for (int i = 0; i < 10; i++)
            {
                var tEntity = (new TestB()).Caller();
                stopwatch.Restart();
                if (tEntity.Get <string>("Name") == "111")
                {
                    //调用动态委托赋值
                    tEntity.Set("Name", "222");
                }
                stopwatch.Stop();
                Console.WriteLine("new:" + stopwatch.Elapsed);
            }


            //创建动态类实例代理
            DynamicOperator <TestB> instance2 = new DynamicOperator <TestB>();

            if (instance2["Name"].StringValue == "111")
            {
                //调用动态委托赋值
                instance2["Name"].StringValue = "222";
            }
            //调用动态类
            Console.WriteLine(instance2["Name"].StringValue);

            var temp = StaticEntityOperator.Create(typeof(StaticTestB));

            temp.Set("Name", "Name");
            temp.Set("Age", 1);

            Console.WriteLine(temp.Get <string>("Name"));
            Console.WriteLine(temp.Get <int>("Age"));
            Console.WriteLine(StaticTestB.Name);
            Console.WriteLine(StaticTestB.Age);
            Console.ReadKey();
        }