Exemple #1
0
        // 收集所有 字段,属性,方法
        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);
        }