Example #1
0
 private static void SetProperty <T>(
     ref T newO,
     ObjectPropertyMapping indexerVal,
     object tempValue,
     CustomMappingFunction customMappingFunction)
 {
     if (customMappingFunction != null)
     {
         var customVal = customMappingFunction.Action.Invoke(tempValue);
         indexerVal.ObjectPropertyInfo.SetValue(newO, customVal);
     }
     else
     {
         if (indexerVal.ObjectType == typeof(Guid))
         {
             indexerVal.ObjectPropertyInfo.SetValue(newO, new Guid(tempValue.ToString()), null);
         }
         else if (indexerVal.ObjectPropertyInfo.PropertyType.IsEnum)
         {
             indexerVal.ObjectPropertyInfo.SetValue(
                 newO,
                 Enum.Parse(indexerVal.ObjectPropertyInfo.PropertyType, tempValue.ToString()),
                 null);
         }
         else if (indexerVal.ObjectType == typeof(bool))
         {
             if (tempValue == "0" || tempValue == "1")
             {
                 indexerVal.ObjectPropertyInfo.SetValue(
                     newO,
                     Convert.ChangeType(int.Parse(tempValue.ToString()), indexerVal.ObjectType),
                     null);
             }
             else
             {
                 indexerVal.ObjectPropertyInfo.SetValue(
                     newO,
                     Convert.ChangeType(tempValue, indexerVal.ObjectType),
                     null);
             }
         }
         else
         {
             indexerVal.ObjectPropertyInfo.SetValue(
                 newO,
                 Convert.ChangeType(tempValue, indexerVal.ObjectType),
                 null);
         }
     }
 }
Example #2
0
        public SqlDataAccessHelper SetPostProcessFunction <T>(
            string targetProperty,
            Func <object, object> mappingFunction)
        {
            targetProperty = targetProperty.ToLower();

            var mappingFunctionWrapper = new CustomMappingFunction
            {
                Action         = mappingFunction,
                TargetProperty = targetProperty,
                TargetType     = typeof(T)
            };

            if (ExecutionContext.ParameterMappingFunctionCollection.ContainsKey(targetProperty))
            {
                ExecutionContext.ParameterMappingFunctionCollection[targetProperty] = mappingFunctionWrapper;
            }
            else
            {
                ExecutionContext.ParameterMappingFunctionCollection.Add(targetProperty, mappingFunctionWrapper);
            }

            return(this);
        }