示例#1
0
        /// <summary>
        /// Gets the source value for a given data object.
        /// </summary>
        /// <param name="dataObject">Data object on which to get the source value.</param>
        /// <returns>Source value.</returns>
        public static object GetSourceValue(IDataObjectBase dataObject)
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }
            var sourceValueType = dataObject.Field.DatatypeOfSource;

            try
            {
                return(dataObject.GetType()
                       .GetMethod("GetSourceValue")
                       .MakeGenericMethod(new[] { sourceValueType })
                       .Invoke(dataObject, null));
            }
            catch (TargetInvocationException ex)
            {
                var deliveryEngineException = ex.InnerException as DeliveryEngineExceptionBase;
                if (deliveryEngineException != null)
                {
                    throw ex.InnerException;
                }
                throw new DeliveryEngineSystemException(Resource.GetExceptionMessage(ExceptionMessage.UnableToGetValueForField, dataObject.Field.NameTarget, dataObject.Field.Table.NameTarget, ex.InnerException.Message), ex.InnerException);
            }
        }
示例#2
0
        /// <summary>
        /// Updates the source value on a given data object.
        /// </summary>
        /// <param name="dataObject">Data object on which to update the source value.</param>
        /// <param name="newSourceValue">New source value.</param>
        public static void UpdateSourceValue(IDataObjectBase dataObject, object newSourceValue)
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }
            var valueType = newSourceValue == null ? typeof(object) : newSourceValue.GetType();
            var updateSourceValueMethod = dataObject.GetType()
                                          .GetMethod("UpdateSourceValue")
                                          .MakeGenericMethod(new[] { valueType });

            try
            {
                updateSourceValueMethod.Invoke(dataObject, new[] { newSourceValue });
            }
            catch (TargetInvocationException ex)
            {
                throw new DeliveryEngineSystemException(Resource.GetExceptionMessage(ExceptionMessage.InvokeError, dataObject.GetType().Name, updateSourceValueMethod.Name, ex.InnerException.Message), ex);
            }
        }