示例#1
0
        /// <summary>
        /// if the value is a List Of T, we FormatString it as a list [1,2,3]
        /// else we FormatString the value
        /// </summary>
        /// <param name="valueFormat"></param>
        /// <param name="ov"></param>
        /// <returns></returns>
        private static string EvaluateValue(string valueFormat, object ov)
        {
            string v = "";

            if (ov == null)
            {
                return(null);
            }
            if (ov == System.DBNull.Value)
            {
                return(null);
            }

            if (ReflectionHelper.IsTypeListOfT(ov.GetType()))
            {
                Type lt = ReflectionHelper.GetListType(ov.GetType());
                if (lt != null)
                {
                    v = typeof(ExtendedFormat).GetMethod("ListToString").MakeGenericMethod(lt).Invoke(null, new object [] { ov }).ToString();
                }
            }
            else
            {
                v = Generated.FormatValueBasedOnType(ov, valueFormat);
            }
            return(v);
        }
示例#2
0
        /// <summary>
        /// Evaluate a property or function on an instance and return the result.
        /// List Of T value are evaluated as [1,2,3]
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="methodOrPropertyName"></param>
        /// <param name="valueFormat"></param>
        /// <returns></returns>
        private static string EvaluatePropertyOrFunction(object instance, string methodOrPropertyName, string valueFormat)
        {
            bool   functionCallMode = false;
            string v = null;

            if (methodOrPropertyName.EndsWith("()"))
            {
                methodOrPropertyName = methodOrPropertyName.Substring(0, methodOrPropertyName.Length - 2);
                functionCallMode     = true;
            }

            if (functionCallMode)
            {
                var o  = ReflectionHelper.ExecuteMethod(instance, methodOrPropertyName);
                var ov = Generated.FormatValueBasedOnType(o, valueFormat);
                v = EvaluateValue(valueFormat, ov);
            }
            else
            {
                if (ReflectionHelper.PropertyExist(instance, methodOrPropertyName))
                {
                    var ov = ReflectionHelper.GetProperty(instance, methodOrPropertyName);
                    v = EvaluateValue(valueFormat, ov);
                }
                else
                {
                    throw new ExtendedFormatException(String.Format(PROPERTY_NOT_FIND_IN_OBJECT, methodOrPropertyName, instance.GetType().FullName));
                }
            }
            return(v);
        }