public CommandData(MethodInfo methodData, CommandAttribute commandAttribute, int defaultParameterCount = 0) : this(methodData, commandAttribute.Alias, defaultParameterCount) { CommandDescription = commandAttribute.Description; if (_isMono) { MonoTarget = commandAttribute.MonoTarget; } }
private static object CallInstance(Type classType, string funcName, MonoTargetType targetType, string[] args) { MethodInfo[] methods = ExtractMethods(classType, funcName); MethodInfo method = GetIdealOverload(methods, false, args.Length); object[] parsedArgs = CreateArgs(method, args); IEnumerable <object> targets = InvocationTargetFactory.FindTargets(classType, targetType); return(InvocationTargetFactory.InvokeOnTargets(method, targets, parsedArgs)); }
private static object CallInstance( [CommandParameterDescription("Namespace qualified typename of the class.")] Type classType, [CommandParameterDescription("Name of the method or property.")] string funcName, [CommandParameterDescription("The MonoTargetType used to find the target instances.")] MonoTargetType targetType, [CommandParameterDescription("The arguments for the function call.")] string[] args, [CommandParameterDescription("The types of the arguments to resolve ambiguous overloads.")] Type[] argTypes) { MethodInfo[] methods = ExtractMethods(classType, funcName); MethodInfo method = GetIdealOverload(methods, false, argTypes); object[] parsedArgs = CreateArgs(method, argTypes, args); IEnumerable <object> targets = InvocationTargetFactory.FindTargets(classType, targetType); return(InvocationTargetFactory.InvokeOnTargets(method, targets, parsedArgs)); }
public CommandAttribute([CallerMemberName] string aliasOverride = "", Platform supportedPlatforms = Platform.AllPlatforms, MonoTargetType targetType = MonoTargetType.Single) { Alias = aliasOverride; MonoTarget = targetType; SupportedPlatforms = supportedPlatforms; for (int i = 0; i < _bannedAliasChars.Length; i++) { if (Alias.Contains(_bannedAliasChars[i])) { string errorMessage = $"Development Processor Error: Command with alias '{Alias}' contains the char '{_bannedAliasChars[i]}' which is banned. Unexpected behaviour may occur."; Debug.LogError(errorMessage); Valid = false; throw new ArgumentException(errorMessage, nameof(aliasOverride)); } } }
public CommandAttribute(string aliasOverride, string description, MonoTargetType targetType, Platform supportedPlatforms = Platform.AllPlatforms) : this(aliasOverride, description, supportedPlatforms, targetType) { }
public CommandAttribute(string aliasOverride, string description, Platform supportedPlatforms = Platform.AllPlatforms, MonoTargetType targetType = MonoTargetType.Single) : this(aliasOverride, supportedPlatforms, targetType) { Description = description; }
private static object CallInstance(Type classType, string funcName, MonoTargetType targetType) { return(CallInstance(classType, funcName, targetType, Array.Empty <string>())); }
public CommandData(MethodInfo methodData, string commandName, int defaultParameterCount = 0) { CommandName = commandName; MethodData = methodData; if (string.IsNullOrWhiteSpace(commandName)) { CommandName = methodData.Name; } Type declaringType = methodData.DeclaringType; _isMono = typeof(MonoBehaviour).IsAssignableFrom(declaringType); if (!_isMono) { MonoTarget = MonoTargetType.Registry; } while (declaringType != null) { IEnumerable <CommandPrefixAttribute> prefixAttributes = declaringType.GetCustomAttributes <CommandPrefixAttribute>(); foreach (CommandPrefixAttribute prefixAttribute in prefixAttributes.Reverse()) { if (prefixAttribute.Valid) { string prefix = prefixAttribute.Prefix; if (string.IsNullOrWhiteSpace(prefix)) { prefix = declaringType.Name; } CommandName = $"{prefix}{CommandName}"; } } declaringType = declaringType.DeclaringType; } MethodParamData = methodData.GetParameters(); ParamTypes = new Type[MethodParamData.Length]; for (int i = 0; i < ParamTypes.Length; i++) { ParamTypes[i] = MethodParamData[i].ParameterType; } _defaultParameters = new object[defaultParameterCount]; for (int i = 0; i < defaultParameterCount; i++) { int j = MethodParamData.Length - defaultParameterCount + i; _defaultParameters[i] = MethodParamData[j].DefaultValue; } if (methodData.IsGenericMethodDefinition) { GenericParamTypes = methodData.GetGenericArguments(); GenericSignature = $"<{string.Join(", ", GenericParamTypes.Select(x => x.Name))}>"; } else { GenericParamTypes = Array.Empty <Type>(); } ParameterSignature = string.Empty; for (int i = 0; i < MethodParamData.Length - defaultParameterCount; i++) { ParameterSignature += $"{(i == 0 ? string.Empty : " ")}{MethodParamData[i].Name}"; } if (ParamCount > 0) { CommandSignature += $"{CommandName}{GenericSignature} {ParameterSignature}"; } else { CommandSignature = $"{CommandName}{GenericSignature}"; } }