KalleOlaviNiemitalo commented on code in PR #1571:
URL: https://github.com/apache/avro/pull/1571#discussion_r912544555
##########
lang/csharp/src/apache/main/Schema/Schema.cs:
##########
@@ -380,5 +381,91 @@ protected static int getHashCode(object obj)
{
return obj == null ? 0 : obj.GetHashCode();
}
+
+ /// <summary>
+ /// Parses the Schema.Type from a string.
+ /// </summary>
+ /// <param name="type">The type to convert.</param>
+ /// <param name="removeQuotes">if set to <c>true</c> [remove
quotes].</param>
+ /// <returns>A Schema.Type unless it could not parse then
null</returns>
+ /// <remarks>
+ /// usage ParseType("string") returns Schema.Type.String
+ /// </remarks>
+ public static Schema.Type? ParseType(string type, bool removeQuotes =
false)
+ {
+ string newValue = removeQuotes ? RemoveQuotes(type) : type;
+
+ switch (newValue)
+ {
+ case "null":
+ return Schema.Type.Null;
+
+ case "boolean":
+ return Schema.Type.Boolean;
+
+ case "int":
+ return Schema.Type.Int;
+
+ case "long":
+ return Schema.Type.Long;
+
+ case "float":
+ return Schema.Type.Float;
+
+ case "double":
+ return Schema.Type.Double;
+
+ case "bytes":
+ return Schema.Type.Bytes;
+
+ case "string":
+ return Schema.Type.String;
+
+ case "record":
+ return Schema.Type.Record;
+
+ case "enumeration":
Review Comment:
I am surprised that this is "enumeration", rather than "enum" like in
<https://avro.apache.org/docs/current/spec.html#Enums>.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]