public static void addMethodToType(string TypeName, TMethod Method) { if (TransformationConfig.addMethodToType.ContainsKey(TypeName) == false) { TransformationConfig.addMethodToType[TypeName] = new List<TMethod>(); } var list = TransformationConfig.addMethodToType[TypeName]; list.Add(Method); }
private IEnumerator WaitGain(TMethod Gain) { yield return new WaitForSeconds(gainWaitTime); Gain(); }
public IEnumerator ToResult(TMethod del) { yield return new WaitForSeconds(5.0f); del(); }
public TAttribute readAttribute() { string name = currentToken.value; string value = null; getNextToken(); if (currentToken.token == ECodeToken.blEquals) { getNextToken(); if (name == "NamedConstructor") { var ctorName = currentToken.value; var mem = new TMethod(currentInterfaceType); mem.name = "ctor"; mem.aliasName = ctorName; mem.resultType = new TType() { name = "void" }; getNextToken(); if (currentToken.token == ECodeToken.brBraceBegin) { readParameters(mem); } return new TConstructorAttribute(mem) { name = ctorName }; } value = currentToken.value; //TODO getNextToken(); return new TNameAttribute() { name = name, value = value }; } if (name == "Constructor") { var mem = new TMethod(currentInterfaceType); mem.name = "ctor"; mem.resultType = new TType() { name = "void" }; if (currentToken.token == ECodeToken.brBraceBegin) { readParameters(mem); } return new TConstructorAttribute(mem); } if (currentToken.token == ECodeToken.brBraceBegin) { } return new TNameAttribute() { name = name }; }
private void readParameter(TMethod mem) { TParameter param = new TParameter(); if (currentToken.token == ECodeToken.brBraceEnd) { return; } if (currentToken.token == ECodeToken.syComma) { getNextToken(); return; } if (currentToken.token == ECodeToken.kwIn) { getNextToken(); } if (currentToken.token == ECodeToken.brSmallBraceBegin) { param.attributes = readAttributes(); } if (currentToken.token == ECodeToken.ltString) { param.type = readType(); param.type.isResult = false; if (currentToken.token == ECodeToken.syPoint) //method(string name...) { param.type.isArray = true; param.paramArray = true; getNextToken(); getNextToken(); getNextToken(); } param.name = currentToken.value; mem.parameters.Add(param); getNextToken(); } }
private void readParameters(TMethod mem) { while (true) { getNextToken(); readParameter(mem); if (currentToken.token == ECodeToken.brBraceEnd) { getNextToken(); break; } } if (mem.appendParamArray) { mem.parameters.Add(new TParameter() { name = "scriptArgs", type = new TType() { name = "object", isArray = true }, paramArray = true }); } }
private TMember readMember() { bool vStatic = false; bool vConst = false; bool vFinal = false; bool vReadonly = false; bool vAttribute = false; TType type = null; string name = ""; TMember mem = null; var attrList = new TAttributeList(); while (true) { switch (currentToken.token) { case ECodeToken.brSmallBraceBegin: attrList = readAttributes(); break; case ECodeToken.kwStatic: vStatic = true; getNextToken(); break; case ECodeToken.kwConst: vConst = true; getNextToken(); break; case ECodeToken.kwAttribute: vAttribute = true; getNextToken(); break; case ECodeToken.kwReadonly: vReadonly = true; getNextToken(); break; //case ECodeToken.kwFinal: // vFinal = true; // break; case ECodeToken.ltString: type = readType(); name = currentToken.value; getNextToken(); if (currentToken.token == ECodeToken.brBraceBegin) { mem = new TMethod(currentInterfaceType); mem.name = name; mem.resultType = type; mem.attributes = attrList; readParameters((TMethod)mem); checkGotoEndOfStatement(); } else { if (vAttribute) { mem = new TProperty(currentInterfaceType); mem.name = name; mem.resultType = type; mem.attributes = attrList; checkGotoEndOfStatement(); return mem; } else { mem = new TField(currentInterfaceType); mem.name = name; mem.resultType = type; mem.attributes = attrList; if (currentToken.token == ECodeToken.blEquals) { getNextToken(); string Value = currentToken.value; getNextToken(); if (currentToken.token == ECodeToken.ltString) { Value += currentToken.value; if (Value.ToLower() == "0xffffffff") { Value = "0xFFFFFFF"; } } ((TField)mem).value = Value; } return mem; } } break; default: getNextToken(); break; } if (currentToken.token == ECodeToken.syEndOfCommand) { break; } } return mem; }
private void readMembers(TFileType t) { string name = ""; bool vStatic = false; bool vFinal = false; while (currentToken != null) { if (currentToken.token == ECodeToken.brBigBraceEnd) { break; } TMember mem = readMember(); if (mem != null) { if (!mem.name.ToLower().StartsWith("webkit") && !mem.name.ToLower().StartsWith("onwebkit")) { if (mem is TMethod) { var met = mem as TMethod; for (var i = 0; i < met.parameters.Count; i++) { if (met.parameters[i].isOptional()) { var newMem = new TMethod(t) { baseMethod = met.baseMethod, isPrivate = met.isPrivate, name = met.name, resultType = met.resultType }; for (var i2 = 0; i2 < i; i2++) { newMem.parameters.Add(met.parameters[i2]); } t.members.addWithCheck(newMem); } } } t.members.addWithCheck(mem); } } getNextToken(); } }
private static void setTransformations() { //In c#-bindinds, types beginning with "HTML" will be renamed to "Html". //THe output generates still the "HTML" version, for example //c#: el is HtmlImageElement //js: el instanceof HTMLImageElement Transformations.renameType("EventListener", "Function"); Transformations.generateElementConstructorForType("HTML", "Element"); //This will extract "hr" from HtmlHrElement and generates document.createElement('hr') Transformations.generateElementConstructorForType("SVG", "Element"); //Extracting the tagName will sometimes not get the correct tagname. Here they can specified more detailed. Transformations.generateElementConstructorCorrectTagName("HTMLImageElement", "img"); Transformations.generateElementConstructorCorrectTagName("HTMLAnchorElement", "a"); Transformations.generateElementConstructorCorrectTagName("HTMLTableCaptionElement", "caption"); Transformations.generateElementConstructorCorrectTagName("HTMLTableCellElement", "td"); Transformations.generateElementConstructorCorrectTagName("HTMLTableColElement", "col"); Transformations.generateElementConstructorCorrectTagName("HTMLTableRowElement", "tr"); Transformations.generateElementConstructorCorrectTagName("HTMLTableSectionElement", "tbody"); //TODO: It can be thead or tfoot, too! Transformations.generateElementConstructorCorrectTagName("HTMLDListElement", "dl"); Transformations.generateElementConstructorCorrectTagName("HTMLOListElement", "ol"); Transformations.generateElementConstructorCorrectTagName("HTMLUListElement", "ul"); Transformations.generateElementConstructorCorrectTagName("HTMLDictionaryElement", "d"); Transformations.generateElementConstructorCorrectTagName("HTMLParagraphElement", "p"); Transformations.generateElementConstructorCorrectTagName("HTMLModElement", "tbody"); // TODO: Could be del or ins, but not mod. mod is an interface. //The Webkit IDL files have sometimes another return type for internal use. Here they can be corrected. Transformations.changeDelegateResultType("PositionCallback", "void"); Transformations.changeDelegateResultType("PositionErrorCallback", "void"); Transformations.renameType("Event", "DomEvent"); var jsonMethod = new TMethod(null); jsonMethod.name = "JSON"; jsonMethod.resultType = new TType() { name = "Object" }; jsonMethod.parameters.Add(new TParameter() { name = "JSONString", type = new TType() { name = "String" } }); Transformations.addMethodToType("Window", jsonMethod); var sendMethod = new TMethod(null); sendMethod.name = "send"; sendMethod.resultType = new TType() { name = "void" }; var Param = new TParameter() { name = "data", type = new TType() { name = "*" } }; Param.attributes.Add(new TNameAttribute(){ name="Optional" }); sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); sendMethod = new TMethod(null); sendMethod.name = "sendArrayBuffer"; sendMethod.aliasName = "send"; sendMethod.resultType = new TType() { name = "void" }; Param = new TParameter() { name = "data", type = new TType() { name = "ArrayBuffer" } }; sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); sendMethod = new TMethod(null); sendMethod.name = "sendBlob"; sendMethod.aliasName = "send"; sendMethod.resultType = new TType() { name = "void" }; Param = new TParameter() { name = "data", type = new TType() { name = "Blob" } }; sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); sendMethod = new TMethod(null); sendMethod.name = "sendDocument"; sendMethod.aliasName = "send"; sendMethod.resultType = new TType() { name = "void" }; Param = new TParameter() { name = "data", type = new TType() { name = "Document" } }; sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); sendMethod = new TMethod(null); sendMethod.name = "sendString"; sendMethod.aliasName = "send"; sendMethod.resultType = new TType() { name = "void" }; Param = new TParameter() { name = "data", type = new TType() { name = "String" } }; sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); sendMethod = new TMethod(null); sendMethod.name = "sendFormData"; sendMethod.aliasName = "send"; sendMethod.resultType = new TType() { name = "void" }; Param = new TParameter() { name = "data", type = new TType() { name = "FormData" } }; sendMethod.parameters.Add(Param); Transformations.addMethodToType("XMLHttpRequest", sendMethod); }
public static CombinedClass GetParsedStructure(Assembly assembly) { var combined = new CombinedClass(); foreach (var aClass in assembly.GetTypes()) { if (!typeof(Microsoft.AspNetCore.Mvc.Controller).IsAssignableFrom(aClass)) { continue; } var cItem = new TClass { ClassName = aClass.Name }; combined.FunctionInfoList.Add(cItem); var methodInfos = aClass.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); if (methodInfos.Length == 0) { continue; } foreach (var method in methodInfos) { MethodCallType callType; var methodParams = method.GetParameters(); var returnType = method.ReturnType; if (method.GetCustomAttribute(typeof(HttpPostAttribute)) != null) { if (!DoesMethodParamsOneOrNoBody(methodParams)) { throw new NotImplementedException($"This Post scenario is not implemented for {aClass.Name} - {method.Name}"); } callType = MethodCallType.Post; } else if (method.GetCustomAttribute(typeof(HttpGetAttribute)) != null) { callType = MethodCallType.Get; if (DoesMethodParamsAnyBody(methodParams)) { throw new NotImplementedException($"This get scenario is not implemented for {aClass.Name} - {method.Name}"); } } else if (method.GetCustomAttribute(typeof(HttpPutAttribute)) != null) { if (!DoesMethodParamsOneOrNoBody(methodParams)) { throw new NotImplementedException($"This put scenario is not implemented for {aClass.Name} - {method.Name}"); } callType = MethodCallType.Put; } else if (method.GetCustomAttribute(typeof(HttpDeleteAttribute)) != null) { if (DoesMethodParamsAnyBody(methodParams)) { throw new NotImplementedException($"This delete scenario is not implemented for {aClass.Name} - {method.Name}"); } callType = MethodCallType.Delete; } else { throw new NotImplementedException("This scenario is not implemented"); } var rName = returnType.Name; var underlysingReturnType = returnType; if (returnType.BaseType == typeof(System.Threading.Tasks.Task)) { (rName, underlysingReturnType) = CodeGenUtils.ProcessGenericVariable(combined, returnType); } else { if (returnType.IsGenericType) { (rName, underlysingReturnType) = CodeGenUtils.ProcessGenericVariable(combined, returnType); } } var mItem = new TMethod { MethodName = method.Name, CallType = callType, OutputParameterType = rName, CanIgnore = CodeGenUtils.CanIgnoreReturnType(underlysingReturnType) }; cItem.Methods.Add(mItem); //var inputParam = ""; foreach (var param in methodParams) { if (!combined.TypescriptModelClassInfoList.Any(x => x.Name == param.ParameterType.Name)) { combined.TypescriptModelClassInfoList.Add(new TypescriptModelClass { Name = param.ParameterType.Name, ModelType = param.ParameterType, CanIgnore = CanIgnoreReturnType(param.ParameterType) }); } mItem.InputParameters.Add(new InputParam { Key = param.ParameterType.Name, Value = param.Name, TypeFullName = param.ParameterType.FullName, InputType = GetInputType(param) }); } } } return(combined); }