Class ParameterBuilder
Utility for building parameters when invoking a command method.
Implements
Namespace: TehGM.Wolfringo.Commands.Parsing
Assembly: Wolfringo.Commands.dll
Syntax
public class ParameterBuilder : IParameterBuilder
Methods
| Improve this Doc View SourceBuildParamsAsync(IEnumerable<ParameterInfo>, ParameterBuilderValues, CancellationToken)
Builds parameters.
Declaration
public async Task<ParameterBuildingResult> BuildParamsAsync(IEnumerable<ParameterInfo> parameters, ParameterBuilderValues values, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ParameterInfo> | parameters | Collection of parameters to be built. |
ParameterBuilderValues | values | Values to use when building params. |
CancellationToken | cancellationToken | Cancellation token used to cancel building |
Returns
Type | Description |
---|---|
Task<ParameterBuildingResult> | Result of the parameters building. |
IsParamAssignable(ParameterInfo, Object)
Checks if parameter can be assigned from given object.
Declaration
protected static bool IsParamAssignable(ParameterInfo parameter, object value)
Parameters
Type | Name | Description |
---|---|---|
ParameterInfo | parameter | The parameter info. |
Object | value | The object to check. |
Returns
Type | Description |
---|---|
Boolean | True if object can be assigned to given param; otherwise false. |
Remarks
This check does null check in addition to reflection type check.
This method is intended to be internal helper reducing code repetition.
IsParamAssignable(Type, Object)
Checks if parameter can be assigned from given object.
Declaration
protected static bool IsParamAssignable(Type type, object value)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of the parameter. |
Object | value | The object to check. |
Returns
Type | Description |
---|---|
Boolean | True if object can be assigned to given param; otherwise false. |
Remarks
This check does null check in addition to reflection type check.
This method is intended to be internal helper reducing code repetition.
TryConvertArgument(ParameterInfo, Int32, ParameterBuilderValues, out Object, out Exception)
Attempts to convert argument to parameter type.
Declaration
protected static bool TryConvertArgument(ParameterInfo parameter, int argIndex, ParameterBuilderValues values, out object result, out Exception error)
Parameters
Type | Name | Description |
---|---|---|
ParameterInfo | parameter | Parameter to convert argument to. |
Int32 | argIndex | Index of argument. |
ParameterBuilderValues | values | Builder values. Must contain Args and ArgumentConverterProvider. |
Object | result | Result of the conversion. Null if conversion failed. |
Exception | error | Exception that occured when converting. Null if there was no exception. |
Returns
Type | Description |
---|---|
Boolean | True if converting was successful; otherwise false. |
TryFindAdditional(Type, IEnumerable<Object>, out Object)
Attempts to find an object of specific type from enumerable of objects.
Declaration
protected static bool TryFindAdditional(Type type, IEnumerable<object> additionals, out object result)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of object to find. |
IEnumerable<Object> | additionals | Enumerable of objects to find from. |
Object | result | Found object. Null if not found. |
Returns
Type | Description |
---|---|
Boolean | True if object was found successfully; otherwise false. |
TryGetAttribute<T>(ParameterInfo, out T)
Attempts to get an attribute present on the parameter.
Declaration
protected static bool TryGetAttribute<T>(ParameterInfo parameter, out T result)
where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
ParameterInfo | parameter | |
T | result |
Returns
Type | Description |
---|---|
Boolean |
Type Parameters
Name | Description |
---|---|
T |
TryGetGenericLogger(Type, IServiceProvider, out Object)
Attempts to create a generic ILogger>T<.
Declaration
public static bool TryGetGenericLogger(Type type, IServiceProvider services, out object result)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Parameter type to create the logger for. |
IServiceProvider | services | Service provider to get logger factory from. |
Object | result | Created logger. Null if failed to create. |
Returns
Type | Description |
---|---|
Boolean | True if successfully created the logger. Otherwise false. |
TryGetService(Type, IServiceProvider, out Object)
Attempts to find a service of type from service provider.
Declaration
public static bool TryGetService(Type type, IServiceProvider services, out object result)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of service to find. |
IServiceProvider | services | Service provider to get service from. |
Object | result | Found service. Null if not found. |
Returns
Type | Description |
---|---|
Boolean | True if service was found successfully; otherwise false. |