public ConstructorCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo)
     : base(cg)
 {
     // WriteInstanceEvents(bindingInfo);
     this.typeBindingInfo = typeBindingInfo;
     this.bindingInfo     = typeBindingInfo.constructors;
     if (this.bindingInfo.count > 0)
     {
         WriteCSAllVariants(this.bindingInfo);
         WriteTSAllVariants(typeBindingInfo, this.bindingInfo);
     }
     else
     {
         WriteDefaultConstructorBinding();
     }
 }
Exemple #2
0
        protected void WriteTSAllVariants(TypeBindingInfo typeBindingInfo, MethodBaseBindingInfo <T> bindingInfo)
        {
            var variants = bindingInfo.variants;

            //NOTE: 如果产生了无法在 typescript 中声明的方法, 则作标记, 并输出一条万能声明
            //      [key: string]: any
            foreach (var variantKV in variants)
            {
                foreach (var method in variantKV.Value.plainMethods)
                {
                    WriteTSDeclaration(typeBindingInfo, method.method, bindingInfo, method.isExtension);
                }
                foreach (var method in variantKV.Value.varargMethods)
                {
                    WriteTSDeclaration(typeBindingInfo, method.method, bindingInfo, method.isExtension);
                }
            }
        }
        public DelegateBindingInfo(TypeBindingInfo typeBindingInfo, PropertyInfo propertyInfo)
        {
            this.declaringType = typeBindingInfo.type;
            this.delegateType  = propertyInfo.PropertyType;
            this.readable      = propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic;
            this.writable      = propertyInfo.SetMethod != null && propertyInfo.SetMethod.IsPublic;
            this.isStatic      = (propertyInfo.GetMethod ?? propertyInfo.SetMethod).IsStatic;
            this.csName        = propertyInfo.Name;

            if (this.isStatic)
            {
                this.name = "BindStaticDelegate_" + propertyInfo.Name;
            }
            else
            {
                this.name = "BindDelegate_" + propertyInfo.Name;
            }

            this.regName = typeBindingInfo.bindingManager.GetNamingAttribute(propertyInfo);
        }
        public bool isStatic; // 静态

        public DelegateBindingInfo(TypeBindingInfo typeBindingInfo, FieldInfo fieldInfo)
        {
            this.declaringType = typeBindingInfo.type;
            this.delegateType  = fieldInfo.FieldType;
            this.readable      = true;
            this.writable      = !fieldInfo.IsInitOnly;
            this.isStatic      = fieldInfo.IsStatic;
            this.csName        = fieldInfo.Name;

            do
            {
                if (this.isStatic)
                {
                    this.name = "BindStaticDelegate_" + fieldInfo.Name;
                }
                else
                {
                    this.name = "BindDelegate_" + fieldInfo.Name;
                }
            } while (false);

            this.regName = typeBindingInfo.bindingManager.GetNamingAttribute(fieldInfo);
        }
Exemple #5
0
 private void GenerateInternal(TypeBindingInfo typeBindingInfo)
 {
     using (var tsMod = new TSModuleCodeGen(this, typeBindingInfo))
     {
         _currentTSModule = tsMod;
         using (new TSNamespaceCodeGen(this, typeBindingInfo.tsTypeNaming.jsNamespace))
         {
             if (typeBindingInfo.IsEnum)
             {
                 using (new EnumCodeGen(this, typeBindingInfo))
                 {
                 }
             }
             else
             {
                 using (new ClassCodeGen(this, typeBindingInfo))
                 {
                 }
             }
         }
         _currentTSModule = null;
     }
 }
