예제 #1
0
        public TypeTransform TransformType(Type type)
        {
            TypeTransform transform;

            if (!typesTarnsform.TryGetValue(type, out transform))
            {
                typesTarnsform[type] = transform = new TypeTransform(type);
            }
            return(transform);
        }
예제 #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);
        }