Exemplo n.º 1
0
        /// <summary>
        /// 执行操作
        /// </summary>
        /// <param name="data">用于操作的<see cref="DESchemaObjectBase"/>对象</param>
        /// <param name="parent">用于操作的父<see cref="DESchemaObjectBase"/>对象</param>
        /// <param name="deletedByContainer">是否被容器删除</param>
        /// <returns></returns>
        public DESchemaObjectBase DoOperation(IDEObjectOperations operationFacade, DESchemaObjectBase data, DESchemaObjectBase parent, bool deletedByContainer = false)
        {
            MethodName.CheckStringIsNullOrEmpty("MethodName");

            Type type = DEObjectOperations.Instance.GetType();

            MethodInfo mi = type.GetMethod(MethodName);

            (mi != null).FalseThrow("不能在类型{0}中找到方法{1}", type.FullName, MethodName);

            object[] parameters = null;

            if (HasParentParemeter || parent != null)
            {
                if (this.OperationMode == SCObjectOperationMode.Delete)
                {
                    parameters = new object[] { data, parent, deletedByContainer }
                }
                ;
                else
                {
                    parameters = new object[] { data, parent }
                };
            }
            else
            {
                parameters = new object[] { data }
            };

            try
            {
                return((DESchemaObjectBase)mi.Invoke(operationFacade, parameters));
            }
            catch (TargetParameterCountException ex)
            {
                Exception realException = ex.GetRealException();

                throw new ApplicationException(string.Format("调用方法{0}出现异常,参数个数为{1}: {2}",
                                                             this.MethodName, parameters.Length, realException.Message), realException);
            }
            catch (System.Exception ex)
            {
                throw ex.GetRealException();
            }
        }
    }