示例#1
0
        void InitMembers(IKVM.Reflection.Type typeDefinition, IUnresolvedTypeDefinition td, IList<IUnresolvedMember> members)
        {
            foreach (var method in typeDefinition.GetMethods (bindingFlags)) {
                if (IsVisible(method.Attributes) && !IsAccessor(method)) {
                    EntityType type = EntityType.Method;
                    if (method.IsSpecialName) {
                        if (method.Name.StartsWith("op_", StringComparison.Ordinal))
                            type = EntityType.Operator;
                    }
                    members.Add(ReadMethod(method, td, type));
                }
            }

            foreach (var method in typeDefinition.GetConstructors (bindingFlags)) {
                if (IsVisible(method.Attributes)) {
                    EntityType type = EntityType.Constructor;
                    members.Add(ReadConstructor(method, td, type));
                }
            }

            foreach (var field in typeDefinition.GetFields (bindingFlags)) {
                if (IsVisible(field.Attributes) && !field.IsSpecialName) {
                    members.Add(ReadField(field, td));
                }
            }

            string defaultMemberName = null;
            var defaultMemberAttribute = typeDefinition.CustomAttributes.FirstOrDefault(
                a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
            if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
                defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
            }

            foreach (var property in typeDefinition.GetProperties (bindingFlags)) {
                bool getterVisible = property.GetMethod != null && IsVisible(property.GetMethod.Attributes);
                bool setterVisible = property.SetMethod != null && IsVisible(property.SetMethod.Attributes);
                if (getterVisible || setterVisible) {
                    EntityType type = EntityType.Property;
                    if (property.GetIndexParameters () != null) {
                        // Try to detect indexer:
                        if (property.Name == defaultMemberName) {
                            type = EntityType.Indexer; // normal indexer
                        }
                        // TODO: HasOverrides ?
                        else if (property.Name.EndsWith(".Item", StringComparison.Ordinal) /*&& (property.GetMethod ?? property.SetMethod).HasOverrides*/) {
                            // explicit interface implementation of indexer
                            type = EntityType.Indexer;
                            // We can't really tell parameterized properties and indexers apart in this case without
                            // resolving the interface, so we rely on the "Item" naming convention instead.
                        }
                    }
                    members.Add(ReadProperty(property, td, type));
                }
            }

            foreach (var ev in typeDefinition.GetEvents (bindingFlags)) {
                if (ev.AddMethod != null && IsVisible(ev.AddMethod.Attributes)) {
                    members.Add(ReadEvent(ev, td));
                }
            }
        }