public TypeBindingInfo(BindingManager bindingManager, Type type, TypeTransform typeTransform) { this.bindingManager = bindingManager; this.type = type; this.transform = typeTransform; this._omit = type.IsDefined(typeof(JSOmitAttribute), false); }
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); }