internal static string getType()

in lang/csharp/src/apache/main/CodeGen/CodeGen.cs [926:1022]


        internal static string getType(Schema schema, bool nullible, ref bool nullibleEnum)
        {
            switch (schema.Tag)
            {
                case Schema.Type.Null:
                    return typeof(object).ToString();
                case Schema.Type.Boolean:
                    return nullible ? $"System.Nullable<{typeof(bool)}>" : typeof(bool).ToString();

                case Schema.Type.Int:
                    return nullible ? $"System.Nullable<{typeof(int)}>" : typeof(int).ToString();

                case Schema.Type.Long:
                    return nullible ? $"System.Nullable<{typeof(long)}>" : typeof(long).ToString();

                case Schema.Type.Float:
                    return nullible ? $"System.Nullable<{typeof(float)}>" : typeof(float).ToString();

                case Schema.Type.Double:
                    return nullible ? $"System.Nullable<{typeof(double)}>" : typeof(double).ToString();

                case Schema.Type.Bytes:
                    return typeof(byte[]).ToString();
                case Schema.Type.String:
                    return typeof(string).ToString();

                case Schema.Type.Enumeration:
                    var namedSchema = schema as NamedSchema;
                    if (namedSchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into a named schema");
                    }

                    if (nullible)
                    {
                        nullibleEnum = true;
                        return "System.Nullable<" + CodeGenUtil.Instance.Mangle(namedSchema.Fullname) + ">";
                    }
                    else
                    {
                        return CodeGenUtil.Instance.Mangle(namedSchema.Fullname);
                    }

                case Schema.Type.Fixed:
                case Schema.Type.Record:
                case Schema.Type.Error:
                    namedSchema = schema as NamedSchema;
                    if (namedSchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into a named schema");
                    }

                    return CodeGenUtil.Instance.Mangle(namedSchema.Fullname);

                case Schema.Type.Array:
                    var arraySchema = schema as ArraySchema;
                    if (arraySchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into an array schema");
                    }

                    return "IList<" + getType(arraySchema.ItemSchema, false, ref nullibleEnum) + ">";

                case Schema.Type.Map:
                    var mapSchema = schema as MapSchema;
                    if (mapSchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into a map schema");
                    }

                    return "IDictionary<string," + getType(mapSchema.ValueSchema, false, ref nullibleEnum) + ">";

                case Schema.Type.Union:
                    var unionSchema = schema as UnionSchema;
                    if (unionSchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into a union schema");
                    }

                    Schema nullibleType = GetNullableType(unionSchema);

                    return nullibleType == null ? CodeGenUtil.Object : getType(nullibleType, true, ref nullibleEnum);

                case Schema.Type.Logical:
                    var logicalSchema = schema as LogicalSchema;
                    if (logicalSchema == null)
                    {
                        throw new CodeGenException("Unable to cast schema into a logical schema");
                    }

                    var csharpType = logicalSchema.LogicalType.GetCSharpType(nullible);
                    return csharpType.IsGenericType && csharpType.GetGenericTypeDefinition() == typeof(Nullable<>)
                        ? $"System.Nullable<{csharpType.GetGenericArguments()[0]}>" : csharpType.ToString();
            }

            throw new CodeGenException("Unable to generate CodeTypeReference for " + schema.Name + " type " + schema.Tag);
        }