Fixes a few bugs with optional params. (#37)
This commit is contained in:
parent
472b84f5ff
commit
d30f93c454
3 changed files with 14 additions and 21 deletions
|
|
@ -194,15 +194,13 @@ namespace Server.Commands
|
|||
int totalParams = 0;
|
||||
|
||||
// Handle optional constructors
|
||||
ParameterInfo[] paramList = ctor.GetParameters().Select(param =>
|
||||
{
|
||||
if (param.DefaultValue is DBNull)
|
||||
ParameterInfo[] paramList = ctor.GetParameters();
|
||||
for (int j = 0; j < paramList.Length; j++)
|
||||
if (!paramList[j].HasDefaultValue)
|
||||
totalParams += 1;
|
||||
|
||||
return param;
|
||||
}).ToArray();
|
||||
|
||||
if (args.Length == totalParams)
|
||||
if (args.Length >= totalParams && args.Length <= paramList.Length)
|
||||
{
|
||||
object[] paramValues = ParseValues(paramList, args);
|
||||
|
||||
|
|
@ -223,25 +221,23 @@ namespace Server.Commands
|
|||
{
|
||||
object[] values = new object[paramList.Length];
|
||||
|
||||
for (int i = 0, a = 0; i < paramList.Length; ++i)
|
||||
for (int i = 0, a = 0; i < paramList.Length; i++)
|
||||
{
|
||||
ParameterInfo param = paramList[i];
|
||||
if (param.DefaultValue is DBNull)
|
||||
{
|
||||
object value = ParseValue(param.ParameterType, args[a++], param.DefaultValue);
|
||||
if (value == null)
|
||||
return null;
|
||||
object value = ParseValue(param.ParameterType, a < args.Length ? args[a++] : null);
|
||||
|
||||
if (value != null)
|
||||
values[i] = value;
|
||||
}
|
||||
else
|
||||
else if (param.HasDefaultValue)
|
||||
values[i] = Type.Missing;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public static object ParseValue(Type type, string value, object defaultValue)
|
||||
public static object ParseValue(Type type, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -630,10 +626,7 @@ namespace Server.Commands
|
|||
{
|
||||
object[] attrs = ctor.GetCustomAttributes(m_ConstructibleType, false);
|
||||
|
||||
if (attrs.Length == 0)
|
||||
return false;
|
||||
|
||||
return accessLevel >= ((ConstructibleAttribute)attrs[0]).AccessLevel;
|
||||
return attrs.Length != 0 && accessLevel >= ((ConstructibleAttribute)attrs[0]).AccessLevel;
|
||||
}
|
||||
|
||||
public static bool IsEnum(Type type)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace Server.Commands
|
|||
}
|
||||
|
||||
[Usage("SpeedBoost [true|false]")]
|
||||
[Description("Enables a speed boost for the invoker. Disable with paramaters.")]
|
||||
[Description("Enables a speed boost for the invoker. Disable with parameters.")]
|
||||
private static void SpeedBoost_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
|
|
|
|||
|
|
@ -4845,7 +4845,7 @@ namespace Server
|
|||
catch
|
||||
{
|
||||
Console.WriteLine(
|
||||
"Warning: 0x{0:X}: Item must have a zero paramater constructor to be separated from a stack. '{1}'.",
|
||||
"Warning: 0x{0:X}: Item must have a zero parameter constructor to be separated from a stack. '{1}'.",
|
||||
oldItem.Serial.Value, oldItem.GetType().Name);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue