public void Initialize(IArgumentDescription argumentDescription) { Modifier = argumentDescription.Modifier; Name = argumentDescription.Name; Type = argumentDescription.Type; VariableType = argumentDescription.ArgumentType; }
protected bool ValidateMethodArguments(MethodInfo InMethod) { if (InMethod.ReturnType != typeof(string)) { DebugHelper.Assert(false, "Method Command must return a string."); return(false); } ParameterInfo[] parameters = InMethod.GetParameters(); if ((parameters != null) && (parameters.Length > 0)) { for (int i = 0; i < parameters.Length; i++) { ParameterInfo info = parameters[i]; if (info.IsOut) { DebugHelper.Assert(false, string.Format("method command argument can't be out parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, info.ParameterType.Name, info.Name)); return(false); } if (info.ParameterType.IsByRef) { DebugHelper.Assert(false, string.Format("method command argument can't be ref parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, info.ParameterType.Name, info.Name)); return(false); } IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(info.ParameterType); DebugHelper.Assert(description != null); if (!description.AcceptAsMethodParameter(info.ParameterType)) { DebugHelper.Assert(false, string.Format("unsupported argument type for method command. Method:{0}, {1}, {2}", InMethod.Name, info.ParameterType.Name, info.Name)); return(false); } } } return(true); }
protected void UpdateCandinates() { bool bShouldResetNull = true; if (arguments != null) { // try auto complete arguments int Index = arguments.Length - 1; var ArgumentTypes = CurrentCommand.argumentsTypes; if (ArgumentTypes != null && Index < ArgumentTypes.Length) { var ArgumentType = ArgumentTypes[Index]; IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(ArgumentType.argumentType); DebugHelper.Assert(ArgDescInterface != null); List <String> Results = ArgDescInterface.FilteredCandinates(ArgumentType.argumentType, arguments[Index]); ResetCandinates(Results); bShouldResetNull = false; } } if (bShouldResetNull) { CandinatesList.Reset(null); } }
public static bool TypeCastCheck(string InArgument, Type InType, out string OutErrorMessage) { IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(InType); DebugHelper.Assert(description != null); return(description.CheckConvert(InArgument, InType, out OutErrorMessage)); }
private bool DrawArgument(ArgumentDescriptionAttribute InArgAttr, int InIndex, ArgumentDescriptionAttribute[] InArgTypes, ref string[] OutValues, ref string OutValue) { if (InArgAttr.isOptional && this.ShouldSkip(InArgAttr, ref OutValues)) { return(false); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); base.DrawLabel(InArgAttr.name); string name = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard)); GUI.SetNextControlName(name); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(200f) }; OutValue = GUILayout.TextField(OutValue, base.ParentView.CustomTextFieldStyle, options); if (GUI.GetNameOfFocusedControl() == name) { IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(InArgAttr.argumentType); DebugHelper.Assert(description != null); List <string> list = description.FilteredCandinates(InArgAttr.argumentType, OutValue); if ((list != null) && (list.Count > 0)) { for (int i = 0; i < list.Count; i++) { string inButtonText = list[i]; if (!inButtonText.Equals(OutValue, StringComparison.InvariantCultureIgnoreCase) && base.DrawButton(inButtonText, string.Empty)) { OutValue = inButtonText; break; } } } } GUILayout.EndHorizontal(); return(true); }
protected virtual bool CheckDependencies(ArgumentDescriptionAttribute InArugmentDescription, DependencyDescription[] InDependencies, string[] InArguments, out string OutMessage) { OutMessage = string.Empty; if (InArguments == null) { OutMessage = "缺少所有必要参数"; return(false); } for (int i = 0; i < InDependencies.Length; i++) { DependencyDescription dependencyDescription = InDependencies[i]; DebugHelper.Assert(dependencyDescription.dependsIndex >= 0 && dependencyDescription.dependsIndex < this.argumentsTypes.Length, "maybe internal error, can't find depend argument description."); if (dependencyDescription.dependsIndex < 0 || dependencyDescription.dependsIndex >= this.argumentsTypes.Length) { OutMessage = "maybe internal error, can't find depend argument description."; return(false); } DebugHelper.Assert(dependencyDescription.dependsIndex < InArguments.Length); string text = InArguments[dependencyDescription.dependsIndex]; Type argumentType = this.argumentsTypes[dependencyDescription.dependsIndex].argumentType; IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType); DebugHelper.Assert(description != null); text = description.GetValue(argumentType, text); if (dependencyDescription.ShouldBackOff(text)) { OutMessage = string.Format("您必须提供参数<{2}>, 因为参数<{0}>=\"{1}\"", this.argumentsTypes[dependencyDescription.dependsIndex].name, text, InArugmentDescription.name); return(false); } } return(true); }
public static bool TypeCastCheck(string InArgument, Type InType, out string OutErrorMessage) { IArgumentDescription DescriptionInterface = ArgumentDescriptionRepository.instance.GetDescription(InType); DebugHelper.Assert(DescriptionInterface != null); return(DescriptionInterface.CheckConvert(InArgument, InType, out OutErrorMessage)); }
private bool DrawArgument( ArgumentDescriptionAttribute InArgAttr, int InIndex, ArgumentDescriptionAttribute[] InArgTypes, ref string[] OutValues, ref string OutValue ) { if (InArgAttr.isOptional && ShouldSkip(InArgAttr, ref OutValues)) { return(false); } GUILayout.BeginHorizontal(); DrawLabel(InArgAttr.name); // string InputName = string.Format("{0}_{1}", CheatCommand.command.baseName, InArgAttr.index); string InputName = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard)); GUI.SetNextControlName(InputName); OutValue = GUILayout.TextField(OutValue, ParentView.CustomTextFieldStyle, GUILayout.Width(200)); string FocusedName = GUI.GetNameOfFocusedControl(); if (FocusedName == InputName) { // let try get some helper for this argument IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(InArgAttr.argumentType); DebugHelper.Assert(ArgDescInterface != null); List <String> Results = ArgDescInterface.FilteredCandinates(InArgAttr.argumentType, OutValue); if (Results != null && Results.Count > 0) { for (int i = 0; i < Results.Count; ++i) { string CandinateName = Results[i]; if (!CandinateName.Equals(OutValue, StringComparison.InvariantCultureIgnoreCase) && DrawButton(CandinateName) ) { OutValue = CandinateName; break; } } } } GUILayout.EndHorizontal(); return(true); }
public ArgumentDescriptionRepository() { ClassEnumerator classEnumerator = new ClassEnumerator(typeof(ArgumentAttribute), typeof(IArgumentDescription), typeof(ArgumentAttribute).get_Assembly(), true, false, false); ListView <Type> .Enumerator enumerator = classEnumerator.results.GetEnumerator(); while (enumerator.MoveNext()) { Type current = enumerator.Current; ArgumentAttribute argumentAttribute = current.GetCustomAttributes(typeof(ArgumentAttribute), false)[0] as ArgumentAttribute; IArgumentDescription argumentDescription = Activator.CreateInstance(current) as IArgumentDescription; this.Descriptions.Add(argumentAttribute.order, argumentDescription); } }
protected override string Execute(string[] InArguments) { if ((this.argumentsTypes == null) || (this.argumentsTypes.Length == 0)) { return(this.Method.Invoke(null, null) as string); } object[] parameters = new object[this.argumentsTypes.Length]; for (int i = 0; i < parameters.Length; i++) { IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(this.argumentsTypes[i].argumentType); DebugHelper.Assert(description != null); parameters[i] = description.Convert(InArguments[i], this.argumentsTypes[i].argumentType); } return(this.Method.Invoke(null, parameters) as string); }
private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues) { DebugHelper.Assert(InArgAttr.isOptional); foreach (DependencyDescription description in InArgAttr.depends) { string inArgument = ExistsValues[description.dependsIndex]; System.Type argumentType = this.CheatCommand.argumentsTypes[description.dependsIndex].argumentType; IArgumentDescription description2 = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType); DebugHelper.Assert(description2 != null); inArgument = description2.GetValue(argumentType, inArgument); if (description.ShouldBackOff(inArgument)) { return(false); } } return(true); }
private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues) { DebugHelper.Assert(InArgAttr.isOptional); DependencyDescription[] depends = InArgAttr.depends; for (int i = 0; i < depends.Length; i++) { DependencyDescription dependencyDescription = depends[i]; string text = ExistsValues[dependencyDescription.dependsIndex]; Type argumentType = this.CheatCommand.argumentsTypes[dependencyDescription.dependsIndex].argumentType; IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType); DebugHelper.Assert(description != null); text = description.GetValue(argumentType, text); if (dependencyDescription.ShouldBackOff(text)) { return(false); } } return(true); }
public ArgumentDescriptionRepository() { ClassEnumerator ArgDescEnumertor = new ClassEnumerator( typeof(ArgumentAttribute), typeof(IArgumentDescription), typeof(ArgumentAttribute).Assembly); var Iter = ArgDescEnumertor.results.GetEnumerator(); while (Iter.MoveNext()) { Type ThisType = Iter.Current; var Attr = ThisType.GetCustomAttributes(typeof(ArgumentAttribute), false)[0] as ArgumentAttribute; IArgumentDescription DescInterface = Activator.CreateInstance(ThisType) as IArgumentDescription; Descriptions.Add(Attr.order, DescInterface); } }
protected override string Execute(string[] InArguments) { if (argumentsTypes == null || argumentsTypes.Length == 0) { return(Method.Invoke(null, null) as string); } else { object[] Parameters = new object[argumentsTypes.Length]; for (int i = 0; i < Parameters.Length; ++i) { IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(argumentsTypes[i].argumentType); DebugHelper.Assert(ArgDescInterface != null); Parameters[i] = ArgDescInterface.Convert(InArguments[i], argumentsTypes[i].argumentType); } return(Method.Invoke(null, Parameters) as string); } }
private bool DrawArgument(ArgumentDescriptionAttribute InArgAttr, int InIndex, ArgumentDescriptionAttribute[] InArgTypes, ref string[] OutValues, ref string OutValue) { if (InArgAttr.isOptional && this.ShouldSkip(InArgAttr, ref OutValues)) { return(false); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); base.DrawLabel(InArgAttr.name); string text = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard)); GUI.SetNextControlName(text); OutValue = GUILayout.TextField(OutValue, this.ParentView.CustomTextFieldStyle, new GUILayoutOption[] { GUILayout.Width(200f) }); string nameOfFocusedControl = GUI.GetNameOfFocusedControl(); if (nameOfFocusedControl == text) { IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(InArgAttr.argumentType); DebugHelper.Assert(description != null); List <string> list = description.FilteredCandinates(InArgAttr.argumentType, OutValue); if (list != null && list.get_Count() > 0) { for (int i = 0; i < list.get_Count(); i++) { string text2 = list.get_Item(i); if (!text2.Equals(OutValue, 3) && base.DrawButton(text2, string.Empty)) { OutValue = text2; break; } } } } GUILayout.EndHorizontal(); return(true); }
protected bool ValidateMethodArguments(MethodInfo InMethod) { Type ReturnType = InMethod.ReturnType; if (ReturnType != typeof(string)) { DebugHelper.Assert(false, "Method Command must return a string."); return(false); } ParameterInfo[] Parameters = InMethod.GetParameters(); if (Parameters != null && Parameters.Length > 0) { for (int i = 0; i < Parameters.Length; ++i) { ParameterInfo ParameterType = Parameters[i]; if (ParameterType.IsOut) { DebugHelper.Assert(false, string.Format( "method command argument can't be out parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, ParameterType.ParameterType.Name, ParameterType.Name) ); return(false); } /* * if (ParameterType.IsOptional) * { * DebugHelper.Assert(false, * string.Format( * "method command argument can't be optional. Method:{0}, Parameter:{1} {2}", * InMethod.Name, * ParameterType.ParameterType.Name, * ParameterType.Name * ) * ); * * return false; * } */ if (ParameterType.ParameterType.IsByRef) { DebugHelper.Assert(false, string.Format( "method command argument can't be ref parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, ParameterType.ParameterType.Name, ParameterType.Name) ); return(false); } IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(ParameterType.ParameterType); DebugHelper.Assert(ArgDescInterface != null); if (!ArgDescInterface.AcceptAsMethodParameter(ParameterType.ParameterType)) { DebugHelper.Assert(false, string.Format( "unsupported argument type for method command. Method:{0}, {1}, {2}", InMethod.Name, ParameterType.ParameterType.Name, ParameterType.Name ) ); return(false); } } } return(true); }
private static void InitializeArgumentType(ISequenceManager sequenceManager, DescriptionDataTable descriptionCollection, IArgumentDescription argumentDescription) { ArgumentDescription argDescription = (ArgumentDescription)argumentDescription; // 如果类型描述类为空且TypeData非空,则说明该argDescription已经被修改过,无需再执行处理 if (argDescription.TypeDescription == null) { if (null == argDescription.Type) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad, i18N.GetFStr("InvalidArgType", argDescription.Name)); } return; } string fullName = GetFullName(argDescription.TypeDescription); if (descriptionCollection.ContainsType(fullName)) { argDescription.Type = descriptionCollection.GetTypeData(fullName); } else { ITypeData typeData = sequenceManager.CreateTypeData(argDescription.TypeDescription); descriptionCollection.AddTypeData(fullName, typeData); argDescription.Type = typeData; } argDescription.TypeDescription = null; }