internal static object[] GetIndexerValues(string path, IList <ParameterInfo> parameters = null, Type castType = null)
        {
            if (path.StartsWith("Item[", StringComparison.Ordinal))
            {
                path = path.Substring(4);
            }
            if (!path.StartsWith("[", StringComparison.Ordinal))
            {
                return(Empty.Array <object>());
            }
            var args = path
                       .RemoveBounds()
                       .Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);
            var result = new object[args.Length];

            for (int i = 0; i < args.Length; i++)
            {
                var s = args[i];
                if (parameters != null)
                {
                    castType = parameters[i].ParameterType;
                }
                if (!string.IsNullOrEmpty(s) && s[0] == '\"' && s.EndsWith("\""))
                {
                    s = s.RemoveBounds();
                }
                result[i] = s == "null" ? null : BindingServiceProvider.ValueConverter(BindingMemberInfo.Empty, castType, s);
            }
            return(result);
        }
Exemple #2
0
 internal static bool TryGetStaticValue <T>(this Expression expression, out T value, bool throwOnError)
 {
     try
     {
         object v;
         var    exp = expression as ConstantExpression;
         if (exp == null)
         {
             v = Expression.Lambda(expression, Empty.Array <ParameterExpression>())
                 .Compile()
                 .DynamicInvoke(Empty.Array <object>());
         }
         else
         {
             v = exp.Value;
         }
         value = (T)BindingServiceProvider.ValueConverter(BindingMemberInfo.Empty, typeof(T), v);
         return(true);
     }
     catch (Exception e)
     {
         value = default(T);
         if (throwOnError)
         {
             throw ExceptionManager.ExpressionShouldBeStaticValue(expression, e);
         }
         return(false);
     }
 }
        internal static object[] GetIndexerValues(IList <ParameterInfo> parameters, string path, Type castType = null)
        {
            string replace = path.Replace("[", string.Empty).Replace("]", string.Empty);
            var    strings = replace.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            var    result  = new object[strings.Length];

            for (int i = 0; i < strings.Length; i++)
            {
                var s = strings[i];
                if (parameters != null)
                {
                    castType = parameters[i].ParameterType;
                }
                result[i] = s == "null" ? null : BindingServiceProvider.ValueConverter(castType, s);
            }
            return(result);
        }