Beispiel #1
0
            public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node)
            {
                var nodeName = node.QualifiedName();

                if (nodeName != m_EnumTypeName)
                {
                    return(base.VisitEnumDeclaration(node));
                }

                var classDeclaration = ClassDeclaration(m_EnumTypeName.Name)
                                       .WithModifiers(node.Modifiers)
                                       .Abstract()
                                       .AddMembers(node
                                                   .WithIdentifier(ParseToken(m_NestedEnumTypeName))
                                                   .Internal())
                                       .AddProperty(m_NestedEnumTypeName, m_EnumPropertyName, p => p.Internal())
                                       .AddMembers(ConstructorDeclaration(node.Identifier.WithoutTrivia())
                                                   .AddParameterListParameters(Parameter(ParseToken(m_EnumPropertyName.ToParameterName()))
                                                                               .WithType(ParseTypeName(m_NestedEnumTypeName)))
                                                   .WithExpressionBody($"{m_EnumPropertyName} = {m_EnumPropertyName.ToParameterName()}")
                                                   )
                                       .AddMembers(MethodDeclaration(ParseTypeName("string"), "ToString")
                                                   .Public()
                                                   .Override()
                                                   .WithExpressionBody($"Enum.GetName(typeof({m_NestedEnumTypeName}), {m_EnumPropertyName}) ?? {DefaultEnumPropertyName}.ToString()")
                                                   )
                                       .AddMembers(MethodDeclaration(ParseTypeName("bool"), "Equals")
                                                   .AddParameterListParameters(Parameter(ParseToken("other")).WithType(ParseTypeName(m_EnumTypeName.Name)))
                                                   .WithExpressionBody($"{m_EnumPropertyName} == other.{m_EnumPropertyName}"))
                                       .AddMembers(MethodDeclaration(ParseTypeName("bool"), "Equals")
                                                   .Public()
                                                   .Override()
                                                   .AddParameterListParameters(Parameter(ParseToken("obj")).WithType(CurrentCompilationOptions.Nullability ? ParseTypeName("object?") : ParseTypeName("object")))
                                                   .WithBody(Block(
                                                                 ParseStatement("if (ReferenceEquals(null, obj)) return false;").WithTrailingTrivia(CarriageReturnLineFeed),
                                                                 ParseStatement("if (ReferenceEquals(this, obj)) return true;").WithTrailingTrivia(CarriageReturnLineFeed),
                                                                 ParseStatement("if (obj.GetType() != GetType()) return false;").WithTrailingTrivia(CarriageReturnLineFeed),
                                                                 ParseStatement($"return Equals(({m_EnumTypeName.Name}) obj);")
                                                                 )))
                                       .AddMembers(MethodDeclaration(ParseTypeName("int"), "GetHashCode")
                                                   .Public()
                                                   .Override()
                                                   .WithParameterList(ParameterList())
                                                   .WithExpressionBody($"(int) {m_EnumPropertyName}")
                                                   );

                return(classDeclaration);
            }
        public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            String name        = node.Identifier.ValueText;
            String replaceName = "";

            if (SharedContainer.Instance.nameMap.ContainsKey(name))
            {
                replaceName = SharedContainer.Instance.nameMap[name];
            }
            else
            {
                replaceName = SharedContainer.Instance.RandomString(SharedContainer.Instance.nameMap.Count() + 1);
                SharedContainer.Instance.nameType[name] = Priority.En_Priority.CLASS;
                SharedContainer.Instance.nameMap[name]  = replaceName;
            }

            EnumDeclarationSyntax newSyntax = node.WithIdentifier(Identifier(replaceName)).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());

            return(base.VisitEnumDeclaration(node.ReplaceNode(node, newSyntax)));
        }