Avro C#
Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
Avro.CodeGen Class Reference

Generates C# code from Avro schemas and protocols. More...

Public Member Functions

 CodeGen ()
 Initializes a new instance of the CodeGen class. More...
 
 CodeGen (Dictionary< string, CodeNamespace > namespaceLookup)
 Initializes a new instance of the CodeGen class. More...
 
virtual void AddProtocol (Protocol protocol)
 Adds a protocol object to generate code for. More...
 
virtual void AddProtocol (string protocolText, IEnumerable< KeyValuePair< string, string >> namespaceMapping=null)
 Parses and adds a protocol object to generate code for. More...
 
virtual void AddSchema (Schema schema)
 Adds a schema object to generate code for. More...
 
virtual void AddSchema (string schemaText, IEnumerable< KeyValuePair< string, string >> namespaceMapping=null)
 Parses and adds a schema object to generate code for. More...
 
virtual CodeCompileUnit GenerateCode ()
 Generates code for the given protocol and schema objects. More...
 
virtual void WriteCompileUnit (string outputFile)
 Writes the generated compile unit into one file. More...
 
virtual void WriteTypes (string outputdir, bool skipDirectories=false)
 Writes each types in each namespaces into individual files. More...
 

Static Public Member Functions

static Schema getNullableType (UnionSchema schema)
 Gets the schema of a union with null. More...
 
static Schema GetNullableType (UnionSchema schema)
 Gets the schema of a union with null. More...
 

Protected Member Functions

virtual CodeNamespace AddNamespace (string name)
 Adds a namespace object for the given name into the dictionary if it doesn't exist yet. More...
 
virtual CodeNamespace addNamespace (string name)
 Adds a namespace object for the given name into the dictionary if it doesn't exist yet. More...
 
virtual void ProcessSchemas ()
 Generates code for the schema objects. More...
 
virtual void processSchemas ()
 Generates code for the schema objects. More...
 
virtual void ProcessProtocols ()
 Generates code for the protocol objects. More...
 
virtual void processProtocols ()
 Generates code for the protocol objects. More...
 
virtual SchemaNames generateNames (Protocol protocol)
 Generate list of named schemas from given protocol. More...
 
virtual SchemaNames GenerateNames (Protocol protocol)
 Generate list of named schemas from given protocol. More...
 
virtual SchemaNames generateNames (Schema schema)
 Generate list of named schemas from given schema. More...
 
virtual SchemaNames GenerateNames (Schema schema)
 Generate list of named schemas from given schema. More...
 
virtual void addName (Schema schema, SchemaNames names)
 Recursively search the given schema for named schemas and adds them to the given container. More...
 
virtual void processFixed (Schema schema)
 Creates a class declaration for fixed schema. More...
 
virtual void processEnum (Schema schema)
 Creates an enum declaration. More...
 
virtual void processInterface (Protocol protocol)
 Generates code for an individual protocol. More...
 
virtual CodeTypeDeclaration processRecord (Schema schema)
 Creates a class declaration. More...
 
virtual void createSchemaField (Schema schema, CodeTypeDeclaration ctd, bool overrideFlag)
 Creates the static schema field for class types. More...
 
virtual CodeCommentStatement createDocComment (string comment)
 Creates an XML documentation for the given comment. More...
 

Properties

CodeCompileUnit CompileUnit [get]
 Gets object that contains all the generated types. More...
 
IList< SchemaSchemas [get]
 Gets list of schemas to generate code for. More...
 
IList< ProtocolProtocols [get]
 Gets list of protocols to generate code for. More...
 
IDictionary< string, string > NamespaceMapping [get]
 Gets mapping of Avro namespaces to C# namespaces. More...
 
Dictionary< string, CodeNamespace > NamespaceLookup [get]
 Gets list of generated namespaces. More...
 

Detailed Description

Generates C# code from Avro schemas and protocols.

Constructor & Destructor Documentation

◆ CodeGen() [1/2]

Avro.CodeGen.CodeGen ( )
inline

Initializes a new instance of the CodeGen class.

◆ CodeGen() [2/2]

Avro.CodeGen.CodeGen ( Dictionary< string, CodeNamespace >  namespaceLookup)
inline

Initializes a new instance of the CodeGen class.

Parameters
namespaceLookupThe namespace lookup.

Member Function Documentation

◆ addName()

