示例#1
0
        private static TypedMethodHandler TryUseHandlerMethod(Type accessorType, Type methodOwner, System.Reflection.MethodInfo mi)
        {
            System.Reflection.MethodInfo accessor_method = accessorType.GetMethod(mi.Name);
            if (accessor_method == null)
            {
                //return null; // this Handle Method does not handle accessor's method;
                throw new InvalidOperationException("Access method '" + mi.Name + "' on type '" + accessorType.Name + "' could not be found.");
            }

            var prms = mi.GetParameters();

            if (prms.Length == 0)
            {
                return(null);
            }
            var         prm0 = prms[0];
            IComparable handlerCommandText = StoreLakeDao.TryGetCommandText(methodOwner, mi.Name);

            if (handlerCommandText == null)
            {
                // no command handler here. try an accessor type - (from attribute?)?
                handlerCommandText = StoreLakeDao.TryGetCommandText(accessorType, mi.Name);
                if (handlerCommandText == null)
                {
                    //System.Reflection.MethodInfo accessor_method_x = accessorType.GetMethod(mi.Name);
                    //if (accessor_method == null)
                    //{
                    //    return null;
                    //}

                    throw new InvalidOperationException(TypedMethodHandler.BuildMismatchMethodExpectionText(mi, accessor_method, "CommandText field '" + mi.Name + "CommandText' could not be found."));
                }
            }

            var handler = new TypedMethodHandler(mi, false, handlerCommandText);

            if (handler.ValidateReadMethodX(accessor_method))
            {
                return(handler);
            }
            return(null);
        }
示例#2
0
        public void RegisterAddedCommandHandlerContract(DataSet db, Type contractType, Type implementationType)
        {
            //foreach (Type contractType in contracts)
            {
                //Type implementationType = db.GetCommandExecuteHandlerTypeForContract(contractType);
                if (!contractType.IsAssignableFrom(implementationType))
                {
                    throw new InvalidOperationException("Handler type does not match registered contract type. Expected:" + contractType.AssemblyQualifiedName + ", Actual:" + implementationType.AssemblyQualifiedName);
                }

                //string schemaName = db.GetCommandExecuteHandlerSchemaForContract(contractType);
                string schemaName = string.IsNullOrEmpty(db.Namespace) ? "dbo" : db.Namespace;

                Type methodOwner = contractType;

                foreach (var mi in implementationType.GetMethods())
                {
                    if (mi.DeclaringType == typeof(object))
                    {
                        // skip
                    }
                    else
                    {
                        IComparable handlerCommandText = StoreLakeDao.TryGetCommandText(methodOwner, mi.Name);
                        bool        isProcedureHandler = false;
                        if (handlerCommandText == null)
                        {
                            isProcedureHandler = true;
                            handlerCommandText = '[' + schemaName + "].[" + mi.Name + ']'; // procedure name
                        }
                        var handler = new TypedMethodHandler(mi, isProcedureHandler, handlerCommandText);
                        if (handler.ValidateReadMethodX(mi))
                        {
                            RegisterCommandExecutionHandler(handler);
                        }
                    }
                }
            }
        }