Exemple #6
0
        // 生成类型绑定
        public void Generate(TypeBindingInfo typeBindingInfo)
        {
            this.cs.enabled        = (typeBindingInfo.bindingFlags & TypeBindingFlags.BindingCode) != 0 && (typeBindingFlags & TypeBindingFlags.BindingCode) != 0;
            this.tsDeclare.enabled = (typeBindingInfo.bindingFlags & TypeBindingFlags.TypeDefinition) != 0 && (typeBindingFlags & TypeBindingFlags.TypeDefinition) != 0;
            var defs = string.Join(" && ", from def in typeBindingInfo.requiredDefines select def);

            using (new CSDebugCodeGen(this))
            {
                using (new EditorOnlyCodeGen(this, defs))
                {
                    using (new CSPlatformCodeGen(this, TypeBindingFlags.Default))
                    {
                        using (new CSTopLevelCodeGen(this, typeBindingInfo))
                        {
                            using (new CSNamespaceCodeGen(this, this.bindingManager.prefs.ns))
                            {
                                GenerateInternal(typeBindingInfo);
                            }
                        }
                    }
                }
            }
        }
 private void GenerateInternal(TypeBindingInfo typeBindingInfo)
 {
     using (new PlatformCodeGen(this, TypeBindingFlags.Default))
     {
         using (new TopLevelCodeGen(this, typeBindingInfo))
         {
             using (new NamespaceCodeGen(this, this.bindingManager.prefs.ns, typeBindingInfo.jsNamespace))
             {
                 if (typeBindingInfo.IsEnum)
                 {
                     using (new EnumCodeGen(this, typeBindingInfo))
                     {
                     }
                 }
                 else
                 {
                     using (new ClassCodeGen(this, typeBindingInfo))
                     {
                     }
                 }
             }
         }
     }
 }
Exemple #8
0
 public RegFuncNamespaceCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo)
 {
     this.cg = cg;
     this.cg.cs.Append("var ns = register.CreateNamespace(");
     // Debug.LogErrorFormat("{0}: {1}", bindingInfo.type, bindingInfo.Namespace);
     if (!string.IsNullOrEmpty(typeBindingInfo.jsNamespace))
     {
         var split_ns = typeBindingInfo.jsNamespace.Split('.');
         var ns_count = split_ns.Length;
         for (var i = 0; i < ns_count; i++)
         {
             var el_ns = split_ns[i];
             if (i == ns_count - 1)
             {
                 this.cg.cs.AppendL("\"{0}\"", el_ns);
             }
             else
             {
                 this.cg.cs.AppendL("\"{0}\", ", el_ns);
             }
         }
     }
     this.cg.cs.AppendLineL(");");
 }
 public bool OnTypeGenerating(TypeBindingInfo typeBindingInfo, int current, int total)
 {
     return(false);
 }
Exemple #10
0
        public FieldBindingInfo(TypeBindingInfo typeBindingInfo, FieldInfo fieldInfo)
        {
            do
            {
                if (fieldInfo.IsLiteral)
                {
                    try
                    {
                        var cv     = fieldInfo.GetRawConstantValue();
                        var cvType = cv.GetType();
                        if (cvType == typeof(string))
                        {
                            constantValue = $"\"{cv}\"";
                            break;
                        }

                        if (cvType == typeof(int) ||
                            cvType == typeof(uint) ||
                            cvType == typeof(byte) ||
                            cvType == typeof(sbyte) ||
                            cvType == typeof(short) ||
                            cvType == typeof(ushort) ||
                            cvType == typeof(bool))
                        {
                            constantValue = $"{cv}";
                            break;
                        }

                        if (cvType == typeof(float))
                        {
                            var fcv = (float)cv;
                            if (!float.IsInfinity(fcv) &&
                                !float.IsNaN(fcv))
                            {
                                constantValue = $"{cv}";
                                break;
                            }
                        }

                        // if (cvType.IsPrimitive && cvType.IsValueType)
                        // {
                        //     constantValue = $"{cv}";
                        //     break;
                        // }
                    }
                    catch (Exception)
                    {
                    }
                }

                if (fieldInfo.IsStatic)
                {
                    this.getterName = "BindStaticRead_" + fieldInfo.Name;
                    if (!fieldInfo.IsInitOnly && !fieldInfo.IsLiteral)
                    {
                        this.setterName = "BindStaticWrite_" + fieldInfo.Name;
                    }
                }
                else
                {
                    this.getterName = "BindRead_" + fieldInfo.Name;
                    if (!fieldInfo.IsInitOnly && !fieldInfo.IsLiteral)
                    {
                        this.setterName = "BindWrite_" + fieldInfo.Name;
                    }
                }
            } while (false);

            this.regName   = typeBindingInfo.bindingManager.GetNamingAttribute(fieldInfo);
            this.fieldInfo = fieldInfo;
        }
Exemple #11
0
        protected List <ParameterInfo> WriteTSDeclaration(TypeBindingInfo typeBindingInfo, T method, MethodBaseBindingInfo <T> bindingInfo, bool isExtension)
        {
            var    refParameters = new List <ParameterInfo>();
            string tsMethodDeclaration;

            this.cg.AppendJSDoc(method);

            if (typeBindingInfo.transform.GetTSMethodDeclaration(method, out tsMethodDeclaration) ||
                this.cg.bindingManager.GetTSMethodDeclaration(method, out tsMethodDeclaration))
            {
                this.cg.tsDeclare.AppendLine(tsMethodDeclaration);
                return(refParameters);
            }

            string tsMethodRename;

            if (!this.cg.bindingManager.GetTSMethodRename(method, out tsMethodRename))
            {
                tsMethodRename = bindingInfo.jsName;
            }

            var isRaw = method.IsDefined(typeof(JSCFunctionAttribute));
            //TODO: 需要处理参数类型归并问题, 因为如果类型没有导入 ts 中, 可能会在声明中出现相同参数列表的定义
            //      在 MethodVariant 中创建每个方法对应的TS类型名参数列表, 完全相同的不再输出
            var prefix = "";

            // if (method.Name.StartsWith("op_"))
            if (bindingInfo is OperatorBindingInfo)
            {
                prefix += "// js_op_overloading: ";
            }
            else
            {
                // var baseType = typeBindingInfo.type.BaseType;
                // if (baseType != null)
                // {
                //     //TODO: 需要检查 TypeBindingInfo 对此的命名修改
                //     if (baseType.GetMethods().Where(baseMethodInfo => baseMethodInfo.Name == tsMethodRename).Count() != 0)
                //     {
                //         prefix += "// @ts-ignore" + this.cg.tsDeclare.newline + this.cg.tsDeclare.tabString;
                //     }
                // }
            }

            if (method.IsStatic && !isExtension)
            {
                prefix += "static ";
            }

            this.cg.tsDeclare.Append($"{prefix}{tsMethodRename}(");

            if (isRaw)
            {
                this.cg.tsDeclare.AppendL("...uncertain: any[]): any /* uncertain */");
                this.cg.tsDeclare.AppendLine();
            }
            else
            {
                var parameters = method.GetParameters();
                if (isExtension)
                {
                    ArrayUtility.RemoveAt(ref parameters, 0);
                }

                for (int i = 0, len = parameters.Length; i < len;)
                {
                    var parameter     = parameters[i];
                    var parameterType = parameter.ParameterType;
                    if (parameterType == typeof(Native.JSContext) || parameterType == typeof(Native.JSRuntime))
                    {
                        // 剔除 JSContext, JSRuntime
                        ArrayUtility.RemoveAt(ref parameters, i);
                        len--;
                    }
                    else if (parameterType == typeof(ScriptContext) || parameterType == typeof(ScriptRuntime))
                    {
                        // 剔除 ScriptContext, ScriptRuntime
                        ArrayUtility.RemoveAt(ref parameters, i);
                        len--;
                    }
                    // else if (parameter.IsOut)
                    // {
                    //     ArrayUtility.RemoveAt(ref parameters, i);
                    //     len--;
                    //     refParameters.Add(parameter);
                    // }
                    else
                    {
                        // if (parameterType.IsByRef)
                        // {
                        //     refParameters.Add(parameter);
                        // }
                        i++;
                    }
                }

                for (int i = 0, len = parameters.Length; i < len; i++)
                {
                    var parameter        = parameters[i];
                    var parameter_prefix = "";
                    var parameterType    = parameter.ParameterType;

                    if (parameter.IsDefined(typeof(ParamArrayAttribute), false) && i == parameters.Length - 1)
                    {
                        var elementType      = parameterType.GetElementType();
                        var elementTS        = this.cg.bindingManager.GetTSTypeFullName(elementType);
                        var parameterVarName = BindingManager.GetTSVariable(parameter);
                        this.cg.tsDeclare.AppendL($"{parameter_prefix}...{parameterVarName}: {elementTS}[]");
                    }
                    else
                    {
                        var parameterTS      = this.cg.bindingManager.GetTSTypeFullName(parameter);
                        var parameterVarName = BindingManager.GetTSVariable(parameter);
                        this.cg.tsDeclare.AppendL($"{parameter_prefix}{parameterVarName}: {parameterTS}");
                    }

                    if (i != parameters.Length - 1)
                    {
                        this.cg.tsDeclare.AppendL(", ");
                    }
                }
                this.cg.tsDeclare.AppendL($")");
                WriteTSReturn(method, refParameters);
            }
            return(refParameters);
        }
