mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Added default value support to medusa system, thanks to kotz
This commit is contained in:
@@ -459,6 +459,9 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
pb.WithIsMultiple(paramData.IsParams)
|
pb.WithIsMultiple(paramData.IsParams)
|
||||||
.WithIsOptional(paramData.IsOptional)
|
.WithIsOptional(paramData.IsOptional)
|
||||||
.WithIsRemainder(paramData.IsLeftover);
|
.WithIsRemainder(paramData.IsLeftover);
|
||||||
|
|
||||||
|
if (paramData.IsOptional)
|
||||||
|
pb.WithDefault(paramData.DefaultValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
@@ -800,6 +803,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
|
|
||||||
var leftoverAttribute = pi.GetCustomAttribute<leftoverAttribute>(true);
|
var leftoverAttribute = pi.GetCustomAttribute<leftoverAttribute>(true);
|
||||||
var hasDefaultValue = pi.HasDefaultValue;
|
var hasDefaultValue = pi.HasDefaultValue;
|
||||||
|
var defaultValue = pi.DefaultValue;
|
||||||
var isLeftover = leftoverAttribute != null;
|
var isLeftover = leftoverAttribute != null;
|
||||||
var isParams = pi.GetCustomAttribute<ParamArrayAttribute>() is not null;
|
var isParams = pi.GetCustomAttribute<ParamArrayAttribute>() is not null;
|
||||||
var paramType = pi.ParameterType;
|
var paramType = pi.ParameterType;
|
||||||
@@ -857,7 +861,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
throw new ArgumentException("Leftover attribute error.");
|
throw new ArgumentException("Leftover attribute error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdParams.Add(new ParamData(paramType, paramName, hasDefaultValue, isLeftover, isParams));
|
cmdParams.Add(new ParamData(paramType, paramName, hasDefaultValue, defaultValue, isLeftover, isParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ public sealed record ParamData(
|
|||||||
Type Type,
|
Type Type,
|
||||||
string Name,
|
string Name,
|
||||||
bool IsOptional,
|
bool IsOptional,
|
||||||
|
object? DefaultValue,
|
||||||
bool IsLeftover,
|
bool IsLeftover,
|
||||||
bool IsParams
|
bool IsParams
|
||||||
);
|
);
|
Reference in New Issue
Block a user