ToString() public method

public ToString ( ) : string
return string
Example #1
0
 private static void testToString(Schema sc)
 {
     try
     {
         Assert.AreEqual(sc, Schema.Parse(sc.ToString()));
     }
     catch (Exception e)
     {
         throw new AvroException(e.ToString() + ": " + sc.ToString());
     }
 }
Example #2
0
        /// <summary>
        /// Creates the static schema field for class types
        /// </summary>
        /// <param name="schema">schema</param>
        /// <param name="ctd">CodeTypeDeclaration for the class</param>
        protected virtual void createSchemaField(Schema schema, CodeTypeDeclaration ctd, bool overrideFlag)
        {
            // create schema field
            var ctrfield = new CodeTypeReference("Schema");
            string schemaFname = "_SCHEMA";
            var codeField = new CodeMemberField(ctrfield, schemaFname);
            codeField.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            // create function call Schema.Parse(json)
            var cpe = new CodePrimitiveExpression(schema.ToString());
            var cmie = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(Schema)), "Parse"),
                new CodeExpression[] { cpe });
            codeField.InitExpression = cmie;
            ctd.Members.Add(codeField);

            // create property to get static schema field
            var property = new CodeMemberProperty();
            property.Attributes = MemberAttributes.Public;
            if (overrideFlag) property.Attributes |= MemberAttributes.Override;
            property.Name = "Schema";
            property.Type = ctrfield;

            property.GetStatements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(ctd.Name + "." + schemaFname)));
            ctd.Members.Add(property);
        }
Example #3
0
        protected virtual void createSchemaJavaField(Schema schema, CodeTypeDeclaration ctd, bool overrideFlag, bool isInterface)
        {
            // create schema field 
            var ctrfield = new CodeTypeReference("org.apache.avro.Schema");

            string schemaFname = "SCHEMA$";
            var codeField = new CodeMemberField(ctrfield, schemaFname);
            codeField.Attributes = MemberAttributes.Public | MemberAttributes.Static | MemberAttributes.Final;
            if (isInterface)
            {
                codeField.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Const;
            }
            // create function call Schema.Parse(json)
            var cpe = new CodePrimitiveExpression(schema.ToString());
            var cmie = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(ctrfield), "parse"),
                new CodeExpression[] { cpe });
            codeField.InitExpression = cmie;
            ctd.Members.Add(codeField);

            if (isInterface)
            {
                return;
            }
            // create property to get static schema field
            var property = new CodeMemberMethod();
            property.Attributes = MemberAttributes.Public;
            if (overrideFlag) property.Attributes |= MemberAttributes.Override;
            property.Name = "getSchema";
            property.ReturnType = ctrfield;
            property.Statements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(ctd.Name + "." + schemaFname)));
            ctd.Members.Add(property);

            // create property to get ther record type
            property = new CodeMemberMethod();
            property.Attributes = MemberAttributes.Public;
            if (overrideFlag) property.Attributes |= MemberAttributes.Override;
            property.Name = "getRecord";
            property.ReturnType = new CodeTypeReference(ctd.Name);
            property.Statements.Add(new CodeMethodReturnStatement(new CodeThisReferenceExpression()));
            ctd.Members.Add(property);
        }