virtual void Avro.CodeGen.addName ( Schema  schema,
SchemaNames  names 
)
inlineprotectedvirtual

Recursively search the given schema for named schemas and adds them to the given container.

Parameters
schemaschema object to search.
nameslist of named schemas.
Exceptions
CodeGenExceptionUnable to add name for " + schema.Name + " type " + schema.Tag.

◆ AddNamespace()

virtual CodeNamespace Avro.CodeGen.AddNamespace ( string  name)
inlineprotectedvirtual

Adds a namespace object for the given name into the dictionary if it doesn't exist yet.

Parameters
namename of namespace.
Returns
Code Namespace.
Exceptions
ArgumentNullExceptionname - name cannot be null.

◆ addNamespace()

virtual CodeNamespace Avro.CodeGen.addNamespace ( string  name)
inlineprotectedvirtual

Adds a namespace object for the given name into the dictionary if it doesn't exist yet.

Parameters
namename of namespace.
Returns
Code Namespace.
Exceptions
ArgumentNullExceptionname - name cannot be null.

◆ AddProtocol() [1/2]

virtual void Avro.CodeGen.AddProtocol ( Protocol  protocol)
inlinevirtual

Adds a protocol object to generate code for.

Parameters
protocolThe protocol.

◆ AddProtocol() [2/2]

virtual void Avro.CodeGen.AddProtocol ( string  protocolText,
IEnumerable< KeyValuePair< string, string >>  namespaceMapping = null 
)
inlinevirtual

Parses and adds a protocol object to generate code for.

Parameters
protocolTextThe protocol.
namespaceMappingnamespace mapping key value pairs.

◆ AddSchema() [1/2]

virtual void Avro.CodeGen.AddSchema ( Schema  schema)
inlinevirtual

Adds a schema object to generate code for.

Parameters
schemaschema object.

◆ AddSchema() [2/2]

virtual void Avro.CodeGen.AddSchema ( string  schemaText,
IEnumerable< KeyValuePair< string, string >>  namespaceMapping = null 
)
inlinevirtual

Parses and adds a schema object to generate code for.

Parameters
schemaTextschema object.
namespaceMappingnamespace mapping key value pairs.

◆ createDocComment()

virtual CodeCommentStatement Avro.CodeGen.createDocComment ( string  comment)
inlineprotectedvirtual

Creates an XML documentation for the given comment.

Parameters
commentcomment.
Returns
a statement consisting of a single comment.

◆ createSchemaField()

virtual void Avro.CodeGen.createSchemaField ( Schema  schema,
CodeTypeDeclaration  ctd,
bool  overrideFlag 
)
inlineprotectedvirtual

Creates the static schema field for class types.

Parameters
schemaschema.
ctdCodeTypeDeclaration for the class.
overrideFlagIndicates whether we should add the MemberAttributes.Override to the generated property.

◆ GenerateCode()

virtual CodeCompileUnit Avro.CodeGen.GenerateCode ( )
inlinevirtual

Generates code for the given protocol and schema objects.

Returns
CodeCompileUnit object.

◆ generateNames() [1/2]

virtual SchemaNames Avro.CodeGen.generateNames ( Protocol  protocol)
inlineprotectedvirtual

Generate list of named schemas from given protocol.

Parameters
protocolprotocol to process.
Returns
List of named schemas.
Exceptions
ArgumentNullExceptionprotocol - Protocol can not be null.

◆ GenerateNames() [1/2]

virtual SchemaNames Avro.CodeGen.GenerateNames ( Protocol  protocol)
inlineprotectedvirtual

Generate list of named schemas from given protocol.

Parameters
protocolprotocol to process.
Returns
List of named schemas.
Exceptions
ArgumentNullExceptionprotocol - Protocol can not be null.

◆ generateNames() [2/2]

virtual SchemaNames Avro.CodeGen.generateNames ( Schema  schema)
inlineprotectedvirtual

Generate list of named schemas from given schema.

Parameters
schemaschema to process.
Returns
List of named schemas.

◆ GenerateNames() [2/2]

virtual SchemaNames Avro.CodeGen.GenerateNames ( Schema  schema)
inlineprotectedvirtual

Generate list of named schemas from given schema.

Parameters
schemaschema to process.
Returns
List of named schemas.

◆ getNullableType()

static Schema Avro.CodeGen.getNullableType ( UnionSchema  schema)
inlinestatic

