예제 #1
0
 public ConstructorCodeGen(CodeGenerator cg, TypeBindingInfo bindingInfo)
     : base(cg)
 {
     // WriteInstanceEvents(bindingInfo);
     this.bindingInfo = bindingInfo.constructors;
     if (this.bindingInfo.count > 0)
     {
         WriteAllVariants(this.bindingInfo);
         WriteTSAllVariants(this.bindingInfo);
     }
     else
     {
         WriteDefaultConstructorBinding();
     }
 }
예제 #2
0
        public TypeBindingInfo(BindingManager bindingManager, Type type)
        {
            this.bindingManager = bindingManager;
            this.type           = type;
            this.transform      = bindingManager.GetTypeTransform(type);
            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);
            }
            else
            {
                if (type.DeclaringType != null)
                {
                    this.jsNamespace = string.IsNullOrEmpty(type.Namespace)
                        ? type.DeclaringType.Name
                        : string.Format("{0}.{1}", type.Namespace, type.DeclaringType.Name);
                }
                else
                {
                    this.jsNamespace = type.Namespace ?? "";
                }

                if (type.IsGenericType)
                {
                    this.jsName = naming.Substring(0, naming.IndexOf('`'));
                    foreach (var gp in type.GetGenericArguments())
                    {
                        this.jsName += "_" + gp.Name;
                    }
                }
                else
                {
                    this.jsName = naming;
                }
            }
            this.name         = "DuktapeJS_" + (this.jsNamespace + "_" + this.jsName).Replace('.', '_').Replace('+', '_');
            this.constructors = new ConstructorBindingInfo(type);
        }