Ejemplo n.º 1
0
        private IEnumerable <MemberDeclarationSyntax> getMembers(Type type, TypeNameResolver typeNameResolver)
        {
            // TODO: Add static members to a manager interface. (Daniel Potter, 11/8/2017)
            foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (memberInfo.GetCustomAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)) != null)
                {
                    continue;
                }

                MemberExtensionKind extensionKind;
                switch (memberInfo.MemberType)
                {
                case MemberTypes.Constructor:
                    // TODO: Constructors should be added to a manager interface. (Daniel
                    //       Potter, 11/8/2017)
                    break;

                case MemberTypes.Event:
                    var eventInfo = (EventInfo)memberInfo;

                    extensionKind = eventInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    EventFieldDeclarationSyntax eventDeclaration = getEvent(eventInfo, typeNameResolver);

                    if (extensionKind == MemberExtensionKind.New)
                    {
                        eventDeclaration = eventDeclaration
                                           .AddModifiers(Token(SyntaxKind.NewKeyword));
                    }

                    yield return(eventDeclaration);

                    break;

                case MemberTypes.Field:
                    // TODO: Constants need to be handled somehow. (Daniel Potter, 11/8/2017)
                    break;

                case MemberTypes.Method:
                    var methodInfo = (MethodInfo)memberInfo;

                    if (methodInfo.IsSpecialName)
                    {
                        continue;
                    }

                    extensionKind = methodInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    MethodDeclarationSyntax methodDeclaration = getMethod(methodInfo, typeNameResolver);

                    if (extensionKind == MemberExtensionKind.New)
                    {
                        methodDeclaration = methodDeclaration
                                            .AddModifiers(Token(SyntaxKind.NewKeyword));
                    }

                    yield return(methodDeclaration);

                    break;

                case MemberTypes.Property:
                    var propertyInfo = (PropertyInfo)memberInfo;

                    extensionKind = propertyInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    if (propertyInfo.GetIndexParameters().Length > 0)
                    {
                        IndexerDeclarationSyntax indexerDeclaration = getIndexer(propertyInfo, typeNameResolver);

                        if (extensionKind == MemberExtensionKind.New)
                        {
                            indexerDeclaration = indexerDeclaration
                                                 .AddModifiers(Token(SyntaxKind.NewKeyword));
                        }

                        yield return(indexerDeclaration);
                    }
                    else
                    {
                        PropertyDeclarationSyntax propertyDeclaration = getProperty(propertyInfo, typeNameResolver);

                        if (extensionKind == MemberExtensionKind.New)
                        {
                            propertyDeclaration = propertyDeclaration
                                                  .AddModifiers(Token(SyntaxKind.NewKeyword));
                        }

                        yield return(propertyDeclaration);
                    }
                    break;

                case MemberTypes.NestedType:
                    // TODO: Nested types need to be handled somehow. (Daniel Potter, 11/8/2017)
                    break;

                default:
                    // TODO: Log these for diagnostics. (Daniel Potter, 11/8/2017)
                    break;
                }
            }
        }