Exemple #12
0
        public ClassCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo)
            : base(cg, typeBindingInfo)
        {
            this.cg.AppendJSDoc(this.typeBindingInfo.type);
            var transform   = this.typeBindingInfo.transform;
            var prefix      = string.IsNullOrEmpty(this.typeBindingInfo.jsNamespace) ? "declare " : "";
            var super       = this.cg.bindingManager.GetTSSuperName(this.typeBindingInfo);
            var interfaces  = this.cg.bindingManager.GetTSInterfacesName(this.typeBindingInfo.type);
            var implements  = "";
            var jsClassName = this.typeBindingInfo.jsName;
            var jsClassType = "";

            if (typeBindingInfo.isEditorRuntime)
            {
                this.cg.tsDeclare.AppendLine("@jsb.EditorRuntime");
            }


            if (typeBindingInfo.type.IsInterface)
            {
                jsClassType = "interface";

                if (string.IsNullOrEmpty(interfaces))
                {
                    if (!string.IsNullOrEmpty(super))
                    {
                        implements += $" extends {super}"; // something wrong
                    }
                }
                else
                {
                    implements += $" extends {interfaces}";

                    if (!string.IsNullOrEmpty(super))
                    {
                        implements += $", {super}"; // something wrong
                    }
                }
            }
            else
            {
                jsClassType = typeBindingInfo.type.IsAbstract ? "abstract class" : "class";

                if (!string.IsNullOrEmpty(super))
                {
                    implements += $" extends {super}";
                }

                if (!string.IsNullOrEmpty(interfaces))
                {
                    implements += $" implements {interfaces}";
                }
            }

            this.cg.tsDeclare.AppendLine($"{prefix}{jsClassType} {jsClassName}{implements} {{");
            this.cg.tsDeclare.AddTabLevel();

            // 生成函数体
            // 构造函数
            if (this.typeBindingInfo.constructors.available)
            {
                using (new PInvokeGuardCodeGen(cg, typeof(Native.JSCFunctionMagic)))
                {
                    using (new BindingConstructorDeclareCodeGen(cg, this.typeBindingInfo.constructors.csBindName))
                    {
                        using (new TryCatchGuradCodeGen(cg))
                        {
                            using (new ConstructorCodeGen(cg, this.typeBindingInfo))
                            {
                            }
                        }
                    }
                }
            }

            // 非静态成员方法
            foreach (var kv in this.typeBindingInfo.methods)
            {
                var methodBindingInfo = kv.Value;

                if (transform == null || !transform.IsRedirectedMethod(methodBindingInfo.jsName))
                {
                    using (new PInvokeGuardCodeGen(cg))
                    {
                        using (new BindingFuncDeclareCodeGen(cg, methodBindingInfo.csBindName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new MethodCodeGen(cg, methodBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }

                using (new TSMethodCodeGen(cg, this.typeBindingInfo, methodBindingInfo))
                {
                }
            }

            //TODO: C# 抽象类可以不提供方法实现, d.ts 需要补充声明
            // if (this.bindingInfo.type.IsAbstract && !this.bindingInfo.type.IsInterface)
            // {
            // }
            // 静态成员方法
            if (!typeBindingInfo.type.IsGenericTypeDefinition)
            {
                foreach (var kv in this.typeBindingInfo.staticMethods)
                {
                    var methodBindingInfo = kv.Value;
                    if (transform == null || !transform.IsRedirectedMethod(methodBindingInfo.jsName))
                    {
                        if (methodBindingInfo._cfunc != null)
                        {
                            continue;
                        }

                        using (new PInvokeGuardCodeGen(cg))
                        {
                            using (new BindingFuncDeclareCodeGen(cg, methodBindingInfo.csBindName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new MethodCodeGen(cg, methodBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }

                    using (new TSMethodCodeGen(cg, typeBindingInfo, methodBindingInfo))
                    {
                    }
                }
            }

            if (!typeBindingInfo.type.IsGenericTypeDefinition)
            {
                foreach (var operatorBindingInfo in this.typeBindingInfo.operators)
                {
                    if (transform == null || !transform.IsRedirectedMethod(operatorBindingInfo.jsName))
                    {
                        using (new PInvokeGuardCodeGen(cg))
                        {
                            using (new BindingFuncDeclareCodeGen(cg, operatorBindingInfo.csBindName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new OperatorCodeGen(cg, operatorBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }

                    using (new TSOperatorCodeGen(cg, typeBindingInfo, operatorBindingInfo))
                    {
                    }
                }
            }

            // 所有附加方法
            if (transform != null)
            {
                transform.ForEachAdditionalTSMethodDeclaration(decl =>
                {
                    this.cg.tsDeclare.AppendLine(decl);
                });
            }

            // 所有属性
            foreach (var kv in this.typeBindingInfo.properties)
            {
                var propertyBindingInfo = kv.Value;

                // 静态
                if (propertyBindingInfo.staticPair.IsValid())
                {
                    // 可读属性
                    if (propertyBindingInfo.staticPair.getterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                        {
                            using (new BindingGetterFuncDeclareCodeGen(cg, propertyBindingInfo.staticPair.getterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertyGetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }

                    // 可写属性
                    if (propertyBindingInfo.staticPair.setterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                        {
                            using (new BindingSetterFuncDeclareCodeGen(cg, propertyBindingInfo.staticPair.setterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertySetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                }

                // 非静态
                if (propertyBindingInfo.instancePair.IsValid())
                {
                    // 可读属性
                    if (propertyBindingInfo.instancePair.getterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                        {
                            using (new BindingGetterFuncDeclareCodeGen(cg, propertyBindingInfo.instancePair.getterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertyGetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                    // 可写属性
                    if (propertyBindingInfo.instancePair.setterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                        {
                            using (new BindingSetterFuncDeclareCodeGen(cg, propertyBindingInfo.instancePair.setterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertySetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // 所有字段
            foreach (var kv in this.typeBindingInfo.fields)
            {
                var fieldBindingInfo = kv.Value;

                // 可读
                if (fieldBindingInfo.getterName != null)
                {
                    using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                    {
                        using (new BindingGetterFuncDeclareCodeGen(cg, fieldBindingInfo.getterName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new FieldGetterCodeGen(cg, fieldBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }

                // 可写
                if (fieldBindingInfo.setterName != null)
                {
                    using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                    {
                        using (new BindingSetterFuncDeclareCodeGen(cg, fieldBindingInfo.setterName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new FieldSetterCodeGen(cg, fieldBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }
            }

            // 所有事件
            foreach (var kv in this.typeBindingInfo.events)
            {
                var eventBindingInfo = kv.Value;
                using (new PInvokeGuardCodeGen(cg))
                {
                    using (new BindingFuncDeclareCodeGen(cg, eventBindingInfo.name))
                    {
                        using (new TryCatchGuradCodeGen(cg))
                        {
                            using (new EventOperationCodeGen(cg, eventBindingInfo))
                            {
                            }
                        }
                    }
                }
            }

            // 所有委托 (Field/Property)
            foreach (var kv in this.typeBindingInfo.delegates)
            {
                var delegateBindingInfo = kv.Value;
                using (new PInvokeGuardCodeGen(cg))
                {
                    using (new BindingFuncDeclareCodeGen(cg, delegateBindingInfo.name))
                    {
                        using (new TryCatchGuradCodeGen(cg))
                        {
                            using (new DelegateOperationCodeGen(cg, delegateBindingInfo))
                            {
                            }
                        }
                    }
                }
            }
        }
        public ClassCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo)
            : base(cg, typeBindingInfo)
        {
            this.cg.AppendJSDoc(this.typeBindingInfo.type);
            var transform        = this.typeBindingInfo.transform;
            var prefix           = this.typeBindingInfo.tsTypeNaming.topLevel ? "declare " : "";
            var superBindingInfo = this.cg.bindingManager.GetSuperTypeBindingInfo(this.typeBindingInfo);
            var super            = superBindingInfo != null?this.cg.currentTSModule.GetTSTypeFullName(superBindingInfo.type) : "";

            var interfaces  = this.cg.currentTSModule.GetTSInterfacesName(this.typeBindingInfo.type);
            var implements  = "";
            var jsClassName = this.typeBindingInfo.tsTypeNaming.jsName;
            var jsClassType = "";

            if (typeBindingInfo.requiredDefines.Count != 0)
            {
                var defs = string.Join(", ", from def in typeBindingInfo.requiredDefines select $"\"{def}\"");
                this.cg.tsDeclare.AppendLine($"@{this.cg.bindingManager.GetDefaultTypePrefix()}RequiredDefines({defs})");
            }

            if (typeBindingInfo.type.IsInterface)
            {
                jsClassType = "interface";

                if (string.IsNullOrEmpty(interfaces))
                {
                    if (!string.IsNullOrEmpty(super))
                    {
                        implements += $" extends {super}"; // something wrong
                    }
                }
                else
                {
                    implements += $" extends {interfaces}";

                    if (!string.IsNullOrEmpty(super))
                    {
                        implements += $", {super}"; // something wrong
                    }
                }
            }
            else
            {
                jsClassType = typeBindingInfo.type.IsAbstract ? "abstract class" : "class";

                if (!string.IsNullOrEmpty(super))
                {
                    implements += $" extends {super}";
                }

                if (!string.IsNullOrEmpty(interfaces))
                {
                    implements += $" implements {interfaces}";
                }
            }

            this.cg.tsDeclare.AppendLine($"{prefix}{jsClassType} {jsClassName}{implements} {{");
            this.cg.tsDeclare.AddTabLevel();

            // 生成函数体
            // 构造函数
            if (this.typeBindingInfo.constructors.available)
            {
                if (this.typeBindingInfo.transform.csConstructorOverride == null)
                {
                    using (new PInvokeGuardCodeGen(cg, typeof(Native.JSCFunctionMagic)))
                    {
                        using (new BindingConstructorDeclareCodeGen(cg, this.typeBindingInfo.constructors.csBindName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new ConstructorCodeGen(cg, this.typeBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }

                using (new TSConstructorCodeGen(cg, this.typeBindingInfo, this.typeBindingInfo.constructors))
                {
                }
            }

            // 非静态成员方法
            foreach (var kv in this.typeBindingInfo.methods)
            {
                var methodBindingInfo = kv.Value;
                var jscOverride       = transform.GetCSMethodOverrideBinding(methodBindingInfo.jsName);
                if (jscOverride == null)
                {
                    using (new PInvokeGuardCodeGen(cg))
                    {
                        using (new BindingFuncDeclareCodeGen(cg, methodBindingInfo.csBindName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new MethodCodeGen(cg, this.typeBindingInfo, methodBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }

                using (new TSMethodCodeGen <MethodInfo>(cg, this.typeBindingInfo, methodBindingInfo))
                {
                }
            }

            //TODO: C# 抽象类可以不提供方法实现, d.ts 需要补充声明
            // if (this.bindingInfo.type.IsAbstract && !this.bindingInfo.type.IsInterface)
            // {
            // }
            // 静态成员方法
            if (!typeBindingInfo.type.IsGenericTypeDefinition)
            {
                foreach (var kv in this.typeBindingInfo.staticMethods)
                {
                    var methodBindingInfo = kv.Value;
                    if (methodBindingInfo._cfunc != null)
                    {
                        continue;
                    }

                    var jscOverride = transform.GetCSMethodOverrideBinding(methodBindingInfo.jsName);
                    if (jscOverride == null)
                    {
                        using (new PInvokeGuardCodeGen(cg))
                        {
                            using (new BindingFuncDeclareCodeGen(cg, methodBindingInfo.csBindName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new MethodCodeGen(cg, this.typeBindingInfo, methodBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }

                    using (new TSMethodCodeGen <MethodInfo>(cg, typeBindingInfo, methodBindingInfo))
                    {
                    }
                }
            }

            if (!typeBindingInfo.type.IsGenericTypeDefinition)
            {
                foreach (var operatorBindingInfo in this.typeBindingInfo.operators)
                {
                    using (new PInvokeGuardCodeGen(cg))
                    {
                        using (new BindingFuncDeclareCodeGen(cg, operatorBindingInfo.csBindName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new OperatorCodeGen(cg, this.typeBindingInfo, operatorBindingInfo))
                                {
                                }
                            }
                        }
                    }

                    using (new TSOperatorCodeGen(cg, typeBindingInfo, operatorBindingInfo))
                    {
                    }
                }
            }

            // 所有附加方法
            if (transform != null)
            {
                transform.ForEachAdditionalTSMethodDeclaration(decl =>
                {
                    this.cg.tsDeclare.AppendLine(decl);
                });
            }

            // 所有属性
            foreach (var kv in this.typeBindingInfo.properties)
            {
                var propertyBindingInfo = kv.Value;

                // 静态
                if (propertyBindingInfo.isStatic)
                {
                    // 可读属性
                    if (propertyBindingInfo.staticPair.getterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                        {
                            using (new BindingGetterFuncDeclareCodeGen(cg, propertyBindingInfo.staticPair.getterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertyGetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }

                    // 可写属性
                    if (propertyBindingInfo.staticPair.setterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                        {
                            using (new BindingSetterFuncDeclareCodeGen(cg, propertyBindingInfo.staticPair.setterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertySetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
                else // if (propertyBindingInfo.instancePair.IsValid())
                {
                    // 非静态
                    // 可读属性
                    if (propertyBindingInfo.instancePair.getterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                        {
                            using (new BindingGetterFuncDeclareCodeGen(cg, propertyBindingInfo.instancePair.getterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertyGetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                    // 可写属性
                    if (propertyBindingInfo.instancePair.setterName != null)
                    {
                        using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                        {
                            using (new BindingSetterFuncDeclareCodeGen(cg, propertyBindingInfo.instancePair.setterName))
                            {
                                using (new TryCatchGuradCodeGen(cg))
                                {
                                    using (new PropertySetterCodeGen(cg, propertyBindingInfo))
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // 所有字段
            foreach (var kv in this.typeBindingInfo.fields)
            {
                var fieldBindingInfo = kv.Value;

                // 可读
                if (fieldBindingInfo.getterName != null)
                {
                    using (new PInvokeGuardCodeGen(cg, typeof(JSGetterCFunction)))
                    {
                        using (new BindingGetterFuncDeclareCodeGen(cg, fieldBindingInfo.getterName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new FieldGetterCodeGen(cg, fieldBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }

                // 可写
                if (fieldBindingInfo.setterName != null)
                {
                    using (new PInvokeGuardCodeGen(cg, typeof(JSSetterCFunction)))
                    {
                        using (new BindingSetterFuncDeclareCodeGen(cg, fieldBindingInfo.setterName))
                        {
                            using (new TryCatchGuradCodeGen(cg))
                            {
                                using (new FieldSetterCodeGen(cg, fieldBindingInfo))
                                {
                                }
                            }
                        }
                    }
                }
            }

            // 所有事件
            foreach (var kv in this.typeBindingInfo.events)
            {
                var eventBindingInfo = kv.Value;
                using (new PInvokeGuardCodeGen(cg))
                {
                    using (new BindingFuncDeclareCodeGen(cg, eventBindingInfo.name))
                    {
                        using (new TryCatchGuradCodeGen(cg))
                        {
                            using (new EventOperationCodeGen(cg, eventBindingInfo))
                            {
                            }
                        }
                    }
                }
            }

            // 所有委托 (Field/Property)
            foreach (var kv in this.typeBindingInfo.delegates)
            {
                var delegateBindingInfo = kv.Value;
                using (new PInvokeGuardCodeGen(cg))
                {
                    using (new BindingFuncDeclareCodeGen(cg, delegateBindingInfo.name))
                    {
                        using (new TryCatchGuradCodeGen(cg))
                        {
                            using (new DelegateOperationCodeGen(cg, delegateBindingInfo))
                            {
                            }
                        }
                    }
                }
            }
        }
 public virtual void OnPostGenerateType(BindingManager bindingManager, TypeBindingInfo bindingInfo)
 {
 }
 public void AddTypeReference(string moduleName, TypeBindingInfo typeBindingInfo, string[] elements, string jsName)
 {
 }
Exemple #16
0
        public void AddModuleEntry(string moduleName, string runtimeVarName, string moduleVarName, TypeBindingInfo typeBindingInfo)
        {
            var csType           = this.cg.bindingManager.GetCSTypeFullName(typeBindingInfo.type);
            var csNamespace      = this.cg.bindingManager.prefs.ns;
            var csBindingName    = typeBindingInfo.csBindingName;
            var elements         = typeBindingInfo.tsTypeNaming.jsNamespace.Split('.');
            var jsNameNormalized = CodeGenUtils.Normalize(typeBindingInfo.tsTypeNaming.jsName);
            var jsNamespace      = CodeGenUtils.Concat(", ", CodeGenUtils.ConcatAsLiteral(", ", elements), $"\"{jsNameNormalized}\"");

            AddStatement($"{runtimeVarName}.AddTypeReference({moduleVarName}, typeof({csType}), {csNamespace}.{csBindingName}.Bind, {jsNamespace});");
            this.cg.bindingManager.callback.AddTypeReference(moduleName, typeBindingInfo, elements, jsNameNormalized);
        }
Exemple #17
0
 public CSTopLevelCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo)
 {
     this.cg = cg;
     this.AppendCommonHead();
     // this.cg.typescript.AppendLine("// {0} {1}", Environment.UserName, this.cg.bindingManager.dateTime);
 }
Exemple #18
0
 public TSOperatorCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo, OperatorBindingInfo bindingInfo)
     : base(cg)
 {
     this.bindingInfo = bindingInfo;
     WriteTSAllVariants(typeBindingInfo, this.bindingInfo);
 }
 public TSMethodCodeGen(CodeGenerator cg, TypeBindingInfo typeBindingInfo, MethodBaseBindingInfo <T> bindingInfo)
     : base(cg)
 {
     this.bindingInfo = bindingInfo;
     WriteTSAllVariants(typeBindingInfo, this.bindingInfo);
 }