コード例 #1
0
        public T ExecuteInterfaceMethod <T>(MethodInformation method, Action <T> action)
        {
            DataOptType dataOptType = ((IDataInterface)this).dataOptType;

            method.dataProviderNamespace = dataProviderNamespace;
            method.dataProviderClassName = dataProviderClassName;
            method.fields           = fields;
            method.fieldsType       = fieldsType;
            method.ResultExecMethod = ResultExecMethod;
            method.sqlExecType      = sqlExecType;

            string sqlVarName = "sql";
            DynamicCodeAutoCall dynamicCodeAutoCall = new DynamicCodeAutoCall();

            sql = dynamicCodeAutoCall.ExecReplaceForSqlByFieldName(sql, sqlVarName, method);

            DynamicCodeChange dynamicCodeChange = new DynamicCodeChange();

            try
            {
                dynamicCodeChange.AnalyzeSql(method, dataOptType, sqlVarName, ref sql);
            }
            catch (Exception ex)
            {
                e(ex.ToString(), ErrorLevels.severe);
                throw ex;
            }

            DynamicEntity dynamicEntity = new DynamicEntity();
            T             result        = dynamicEntity.Exec <T>(method, dataOptType, action, sql);

            return(result);
        }
コード例 #2
0
ファイル: AutoCall.cs プロジェクト: daijiu77/ImplementFactory
        /// <summary>
        /// 执行select、insert、update、delete数据操作时被调用
        /// </summary>
        /// <param name="method">接口方法信息对象</param>
        /// <param name="dataOptType">数据操作类型select|insert|update|delete</param>
        /// <param name="sql">sql语句表达式</param>
        /// <param name="code">接口方法代码相关代码字符串</param>
        protected void ExecInterfaceMethodOfCodeStr_DataOpt(MethodInformation method, DataOptType dataOptType, string sql, ref string code)
        {
            StackTrace stackTrace = new StackTrace();
            Type       type       = stackTrace.GetFrame(1).GetMethod().DeclaringType;

            if (null == type.GetInterface("IDataInterface"))
            {
                e("调用该方法的类必须实例接口类 IDataInterface", ErrorLevels.severe);
                throw new Exception("调用该方法的类必须实例接口类 IDataInterface");
            }
            string sqlVarName = "sql";

            DynamicCodeChange dynamicCodeChange = new DynamicCodeChange();

            try
            {
                dynamicCodeChange.AnalyzeSql(method, dataOptType, sqlVarName, ref sql);
            }
            catch (Exception ex)
            {
                e(ex.ToString(), ErrorLevels.severe);
                throw ex;
            }

            code = dynamicCodeAutoCall.ExecReplaceForSqlByFieldName(sql, sqlVarName, method);

            string paraListVarName = "null";

            dynamicCodeAutoCall.DataProviderCode(sqlVarName, method, dataOptType, ref code, ref paraListVarName);
            if (string.IsNullOrEmpty(code) && string.IsNullOrEmpty(sql))
            {
                e("没有提供任何执行语句", ErrorLevels.severe);
                throw new Exception("没有提供任何执行语句");
            }

            string code1 = "";

            if (dataOptType == DataOptType.select ||
                dataOptType == DataOptType.count ||
                DataOptType.procedure == dataOptType)
            {
                code1 = dynamicCodeAutoCall.GetParametersBySqlParameter(sql, method, ref paraListVarName);
                appendCode(method, code1, ref code);

                dynamicCodeAutoCall.MadeExecuteSql(sqlVarName, paraListVarName, method, dataOptType, ref code);
            }
            else
            {
                code1 = dynamicCodeChange.GetParametersBySqlParameter(sql, sqlVarName, method, dataOptType, ref paraListVarName);
                appendCode(method, code1, ref code);
            }
        }