Esempio n. 1
0
        private CSharpOutput CreateCSharpDump(PapyrusAssemblyDefinition asm)
        {
            var type = asm.Types.First();

            var outputFileName = type.Name.Value + ".cs";

            var sourceBuilder     = new SourceBuilder();
            var outputFileContent =
                WriteType(sourceBuilder, asm, type)
                .Replace(" ::", " ")
                .Replace("(::", "(")
                .Replace(",::", ",")
                .Replace("!::", "!");

            return(new CSharpOutput(outputFileName, outputFileContent));
        }
Esempio n. 2
0
        private string WriteType(SourceBuilder source, PapyrusAssemblyDefinition asm, PapyrusTypeDefinition type,
                                 int indent = 0)
        {
            activeBuilder = source;

            if (type.Documentation != null && !string.IsNullOrEmpty(type.Documentation.Value))
            {
                WriteDoc(type.Documentation, indent);
            }

            if (type.IsStruct)
            {
                Append("public struct " + (string)type.Name + " ", indent);
            }
            else
            {
                Append("public class " + (string)type.Name + " ", indent);
            }

            if (!RefIsNull(type.BaseTypeName))
            {
                Append(": " + (string)type.BaseTypeName + Environment.NewLine);
            }

            AppendLine("{", indent);


            foreach (var t in type.NestedTypes)
            {
                WriteType(source, asm, t, indent + 1);
            }

            foreach (var field in type.Fields)
            {
                if (field.Documentation != null && !string.IsNullOrEmpty(field.Documentation))
                {
                    WriteDoc(field.Documentation, indent + 1);
                }
                if (field.TypeName.Contains("#"))
                {
                    AppendLine("// Access to Struct: " + field.TypeName, indent + 1);
                    AppendLine("public " + field.TypeName.Split('#').LastOrDefault() + " " + (string)field.Name + ";",
                               indent + 1);
                }
                else
                {
                    AppendLine("public " + field.TypeName + " " + (string)field.Name + ";", indent + 1);
                }
            }

            foreach (var prop in type.Properties)
            {
                if (prop.Documentation != null && !string.IsNullOrEmpty(prop.Documentation.Value))
                {
                    WriteDoc(prop.Documentation, indent + 1);
                }


                //AppendLine("// Struct Variable: " + typeName, indent + 1);
                //AppendLine(typeName.Split('#').LastOrDefault() + " " + ((string)var.Name) + ";", indent + 1);

                var typeName = (string)prop.TypeName;

                if (typeName.Contains("#"))
                {
                    AppendLine("// Struct Property: " + typeName, indent + 1);
                    typeName = typeName.Split('#').LastOrDefault();
                }

                if (!string.IsNullOrEmpty(prop.AutoName))
                {
                    AppendLine("public " + typeName + " " + (string)prop.Name + " { get; set; }", indent + 1);
                }
                else
                {
                    Append("public " + typeName + " " + (string)prop.Name, indent + 1);
                    if (!prop.HasSetter && !prop.HasGetter)
                    {
                        AppendLine("{ get; set; }", indent + 1);
                    }
                    else
                    {
                        AppendLine("");
                        AppendLine("{", 1);
                        if (prop.HasGetter)
                        {
                            Append("get ", 2);
                            WriteMethod(prop.GetMethod, type, asm, indent + 3, prop, true);
                        }
                        if (prop.HasSetter)
                        {
                            Append("set ", 2);
                            WriteMethod(prop.SetMethod, type, asm, indent + 3, prop, false, true);
                        }
                        AppendLine("}", indent + 1);
                    }
                }
            }

            foreach (var s in type.States)
            {
                foreach (var m in s.Methods)
                {
                    WriteMethod(m, type, asm, indent + 1);
                }
            }


            AppendLine("}", indent);

            return(source.ToString());
        }