Gets the schema of a union with null.

Parameters
schemaunion schema.
Returns
schema that is nullable.
Exceptions
ArgumentNullExceptionschema - UnionSchema can not be null.

◆ GetNullableType()

static Schema Avro.CodeGen.GetNullableType ( UnionSchema  schema)
inlinestatic

Gets the schema of a union with null.

Parameters
schemaunion schema.
Returns
schema that is nullable.
Exceptions
ArgumentNullExceptionschema - UnionSchema can not be null.

◆ processEnum()

virtual void Avro.CodeGen.processEnum ( Schema  schema)
inlineprotectedvirtual

Creates an enum declaration.

Parameters
schemaenum schema.
Exceptions
CodeGenExceptionUnable to cast schema into an enum or Enum symbol " + symbol + " is a C# reserved keyword or Namespace required for enum schema " + enumschema.Name.

◆ processFixed()

virtual void Avro.CodeGen.processFixed ( Schema  schema)
inlineprotectedvirtual

Creates a class declaration for fixed schema.

Parameters
schemafixed schema.
Exceptions
CodeGenExceptionUnable to cast schema into a fixed or Namespace required for enum schema " + fixedSchema.Name.

◆ processInterface()

virtual void Avro.CodeGen.processInterface ( Protocol  protocol)
inlineprotectedvirtual

Generates code for an individual protocol.

Parameters
protocolProtocol to generate code for.
Exceptions
CodeGenExceptionNamespace required for enum schema " + nspace.

◆ ProcessProtocols()

virtual void Avro.CodeGen.ProcessProtocols ( )
inlineprotectedvirtual

Generates code for the protocol objects.

Exceptions
CodeGenExceptionNames in protocol should only be of type NamedSchema, type found {sn.Value.Tag}

◆ processProtocols()

virtual void Avro.CodeGen.processProtocols ( )
inlineprotectedvirtual

Generates code for the protocol objects.

Exceptions
CodeGenExceptionNames in protocol should only be of type NamedSchema, type found {sn.Value.Tag}

◆ processRecord()

virtual CodeTypeDeclaration Avro.CodeGen.processRecord ( Schema  schema)
inlineprotectedvirtual

Creates a class declaration.

Parameters
schemarecord schema.
Returns
A new class code type declaration.
Exceptions
CodeGenExceptionUnable to cast schema into a record or Namespace required for record schema " + recordSchema.Name.

◆ ProcessSchemas()

virtual void Avro.CodeGen.ProcessSchemas ( )
inlineprotectedvirtual

Generates code for the schema objects.

Exceptions
CodeGenExceptionNames in schema should only be of type NamedSchema, type found " + sn.Value.Tag.

◆ processSchemas()

virtual void Avro.CodeGen.processSchemas ( )
inlineprotectedvirtual

Generates code for the schema objects.

Exceptions
CodeGenExceptionNames in schema should only be of type NamedSchema, type found " + sn.Value.Tag.

◆ WriteCompileUnit()

virtual void Avro.CodeGen.WriteCompileUnit ( string  outputFile)
inlinevirtual

Writes the generated compile unit into one file.

Parameters
outputFilename of output file to write to.

◆ WriteTypes()

virtual void Avro.CodeGen.WriteTypes ( string  outputdir,
bool  skipDirectories = false 
)
inlinevirtual

Writes each types in each namespaces into individual files.

Parameters
outputdirname of directory to write to.
skipDirectoriesskip creation of directories based on schema namespace

Property Documentation

◆ CompileUnit

CodeCompileUnit Avro.CodeGen.CompileUnit
get

Gets object that contains all the generated types.

The code compile unit.

◆ NamespaceLookup

Dictionary<string, CodeNamespace> Avro.CodeGen.NamespaceLookup
getprotected

Gets list of generated namespaces.

The namespace lookup.

◆ NamespaceMapping

IDictionary<string, string> Avro.CodeGen.NamespaceMapping
get

Gets mapping of Avro namespaces to C# namespaces.

The namespace mapping.

◆ Protocols

IList<Protocol> Avro.CodeGen.Protocols
get

Gets list of protocols to generate code for.

The protocols.

◆ Schemas

IList<Schema> Avro.CodeGen.Schemas
get

Gets list of schemas to generate code for.

The schemas.


The documentation for this class was generated from the following file: