[ 
https://issues.apache.org/jira/browse/AVRO-3614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17585292#comment-17585292
 ] 

Kalle Niemitalo commented on AVRO-3614:
---------------------------------------

The CodeGenUtil.Mangle method prepends an @ sign to C# keywords to make the C# 
compiler treat them as identifiers. The main library should preferably be 
neutral with regard to programming languages and not use this method. However, 
CodeGen then calls CodeGenUtil.Mangle from {{{}internal static string 
getType(Schema schema, bool nullible, ref bool nullibleEnum){}}}, which is 
called from:
 * The Avro.Specific.SpecificDatumReader<T>.SpecificArrayAccess constructor. 
SpecificArrayAccess then removes "IList<" and ">" from the result and passes 
the rest to ObjectCreator.Instance.New.
 * The Avro.Specific.SpecificDatumReader<T>.SpecificMapAccess constructor, 
which works similarly, except it removes "IDictionary<string," and ">".
 * The Avro.Specific.SpecificDefaultReader.getTargetType method. The result of 
this likewise goes to ObjectCreator.Instance.New.

I think Avro.Specific should be changed not to do any mangling and unmangling. 
Mangling should be done only when C# code is generated, and unmangling should 
perhaps not be done at all. Avro reserves its primitive type names in all 
namespaces anyway, so you don't need mangling to distinguish those from 
user-defined types.

CodeGenUtil.Mangle would then have to recognize C# reserved keywords also next 
to commas and angle brackets, e.g. "IDictionary<string,class.return>", and 
convert to "IDictionary<string,@class.@return>". Perhaps it could just use a 
regexp with the \b word-boundary syntax. This would be called only during C# 
code generation (avrogen) and not during decoding of data, so performance would 
be less important than now.

> Remove System.CodeDom dependency from main library
> --------------------------------------------------
>
>                 Key: AVRO-3614
>                 URL: https://issues.apache.org/jira/browse/AVRO-3614
>             Project: Apache Avro
>          Issue Type: Wish
>          Components: csharp
>    Affects Versions: 1.11.1
>            Reporter: Kalle Niemitalo
>            Priority: Major
>
> The Apache.Avro package on NuGet depends on the System.CodeDom package. I'd 
> like this dependency to be removed so that I wouldn't have to distribute 
> System.CodeDom with my applications, which encode and decode Avro data but do 
> not generate source code at run time.
> This would presumably require moving the code generation features from the 
> Apache.Avro package to a new Apache.Avro.CodeGen package, which would be a 
> breaking change.
> In Avro 1.11.1, System.CodeDom is used by the Avro.CodeGen and 
> Avro.CodeGenUtil classes. From those classes, only the 
> CodeGen.GetNullableType, CodeGenUtil.UnMangle, and CodeGen.getType methods 
> are used by the rest of the library. The CodeGen.getType method also depends 
> on the CodeGenException class and the CodeGenUtil.Mangle method. None of 
> those methods depend on System.CodeDom, so they could be moved to a new 
> static class (perhaps named something like TypeUtil or ReflectionUtil) and 
> kept in the main library.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to