Coldairarrow / EFCore.Sharding

Database Sharding For EFCore
Apache License 2.0
694 stars 143 forks source link

属性获取 #97

Closed Coldairarrow closed 3 years ago

Coldairarrow commented 3 years ago

private class ActLikeInterceptor : IInterceptor
        {
            public ActLikeInterceptor(object obj)
            {
                _obj = obj;
            }
            private object _obj;
            public void Intercept(IInvocation invocation)
            {
                var method = invocation.Method;

                //属性处理
                if (method.Name.StartsWith("get_"))
                {
                    invocation.ReturnValue = Dynamic.InvokeGet(_obj, method.Name.Substring(4));

                    return;
                }
                else if (method.Name.StartsWith("set_"))
                {
                    Dynamic.InvokeSet(_obj, method.Name.Substring(4), invocation.Arguments[0]);

                    return;
                }

                //方法处理
                var name = new InvokeMemberName(method.Name, method.GetGenericArguments());
                if (invocation.Method.ReturnType != typeof(void))
                {
                    invocation.ReturnValue = Dynamic.InvokeMember(_obj, name, invocation.Arguments);
                }
                else
                {
                    Dynamic.InvokeMemberAction(_obj, name, invocation.Arguments);
                }
            }
        }
```c#