public static IArgument[] ConvertArguments(MethodInfo method, CommandArguAttribute[] paramInfos, IArguConverter[] converters, IArgument[] args, StringComparison stringComparison) { bool ignoreCases = stringComparison.IsIgnoreCase(); IEnumerator enumerator = converters.GetEnumerator(); IArguConverter curConvtr = ArguConverterManager.GetConverter <ArguConverter>(); for (int i = 0, end = args.Length; i < end; i++) { if (enumerator.MoveNext() && enumerator.Current != null) { curConvtr = enumerator.Current as IArguConverter; } if (!paramInfos[i].ParameterType.IsAssignableFrom(curConvtr.TargetType)) { throw new CommandParameterConvertException(method, "Parameter type not match argument type."); } IArgument curArgu = args[i]; if (!curConvtr.TargetType.IsInstanceOfType(curArgu.ValueObj)) { curConvtr.IgnoreCases = ignoreCases; try { curArgu.ValueObj = curConvtr.Convert(curArgu.ValueObj); } catch (Exception e) { throw new CommandParameterConvertException(method, null, e); } } } return(args); }
public static bool TryConvertArguments(CommandArguAttribute[] paramInfos, IArguConverter[] converters, ref IArgument[] args, StringComparison stringComparison) { bool ignoreCases = stringComparison.IsIgnoreCase(); IEnumerator enumerator = converters.GetEnumerator(); IArguConverter curConvtr = ArguConverterManager.GetConverter <ArguConverter>(); for (int i = 0, end = args.Length; i < end; i++) { if (enumerator.MoveNext() && enumerator.Current != null) { curConvtr = enumerator.Current as IArguConverter; } if (!paramInfos[i].ParameterType.IsAssignableFrom(curConvtr.TargetType)) { return(false); } IArgument curArgu = args[i]; if (!curConvtr.TargetType.IsInstanceOfType(curArgu.ValueObj)) { curConvtr.IgnoreCases = ignoreCases; if (!curConvtr.TryConvert(curArgu.ValueObj, out var valueObj)) { return(false); } curArgu.ValueObj = valueObj; } } return(true); }