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 IDictionary< string, string > | GetTypes ()
| Gets names and generated code of the schema(s) types 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< Schema > | Schemas`[get]`
| Gets list of schemas to generate code for. More...
IList< Protocol > | Protocols`[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

  namespaceLookup | The namespace lookup.

## Member Function Documentation

## ◆ addName()

virtual void Avro.CodeGen.addName | ( | Schema | schema,
|  | SchemaNames | names
| ) |  |
| inline protected virtual

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

Parameters

  schema | schema object to search.
  names | list of named schemas.

Exceptions

  CodeGenException | Unable to add name for " + schema.Name + " type " + schema.Tag.

## ◆ AddNamespace()

virtual CodeNamespace Avro.CodeGen.AddNamespace | ( | string | name | ) |
| inline protected virtual

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

Parameters

  name | name of namespace.

Returns
  Code Namespace.

Exceptions

  ArgumentNullException | name - name cannot be null.

## ◆ addNamespace()

virtual CodeNamespace Avro.CodeGen.addNamespace | ( | string | name | ) |
| inline protected virtual

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

Parameters

  name | name of namespace.

Returns
  Code Namespace.

Exceptions

  ArgumentNullException | name - name cannot be null.

## ◆ AddProtocol() [1/2]

virtual void Avro.CodeGen.AddProtocol | ( | Protocol | protocol | ) |
| inline virtual

Adds a protocol object to generate code for.

Parameters

  protocol | The protocol.

## ◆ AddProtocol() [2/2]

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

Parses and adds a protocol object to generate code for.

Parameters

  protocolText | The protocol.
  namespaceMapping | namespace mapping key value pairs.

## ◆ AddSchema() [1/2]

virtual void Avro.CodeGen.AddSchema | ( | Schema | schema | ) |
| inline virtual

Adds a schema object to generate code for.

Parameters

  schema | schema object.

## ◆ AddSchema() [2/2]

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

Parses and adds a schema object to generate code for.

Parameters

  schemaText | schema object.
  namespaceMapping | namespace mapping key value pairs.

## ◆ createDocComment()

virtual CodeCommentStatement Avro.CodeGen.createDocComment | ( | string | comment | ) |
| inline protected virtual

Creates an XML documentation for the given comment.

Parameters

  comment | comment.

Returns
  a statement consisting of a single comment.

## ◆ createSchemaField()

virtual void Avro.CodeGen.createSchemaField | ( | Schema | schema,
|  | CodeTypeDeclaration | ctd,
|  | bool | overrideFlag
| ) |  |
| inline protected virtual

Creates the static schema field for class types.

Parameters

  schema | schema.
  ctd | CodeTypeDeclaration for the class.
  overrideFlag | Indicates whether we should add the MemberAttributes.Override to the generated property.

## ◆ GenerateCode()

virtual CodeCompileUnit Avro.CodeGen.GenerateCode | ( |  | ) |
| inline virtual

Generates code for the given protocol and schema objects.

Returns
  CodeCompileUnit object.

## ◆ generateNames() [1/2]

virtual SchemaNames Avro.CodeGen.generateNames | ( | Protocol | protocol | ) |
| inline protected virtual

Generate list of named schemas from given protocol.

Parameters

  protocol | protocol to process.

Returns
  List of named schemas.

Exceptions

  ArgumentNullException | protocol - Protocol can not be null.

## ◆ GenerateNames() [1/2]

virtual SchemaNames Avro.CodeGen.GenerateNames | ( | Protocol | protocol | ) |
| inline protected virtual

Generate list of named schemas from given protocol.

Parameters

  protocol | protocol to process.

Returns
  List of named schemas.

Exceptions

  ArgumentNullException | protocol - Protocol can not be null.

## ◆ generateNames() [2/2]

virtual SchemaNames Avro.CodeGen.generateNames | ( | Schema | schema | ) |
| inline protected virtual

Generate list of named schemas from given schema.

Parameters

  schema | schema to process.

Returns
  List of named schemas.

## ◆ GenerateNames() [2/2]

virtual SchemaNames Avro.CodeGen.GenerateNames | ( | Schema | schema | ) |
| inline protected virtual

Generate list of named schemas from given schema.

Parameters

  schema | schema to process.

Returns
  List of named schemas.

## ◆ getNullableType()

static Schema Avro.CodeGen.getNullableType | ( | UnionSchema | schema | ) |
| inline static

Gets the schema of a union with null.

Parameters

  schema | union schema.

Returns
  schema that is nullable.

Exceptions

  ArgumentNullException | schema - UnionSchema can not be null.

## ◆ GetNullableType()

static Schema Avro.CodeGen.GetNullableType | ( | UnionSchema | schema | ) |
| inline static

Gets the schema of a union with null.

Parameters

  schema | union schema.

Returns
  schema that is nullable.

Exceptions

  ArgumentNullException | schema - UnionSchema can not be null.

## ◆ GetTypes()

virtual IDictionary<string, string> Avro.CodeGen.GetTypes | ( |  | ) |
| inline virtual

Gets names and generated code of the schema(s) types

Returns

## ◆ processEnum()

virtual void Avro.CodeGen.processEnum | ( | Schema | schema | ) |
| inline protected virtual

Creates an enum declaration.

Parameters

  schema | enum schema.

Exceptions

  CodeGenException | Unable 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 | ) |
| inline protected virtual

Creates a class declaration for fixed schema.

Parameters

  schema | fixed schema.

Exceptions

  CodeGenException | Unable to cast schema into a fixed or Namespace required for enum schema " + fixedSchema.Name.

## ◆ processInterface()

virtual void Avro.CodeGen.processInterface | ( | Protocol | protocol | ) |
| inline protected virtual

Generates code for an individual protocol.

Parameters

  protocol | Protocol to generate code for.

Exceptions

  CodeGenException | Namespace required for enum schema " + nspace.

## ◆ ProcessProtocols()

virtual void Avro.CodeGen.ProcessProtocols | ( |  | ) |
| inline protected virtual

Generates code for the protocol objects.

Exceptions

  CodeGenException | Names in protocol should only be of type NamedSchema, type found {sn.Value.Tag}

## ◆ processProtocols()

virtual void Avro.CodeGen.processProtocols | ( |  | ) |
| inline protected virtual

Generates code for the protocol objects.

Exceptions

  CodeGenException | Names in protocol should only be of type NamedSchema, type found {sn.Value.Tag}

## ◆ processRecord()

virtual CodeTypeDeclaration Avro.CodeGen.processRecord | ( | Schema | schema | ) |
| inline protected virtual

Creates a class declaration.

Parameters

  schema | record schema.

Returns
  A new class code type declaration.

Exceptions

  CodeGenException | Unable to cast schema into a record or Namespace required for record schema " + recordSchema.Name.

## ◆ ProcessSchemas()

virtual void Avro.CodeGen.ProcessSchemas | ( |  | ) |
| inline protected virtual

Generates code for the schema objects.

Exceptions

  CodeGenException | Names in schema should only be of type NamedSchema, type found " + sn.Value.Tag.

## ◆ processSchemas()

virtual void Avro.CodeGen.processSchemas | ( |  | ) |
| inline protected virtual

Generates code for the schema objects.

Exceptions

  CodeGenException | Names in schema should only be of type NamedSchema, type found " + sn.Value.Tag.

## ◆ WriteCompileUnit()

virtual void Avro.CodeGen.WriteCompileUnit | ( | string | outputFile | ) |
| inline virtual

Writes the generated compile unit into one file.

Parameters

  outputFile | name of output file to write to.

## ◆ WriteTypes()

virtual void Avro.CodeGen.WriteTypes | ( | string | outputdir,
|  | bool | skipDirectories = `false`
| ) |  |
| inline virtual

Writes each types in each namespaces into individual files.

Parameters

  outputdir | name of directory to write to.
  skipDirectories | skip 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
| get protected

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:

- src/apache/main/CodeGen/CodeGen.cs