Exemple #1
0
        private static string CreateClass(ClassGenerationData classGenerationData, PreservedClassData preservedClassData)
        {
            //  Create a class: (class TestClass)
            var classDeclaration = CreateClassUsingClassGenerationData(classGenerationData);
            var @namespace       = CreateNamespaceDeclarationSyntax(classGenerationData.m_Namespace, classGenerationData.m_Usings);

            if (preservedClassData != null)
            {
                classDeclaration = AppendClassWithPreservedData(classDeclaration, preservedClassData);
            }

            // Add the class to the namespace.
            @namespace = @namespace.AddMembers(classDeclaration);

            // Normalize and get code as string.
            var code = @namespace
                       .NormalizeWhitespace()
                       .ToFullString();

            return(code);
        }
Exemple #2
0
        private static ClassDeclarationSyntax AppendClassWithPreservedData(ClassDeclarationSyntax classDeclaration, PreservedClassData data)
        {
            if (data.m_PreservedFields.Count > 0)
            {
                classDeclaration = classDeclaration.AddMembers(data.m_PreservedFields.ToArray());
            }

            if (data.m_PreservedMethods.Count > 0)
            {
                classDeclaration = classDeclaration.AddMembers(data.m_PreservedMethods.ToArray());
            }

            if (data.m_PreservedProperties.Count > 0)
            {
                classDeclaration = classDeclaration.AddMembers(data.m_PreservedProperties.ToArray());
            }

            return(classDeclaration);
        }
Exemple #3
0
        public static string CreateClass(ClassGenerationData classGenerationData, string codeWithPreservedData = null)
        {
            var preservedData = new PreservedClassData(codeWithPreservedData);

            return(CreateClass(classGenerationData, preservedData));
        }