public TSTypeNaming(BindingManager bindingManager, Type type, TypeTransform typeTransform) { this.type = type; var naming = typeTransform?.GetTypeNaming() ?? type.Name; var indexOfTypeName = naming.LastIndexOf('.'); if (indexOfTypeName >= 0) { // 指定的命名中已经携带了"." var indexOfInnerTypeName = naming.IndexOf('+'); if (indexOfInnerTypeName >= 0) { this.jsModule = naming.Substring(0, indexOfInnerTypeName); var rightName = naming.Substring(indexOfInnerTypeName + 1); var lastIndexOfInnerTypeName = rightName.LastIndexOf('+'); if (lastIndexOfInnerTypeName >= 0) { this.jsNamespace = rightName.Substring(0, lastIndexOfInnerTypeName); this.jsName = rightName.Substring(lastIndexOfInnerTypeName + 1); } else { this.jsNamespace = ""; this.jsName = rightName; } } else { this.jsModule = naming.Substring(0, indexOfTypeName); this.jsNamespace = ""; this.jsName = naming.Substring(indexOfTypeName + 1); } var gArgIndex = this.jsName.IndexOf("<"); if (gArgIndex < 0) { this.jsPureName = this.jsName; } else { this.jsPureName = this.jsName.Substring(0, gArgIndex); } } else { this.jsModule = type.Namespace ?? ""; this.jsNamespace = ""; // 处理内部类层级 var declaringType = type.DeclaringType; while (declaringType != null) { this.jsNamespace = string.IsNullOrEmpty(this.jsNamespace) ? declaringType.Name : $"{declaringType.Name}.{this.jsNamespace}"; declaringType = declaringType.DeclaringType; } if (type.IsGenericType) { this.jsName = naming.Contains("`") ? naming.Substring(0, naming.IndexOf('`')) : naming; this.jsPureName = this.jsName; if (type.IsGenericTypeDefinition) { if (!naming.Contains("<")) { this.jsName += "<"; var gArgs = type.GetGenericArguments(); for (var i = 0; i < gArgs.Length; i++) { this.jsName += gArgs[i].Name; if (i != gArgs.Length - 1) { this.jsName += ", "; } } this.jsName += ">"; } } else { foreach (var gp in type.GetGenericArguments()) { this.jsName += "_" + gp.Name; } } } else { this.jsName = naming; //TODO: 整理 jsPureName 的取值流程 (对于泛型中的嵌套的处理等) var gArgIndex = this.jsName.IndexOf("<"); if (gArgIndex < 0) { this.jsPureName = this.jsName; } else { this.jsPureName = this.jsName.Substring(0, gArgIndex); } } } if (string.IsNullOrEmpty(this.jsNamespace)) { this.jsModuleAccess = this.jsName; this.jsModuleImportAccess = this.jsPureName; this.jsLocalName = ""; } else { var i = this.jsNamespace.IndexOf('.'); this.jsModuleAccess = i < 0 ? this.jsNamespace : this.jsNamespace.Substring(0, i); this.jsModuleImportAccess = this.jsModuleAccess; this.jsLocalName = CodeGenUtils.Concat(".", i < 0 ? "" : this.jsNamespace.Substring(i + 1), this.jsName); } if (this.jsModuleAccess.EndsWith("[]")) { this.jsModuleAccess = this.jsModuleAccess.Substring(0, this.jsModuleAccess.Length - 2); } this.jsDepth = this.jsModuleAccess.Split('.').Length; this.jsFullName = CodeGenUtils.Concat(".", jsModule, jsNamespace, jsName); }
public ConstructorBindingInfo(BindingManager bindingManager, Type decalringType) { this.decalringType = decalringType; this.csBindName = bindingManager.GetConstructorBindName(); this.jsName = "constructor"; }
public MethodBindingInfo(BindingManager bindingManager, bool bStatic, string csName, string jsName) { this.csBindName = bindingManager.GetBindName(bStatic, csName); this.jsName = jsName; }
// 收集所有 字段,属性,方法 public void Collect() { this.constructors = new ConstructorBindingInfo(bindingManager, type); var bindingFlags = Binding.DynamicType.PublicFlags; var fields = type.GetFields(bindingFlags); foreach (var field in fields) { if (field.IsSpecialName || field.Name.StartsWith("_JSFIX_")) { bindingManager.Info("skip special field: {0}", field.Name); continue; } if (field.IsStatic && type.IsGenericTypeDefinition) { bindingManager.Info("skip static field in generic type definition: {0}", field.Name); return; } if (field.FieldType.IsPointer) { bindingManager.Info("skip pointer field: {0}", field.Name); continue; } if (field.IsDefined(typeof(JSOmitAttribute), false)) { bindingManager.Info("skip omitted field: {0}", field.Name); continue; } if (field.IsDefined(typeof(ObsoleteAttribute), false)) { bindingManager.Info("skip obsolete field: {0}", field.Name); continue; } if (transform.IsMemberBlocked(field.Name)) { bindingManager.Info("skip blocked field: {0}", field.Name); continue; } if (transform.Filter(field)) { bindingManager.Info("skip filtered field: {0}", field.Name); continue; } AddField(field); } var events = type.GetEvents(bindingFlags); foreach (var evt in events) { if (evt.IsSpecialName) { bindingManager.Info("skip special event: {0}", evt.Name); continue; } if ((evt.AddMethod?.IsStatic == true || evt.RemoveMethod?.IsStatic == true) && type.IsGenericTypeDefinition) { bindingManager.Info("skip static event in generic type definition: {0}", evt.Name); return; } if (evt.EventHandlerType.IsPointer) { bindingManager.Info("skip pointer event: {0}", evt.Name); continue; } if (evt.IsDefined(typeof(ObsoleteAttribute), false)) { bindingManager.Info("skip obsolete event: {0}", evt.Name); continue; } if (evt.IsDefined(typeof(JSOmitAttribute), false)) { bindingManager.Info("skip omitted event: {0}", evt.Name); continue; } if (transform.IsMemberBlocked(evt.Name)) { bindingManager.Info("skip blocked event: {0}", evt.Name); continue; } if (transform.Filter(evt)) { bindingManager.Info("skip filtered event: {0}", evt.Name); continue; } AddEvent(evt); } var properties = type.GetProperties(bindingFlags); foreach (var property in properties) { if (property.IsSpecialName) { bindingManager.Info("skip special property: {0}", property.Name); continue; } if (property.PropertyType.IsPointer) { bindingManager.Info("skip pointer property: {0}", property.Name); continue; } if ((property.GetMethod?.IsStatic == true || property.SetMethod?.IsStatic == true) && type.IsGenericTypeDefinition) { bindingManager.Info("skip static property in generic type definition: {0}", property.Name); return; } if (property.IsDefined(typeof(JSOmitAttribute), false)) { bindingManager.Info("skip omitted property: {0}", property.Name); continue; } if (property.IsDefined(typeof(ObsoleteAttribute), false)) { bindingManager.Info("skip obsolete property: {0}", property.Name); continue; } if (transform.IsMemberBlocked(property.Name)) { bindingManager.Info("skip blocked property: {0}", property.Name); continue; } if (transform.Filter(property)) { bindingManager.Info("skip filtered property: {0}", property.Name); continue; } //NOTE: 索引访问 if (property.Name == "Item") { if (property.CanRead && property.GetMethod != null && property.GetMethod.IsPublic) { if (BindingManager.IsUnsupported(property.GetMethod)) { bindingManager.Info("skip unsupported get-method: {0}", property.GetMethod); continue; } AddMethod(property.GetMethod, false); } if (property.CanWrite && property.SetMethod != null && property.SetMethod.IsPublic) { if (BindingManager.IsUnsupported(property.SetMethod)) { bindingManager.Info("skip unsupported set-method: {0}", property.SetMethod); continue; } AddMethod(property.SetMethod, false); } // bindingManager.Info("skip indexer property: {0}", property.Name); continue; } AddProperty(property); } if (!type.IsAbstract) { var constructors = type.GetConstructors(); foreach (var constructor in constructors) { if (constructor.IsDefined(typeof(JSOmitAttribute), false)) { bindingManager.Info("skip omitted constructor: {0}", constructor); continue; } if (constructor.IsDefined(typeof(ObsoleteAttribute), false)) { bindingManager.Info("skip obsolete constructor: {0}", constructor); continue; } if (BindingManager.ContainsPointer(constructor)) { bindingManager.Info("skip pointer-param constructor: {0}", constructor); continue; } if (BindingManager.ContainsByRefParameters(constructor)) { bindingManager.Info("skip byref-param constructor: {0}", constructor); continue; } if (transform.Filter(constructor)) { bindingManager.Info("skip filtered constructor: {0}", constructor.Name); continue; } AddConstructor(constructor); } } CollectMethods(type.GetMethods(bindingFlags), false); CollectMethods(bindingManager.GetTypeTransform(type).extensionMethods, true); CollectMethods(bindingManager.GetTypeTransform(type).staticMethods, false); }
private void CollectMethods(IEnumerable <MethodInfo> methods, bool asExtensionAnyway) { foreach (var method in methods) { if (BindingManager.IsGenericMethod(method)) { bindingManager.Info("skip generic method: {0}", method); continue; } if (BindingManager.ContainsPointer(method)) { bindingManager.Info("skip unsafe (pointer) method: {0}", method); continue; } if (method.IsSpecialName) { if (!IsSupportedOperators(method)) { bindingManager.Info("skip special method: {0}", method); continue; } } if (method.IsDefined(typeof(JSOmitAttribute), false)) { bindingManager.Info("skip omitted method: {0}", method); continue; } if (method.IsDefined(typeof(ObsoleteAttribute), false)) { bindingManager.Info("skip obsolete method: {0}", method); continue; } if (transform.IsMemberBlocked(method.Name)) { bindingManager.Info("skip blocked method: {0}", method.Name); continue; } if (transform.Filter(method)) { bindingManager.Info("skip filtered method: {0}", method.Name); continue; } if (asExtensionAnyway || BindingManager.IsExtensionMethod(method)) { var targetType = method.GetParameters()[0].ParameterType; var targetInfo = bindingManager.GetExportedType(targetType); if (targetInfo != null) { targetInfo.AddMethod(method, true); continue; } } AddMethod(method, false); } }
public TypeBindingInfo(BindingManager bindingManager, Type type, TypeTransform typeTransform) { this.bindingManager = bindingManager; this.type = type; this.transform = typeTransform; var naming = this.transform.GetTypeNaming() ?? GetNamingAttribute(type); var indexOfTypeName = naming.LastIndexOf('.'); if (indexOfTypeName >= 0) // 内部类 { this.jsNamespace = naming.Substring(0, indexOfTypeName); this.jsName = naming.Substring(indexOfTypeName + 1); this.jsTypeName = this.jsName; } else { if (type.DeclaringType != null) { if (string.IsNullOrEmpty(type.Namespace)) { this.jsNamespace = type.DeclaringType.Name; } else { this.jsNamespace = $"{type.Namespace}.{type.DeclaringType.Name}"; } } else { this.jsNamespace = type.Namespace ?? ""; } do { if (type.IsGenericType) { if (type.IsGenericTypeDefinition) { this.jsName = naming.Contains("`") ? naming.Substring(0, naming.IndexOf('`')) : naming; this.jsTypeName = this.jsName; if (!naming.Contains("<")) { this.jsName += "<"; var gArgs = type.GetGenericArguments(); for (var i = 0; i < gArgs.Length; i++) { this.jsName += gArgs[i].Name; if (i != gArgs.Length - 1) { this.jsName += ", "; } } this.jsName += ">"; } break; } else { this.jsName = naming.Contains("`") ? naming.Substring(0, naming.IndexOf('`')) : naming; this.jsTypeName = this.jsName; foreach (var gp in type.GetGenericArguments()) { this.jsName += "_" + gp.Name; } break; } } this.jsName = naming; this.jsTypeName = this.jsName; } while (false); } this.csBindingName = bindingManager.prefs.typeBindingPrefix + (this.jsNamespace + "_" + this.jsName).Replace('.', '_').Replace('+', '_').Replace('<', '_').Replace('>', '_'); this.constructors = new ConstructorBindingInfo(type); }
public void AddMethod(MethodInfo methodInfo, bool asExtensionAnyway) { if (this.transform.IsBlocked(methodInfo)) { bindingManager.Info("skip blocked method: {0}", methodInfo.Name); return; } // if (type.IsConstructedGenericType) // { // var gTransform = bindingManager.GetTypeTransform(type.GetGenericTypeDefinition()); // if (gTransform != null && gTransform.IsBlocked(methodInfo.??)) // { // bindingManager.Info("skip blocked method in generic definition: {0}", methodInfo.Name); // return; // } // } var isExtension = asExtensionAnyway || BindingManager.IsExtensionMethod(methodInfo); var isStatic = methodInfo.IsStatic && !isExtension; if (isStatic && type.IsGenericTypeDefinition) { bindingManager.Info("skip static method in generic type definition: {0}", methodInfo.Name); return; } var methodCSName = methodInfo.Name; var methodJSName = this.bindingManager.GetNamingAttribute(this.transform, methodInfo); if (IsOperatorOverloadingEnabled(methodInfo)) { var parameters = methodInfo.GetParameters(); var declaringType = methodInfo.DeclaringType; OperatorBindingInfo operatorBindingInfo = null; switch (methodCSName) { case "op_LessThan": if (parameters.Length == 2) { if (parameters[0].ParameterType == declaringType && parameters[1].ParameterType == declaringType) { operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, methodCSName, "<", "<", 2); } } break; case "op_Addition": if (parameters.Length == 2) { if (parameters[0].ParameterType == declaringType && parameters[1].ParameterType == declaringType) { operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, methodCSName, "+", "+", 2); } } break; case "op_Subtraction": if (parameters.Length == 2) { if (parameters[0].ParameterType == declaringType && parameters[1].ParameterType == declaringType) { operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, methodCSName, "-", "-", 2); } } break; case "op_Equality": if (parameters.Length == 2) { if (parameters[0].ParameterType == declaringType && parameters[1].ParameterType == declaringType) { operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, methodCSName, "==", "==", 2); } } break; case "op_Multiply": if (parameters.Length == 2) { var op0 = bindingManager.GetExportedType(parameters[0].ParameterType); var op1 = bindingManager.GetExportedType(parameters[1].ParameterType); if (op0 != null && op1 != null) { var bindingName = methodCSName + "_" + op0.csBindingName + "_" + op1.csBindingName; operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, bindingName, "*", "*", 2); } } break; case "op_Division": if (parameters.Length == 2) { var op0 = bindingManager.GetExportedType(parameters[0].ParameterType); var op1 = bindingManager.GetExportedType(parameters[1].ParameterType); if (op0 != null && op1 != null) { var bindingName = methodCSName + "_" + op0.csBindingName + "_" + op1.csBindingName; operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, bindingName, "/", "/", 2); } } break; case "op_UnaryNegation": { operatorBindingInfo = new OperatorBindingInfo(bindingManager, methodInfo, isExtension, isStatic, methodCSName, "neg", "-", 1); } break; } if (operatorBindingInfo != null) { operators.Add(operatorBindingInfo); CollectDelegate(methodInfo); bindingManager.Info("[AddOperator] {0}.{1}", type, methodInfo); return; } // fallback to normal method binding } var group = isStatic ? staticMethods : methods; MethodBindingInfo methodBindingInfo; if (!group.TryGetValue(methodCSName, out methodBindingInfo)) { methodBindingInfo = new MethodBindingInfo(bindingManager, isStatic, methodCSName, methodJSName); group.Add(methodCSName, methodBindingInfo); } if (!methodBindingInfo.Add(methodInfo, isExtension)) { bindingManager.Info("fail to add method: {0}", methodInfo.Name); return; } CollectDelegate(methodInfo); bindingManager.Info("[AddMethod] {0}.{1}", type, methodInfo); }
public virtual void OnCleanup(BindingManager bindingManager) { }
public override void Dispose() { using (new RegFuncCodeGen(cg)) { using (new RegFuncNamespaceCodeGen(cg, typeBindingInfo)) { var constructor = typeBindingInfo.constructors.available ? typeBindingInfo.constructors.csBindName : "JSApi.class_private_ctor"; if (!typeBindingInfo.constructors.available && !typeBindingInfo.type.IsAbstract) { if (typeBindingInfo.type.IsSubclassOf(typeof(Component))) { // 因为 ts 泛型约束需要 new() 形式, 所以在定义中产生一个 public 定义 // 例如: GetComponent<T extends Component>(type: { new(): T }): T cg.tsDeclare.AppendLine("/*protected*/ constructor()"); } else { if (!typeBindingInfo.type.IsGenericTypeDefinition) { cg.tsDeclare.AppendLine("protected constructor()"); } } } cg.cs.AppendLine("var cls = ns.CreateClass(\"{0}\", typeof({1}), {2});", typeBindingInfo.jsName, this.cg.bindingManager.GetCSTypeFullName(typeBindingInfo.type), constructor); // 运算符 foreach (var operatorBindingInfo in typeBindingInfo.operators) { var regName = operatorBindingInfo.jsName; var funcName = operatorBindingInfo.csBindName; var parameters = operatorBindingInfo.methodInfo.GetParameters(); var declaringType = operatorBindingInfo.methodInfo.DeclaringType; string redirect; if (this.typeBindingInfo.transform != null && this.typeBindingInfo.transform.TryRedirectMethod(regName, out redirect)) { funcName = redirect; } do { if (parameters.Length == 2) { if (parameters[0].ParameterType != declaringType) { var leftType = typeBindingInfo.bindingManager.GetCSTypeFullName(parameters[0].ParameterType); cg.cs.AppendLine("cls.AddLeftOperator(\"{0}\", {1}, {2}, typeof({3}));", regName, funcName, operatorBindingInfo.length, leftType); break; } else if (parameters[1].ParameterType != declaringType) { var rightType = typeBindingInfo.bindingManager.GetCSTypeFullName(parameters[1].ParameterType); cg.cs.AppendLine("cls.AddRightOperator(\"{0}\", {1}, {2}, typeof({3}));", regName, funcName, operatorBindingInfo.length, rightType); break; } } cg.cs.AppendLine("cls.AddSelfOperator(\"{0}\", {1}, {2});", regName, funcName, operatorBindingInfo.length); } while (false); } // 非静态方法 foreach (var kv in typeBindingInfo.methods) { var regName = kv.Value.jsName; var funcName = kv.Value.csBindName; string redirect; if (this.typeBindingInfo.transform != null && this.typeBindingInfo.transform.TryRedirectMethod(regName, out redirect)) { funcName = redirect; } cg.cs.AppendLine("cls.AddMethod(false, \"{0}\", {1});", regName, funcName); } // 静态方法 foreach (var kv in typeBindingInfo.staticMethods) { var methodBindingInfo = kv.Value; var regName = methodBindingInfo.jsName; if (methodBindingInfo._cfunc != null) { var attr = (JSCFunctionAttribute)methodBindingInfo._cfunc.GetCustomAttribute(typeof(JSCFunctionAttribute)); var methodDeclType = this.cg.bindingManager.GetCSTypeFullName(methodBindingInfo._cfunc.DeclaringType); var isStatic = attr.isStatic ? "true" : "false"; cg.cs.AppendLine("cls.AddRawMethod({0}, \"{1}\", {2}.{3});", isStatic, regName, methodDeclType, methodBindingInfo._cfunc.Name); if (attr.difinitions != null) { foreach (var defEntry in attr.difinitions) { string tsMethodRename; var prefix = attr.isStatic ? "static " : ""; // 附带的签名没有带命名时, 自动加上 if (defEntry.StartsWith("(") || defEntry.StartsWith("<")) { if (this.cg.bindingManager.GetTSMethodRename(methodBindingInfo._cfunc, out tsMethodRename)) { this.cg.tsDeclare.AppendLine($"{prefix}{tsMethodRename}{defEntry}"); } else { this.cg.tsDeclare.AppendLine($"{prefix}{regName}{defEntry}"); } } else { this.cg.tsDeclare.AppendLine($"{prefix}{defEntry}"); } } } else { this.cg.tsDeclare.AppendLine("(...uncertain: any[]): any /* uncertain */"); } } else { var funcName = methodBindingInfo.csBindName; string redirect; if (this.typeBindingInfo.transform != null && this.typeBindingInfo.transform.TryRedirectMethod(regName, out redirect)) { funcName = redirect; } cg.cs.AppendLine("cls.AddMethod(true, \"{0}\", {1});", regName, funcName); } } // 属性 foreach (var kv in typeBindingInfo.properties) { var bindingInfo = kv.Value; if (bindingInfo.staticPair.IsValid()) { var tsPropertyVar = BindingManager.GetTSVariable(bindingInfo.regName); cg.cs.AppendLine("cls.AddProperty(true, \"{0}\", {1}, {2});", tsPropertyVar, bindingInfo.staticPair.getterName != null ? bindingInfo.staticPair.getterName : "null", bindingInfo.staticPair.setterName != null ? bindingInfo.staticPair.setterName : "null"); var tsPropertyPrefix = "static "; if (bindingInfo.staticPair.setterName == null) { tsPropertyPrefix += "readonly "; } var tsPropertyType = this.cg.bindingManager.GetTSTypeFullName(bindingInfo.propertyInfo.PropertyType); cg.AppendJSDoc(bindingInfo.propertyInfo); cg.tsDeclare.AppendLine($"{tsPropertyPrefix}{tsPropertyVar}: {tsPropertyType}"); } if (bindingInfo.instancePair.IsValid()) { var tsPropertyVar = BindingManager.GetTSVariable(bindingInfo.regName); cg.cs.AppendLine("cls.AddProperty(false, \"{0}\", {1}, {2});", tsPropertyVar, bindingInfo.instancePair.getterName != null ? bindingInfo.instancePair.getterName : "null", bindingInfo.instancePair.setterName != null ? bindingInfo.instancePair.setterName : "null"); var tsPropertyPrefix = ""; if (bindingInfo.instancePair.setterName == null) { tsPropertyPrefix += "readonly "; } var tsPropertyType = this.cg.bindingManager.GetTSTypeFullName(bindingInfo.propertyInfo.PropertyType); cg.AppendJSDoc(bindingInfo.propertyInfo); cg.tsDeclare.AppendLine($"{tsPropertyPrefix}{tsPropertyVar}: {tsPropertyType}"); } } foreach (var kv in typeBindingInfo.fields) { var bindingInfo = kv.Value; var bStatic = bindingInfo.isStatic; var tsFieldVar = BindingManager.GetTSVariable(bindingInfo.regName); if (bindingInfo.constantValue != null) { var cv = bindingInfo.constantValue; cg.cs.AppendLine($"cls.AddConstValue(\"{tsFieldVar}\", {cv});"); } else { cg.cs.AppendLine("cls.AddField({0}, \"{1}\", {2}, {3});", bStatic ? "true" : "false", tsFieldVar, bindingInfo.getterName != null ? bindingInfo.getterName : "null", bindingInfo.setterName != null ? bindingInfo.setterName : "null"); } var tsFieldPrefix = bStatic ? "static " : ""; if (bindingInfo.setterName == null) { tsFieldPrefix += "readonly "; } var tsFieldType = this.cg.bindingManager.GetTSTypeFullName(bindingInfo.fieldInfo.FieldType); cg.AppendJSDoc(bindingInfo.fieldInfo); cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}: {tsFieldType}"); } foreach (var kv in typeBindingInfo.events) { var eventBindingInfo = kv.Value; var bStatic = eventBindingInfo.isStatic; var tsFieldVar = BindingManager.GetTSVariable(eventBindingInfo.regName); var tsFieldType = this.cg.bindingManager.GetTSTypeFullName(eventBindingInfo.eventInfo.EventHandlerType); var tsFieldPrefix = ""; if (bStatic) { tsFieldPrefix += "static "; cg.cs.AppendLine($"cls.AddMethod(true, \"{tsFieldVar}\", {eventBindingInfo.name});"); } else { cg.cs.AppendLine($"cls.AddMethod(false, \"{tsFieldVar}\", {eventBindingInfo.name});"); } // tsFieldPrefix += "readonly "; // cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}: jsb.event<{tsFieldType}>"); cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"add\" | \"remove\", fn: {tsFieldType}): void"); } foreach (var kv in typeBindingInfo.delegates) { var delegateBindingInfo = kv.Value; var bStatic = delegateBindingInfo.isStatic; var tsFieldVar = BindingManager.GetTSVariable(delegateBindingInfo.regName); var tsFieldType = this.cg.bindingManager.GetTSTypeFullName(delegateBindingInfo.delegateType); var tsFieldPrefix = ""; if (bStatic) { tsFieldPrefix += "static "; cg.cs.AppendLine($"cls.AddMethod(true, \"{tsFieldVar}\", {delegateBindingInfo.name});"); } else { cg.cs.AppendLine($"cls.AddMethod(false, \"{tsFieldVar}\", {delegateBindingInfo.name});"); } // tsFieldPrefix += "readonly "; // cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}: jsb.event<{tsFieldType}>"); if (delegateBindingInfo.readable) { if (delegateBindingInfo.writable) { cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"get\"): {tsFieldType}"); cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"add\" | \"remove\" | \"set\", fn?: {tsFieldType}): void"); cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"add\" | \"remove\" | \"set\" | \"get\", fn?: {tsFieldType}): {tsFieldType} | void"); } else { cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"get\"): {tsFieldType}"); } } else { cg.tsDeclare.AppendLine($"{tsFieldPrefix}{tsFieldVar}(op: \"set\", fn: {tsFieldType})"); } } cg.cs.AppendLine("cls.Close();"); } } base.Dispose(); this.cg.tsDeclare.DecTabLevel(); this.cg.tsDeclare.AppendLine("}"); }
public virtual void OnPostGenerateType(BindingManager bindingManager, TypeBindingInfo bindingInfo) { }
public virtual void OnPostGenerateDelegate(BindingManager bindingManager, DelegateBridgeBindingInfo bindingInfo) { }
public virtual bool OnExportingType(BindingManager bindingManager, Type type) { return(false); }
public virtual void OnPostCollectTypes(BindingManager bindingManager) { }
public virtual void OnPostExporting(BindingManager bindingManager) { }
public virtual void OnPostCollectAssemblies(BindingManager bindingManager) { }
public virtual void OnInitialize(BindingManager bindingManager) { }