Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1899

PascalCase for property names generated by avrogen for C#

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • csharp
    • None

    Description

      Currently (code in branch 1.8) avrogen generates properties in C# data classes 1:1 as they are defined in shema, what results for field named 'favorite_color' in code like following:

      public string favorite_color {
      get

      { return this._favorite_color; }
      set { this._favorite_color = value; }
      }

      In general property names should use PascalCasing (see: https://msdn.microsoft.com/en-us/library/ms229043.aspx) and correctly generated code would look like

      public string FavoriteColor {
      get { return this._favorite_color; }

      set

      { this._favorite_color = value; }

      }

      Potential change is rather minor:

      .\avro\lang\csharp\src\apache\main\CodeGen\CodeGen.cs : 581
      change
      var mangledName = CodeGenUtil.Instance.Mangle(field.Name);

      to
      var mangledName = CodeGenUtil.Instance.Mangle(AsPropName(field.Name));

      where AsPropName function may look like following

      public string AsPropName(string name)

      { return Regex.Replace(name, @"^\S|_\S", match => match.Value.Replace("_","").ToUpper()); }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              xtracoder Xtra Coder
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: