Skip to content

Conversation

@Kybxd
Copy link
Collaborator

@Kybxd Kybxd commented May 9, 2025

What should we have learned?

C# code style:

Example (in practice by a Unity Game)

#region This file is auto generated. DO NOT EDIT.
using Protoconf;
using System;
using System.IO;
using System.IO.Compression;
using Google.Protobuf;
public static class Datatable
{
    public static void MergeFrom(byte[] data)
    {
        using (var ms = new MemoryStream(data))
        {
            MergeFromZip(ms);
        }
    }
    private static void MergeFromZip(MemoryStream ms)
    {
        ZipArchive zipArchive = new ZipArchive(ms);
        foreach (ZipArchiveEntry entry in zipArchive.Entries)
        {

            if (entry.Length > 0)
            {
                string fileName = entry.Name;
                int dotIndex = fileName.LastIndexOf('.');
                if (dotIndex > 0)
                {
                    fileName = fileName.Substring(0, dotIndex);
                }
                using (Stream entryStream = entry.Open())
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        entryStream.CopyTo(memoryStream);
                        memoryStream.Position = 0;
                        SetConf(fileName, memoryStream);
                    }
                }
            }
        }
    }
    public static HeroConf HeroConf { get; private set; }
    public static ItemConf ItemConf { get; private set; }
    public static VipConf VipConf { get; private set; }

    private static void SetConf(string name, MemoryStream ms)
    {
        switch (name)
        {
            case "HeroConf":
                HeroConf = Deserialize<HeroConf>(ms);
                break;
            case "ItemConf":
                ItemConf = Deserialize<ItemConf>(ms);
                break;
            case "VipConf":
                VipConf = Deserialize<VipConf>(ms);
                break;

            default:
                throw new Exception($"unknown config: {name}");
        }
    }
    private static T Deserialize<T>(MemoryStream ms)
    {
        Type protoType = typeof(T);
        IMessage protoObject = Activator.CreateInstance(protoType) as IMessage;
        protoObject.MergeFrom(ms);
        return (T)protoObject;
    }
}

#endregion

@Kybxd Kybxd force-pushed the csharp-loader branch from cce90e8 to 9a5d600 Compare May 9, 2025 11:57
@wenchy wenchy added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 21, 2025
Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Comment on helper.go:

The newly added Indent function:

func Indent(depth int) string {
	return strings.Repeat("    ", depth)
}

Explanation:
This utility function generates a string consisting of depth repetitions of four spaces. It's a concise and idiomatic way to create indentation for generated code, improving readability and maintainability in code generation scenarios. Whenever you need to output a line with a certain indentation level, you can simply call Indent(level) to get the appropriate amount of leading spaces.

Suggestion:
The implementation is clear and effective. If you anticipate changes to the indent style (for example, switching from 4 spaces to a tab), you could consider defining the indent string as a constant at the top of the file for easier updates:

const indentString = "    "

func Indent(depth int) string {
	return strings.Repeat(indentString, depth)
}

But this is optional. The current code is good as-is!


@wenchy
Copy link
Member

wenchy commented Jul 12, 2025

Hi, @pengjipan! please review this PR (tableau C# loader protoc plugin). As you are an experienced and senior C# developer.

- Install: **dotnet-sdk-8.0**
- Change dir: `cd test/csharp-tableau-loader`
- Generate protoconf: `sh gen.sh`
- Test: `dotnet run`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,127 @@
// Code generated by protoc-gen-csharp-tableau-loader. DO NOT EDIT.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated code files should have suffix: .pc.cs, which C++ and Go also uses.

@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT USE Microsoft Visual Studio, we should use just VSCode.

See https://code.visualstudio.com/docs/languages/csharp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default file content created by dotnet new sln

@Kybxd Kybxd force-pushed the csharp-loader branch 4 times, most recently from 4fde7cb to 472ad69 Compare August 26, 2025 07:37

### Requirements

- dotnet-sdk-8.0
Copy link
Member

@wenchy wenchy Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C#: add loader plugin for C#

3 participants