Example #1
0
        public static object CreateObject(this NewExpression node)
        {
            node.MustNotBeNull();
            var args = node.Arguments.Select(a => a.GetValue()).ToArray();

            if (node.Constructor == null)
            {
                return(Activator.CreateInstance(node.Type, args));
            }
            return(node.Constructor.Invoke(args));
        }
Example #2
0
 public static bool HasParameterArgument(this NewExpression node, Type type = null)
 {
     node.MustNotBeNull();
     foreach (var arg in node.Arguments)
     {
         if (arg.IsParameter(type) || arg.BelongsToParameter(type))
         {
             return(true);
         }
     }
     return(false);
 }