public ConstructorCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo) : base(cg) { // WriteInstanceEvents(bindingInfo); this.bindingInfo = typeBindingInfo.constructors; if (this.bindingInfo.count > 0) { WriteCSAllVariants(this.bindingInfo); WriteTSAllVariants(typeBindingInfo, this.bindingInfo); } else { WriteDefaultConstructorBinding(); } }
public ConstructorCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo) : base(cg) { this.typeBindingInfo = typeBindingInfo; this.methodBindingInfo = typeBindingInfo.constructors; if (this.methodBindingInfo.count > 0) { WriteCSAllVariants(this.typeBindingInfo, this.methodBindingInfo); // WriteTSAllVariants(typeBindingInfo, this.methodBindingInfo); } else { WriteDefaultConstructorBinding(); } }
// 收集所有 字段,属性,方法 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.GetAddMethod(true)?.IsStatic == true || evt.GetRemoveMethod(true)?.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; } var propInfoGetMethod = property.GetGetMethod(true); var propInfoSetMethod = property.GetSetMethod(true); if ((propInfoGetMethod?.IsStatic == true || propInfoSetMethod?.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 && propInfoGetMethod != null && propInfoGetMethod.IsPublic) { if (BindingManager.IsUnsupported(propInfoGetMethod)) { bindingManager.Info("skip unsupported get-method: {0}", propInfoGetMethod); continue; } AddMethod(propInfoGetMethod, false); } if (property.CanWrite && propInfoSetMethod != null && propInfoSetMethod.IsPublic) { if (BindingManager.IsUnsupported(propInfoSetMethod)) { bindingManager.Info("skip unsupported set-method: {0}", propInfoSetMethod); continue; } AddMethod(propInfoSetMethod, 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); }
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); }