private static object InvokeHelper(CallInfo callinfo, IList <object> args, Activate buildType = null) { bool setWithName = true; object theArgument = null; if (callinfo.ArgumentNames.Count == 0 && callinfo.ArgumentCount == 1) { theArgument = args[0]; if (TypeFactorization.IsTypeAnonymous(theArgument) || theArgument is IEnumerable <KeyValuePair <string, object> > ) { setWithName = false; } } if (setWithName && callinfo.ArgumentNames.Count != callinfo.ArgumentCount) { throw new ArgumentException("Requires argument names for every argument"); } object result; if (buildType != null) { result = buildType.Create(); } else { try { result = Activator.CreateInstance <TObjectProtoType>(); } catch (MissingMethodException) { result = InvocationBinding.CreateInstance(typeof(TObjectProtoType)); } } if (setWithName) { theArgument = callinfo.ArgumentNames.Zip(args, (n, a) => new KeyValuePair <string, object>(n, a)); } return(InvocationBinding.InvokeSetAll(result, theArgument)); }