genxs(1)
β¨ genxs β Mono's Xml Serializer Generator β¨
bestie, welcome to the genxs(1) page from the General Commands Manual. this is the whole thing, every last flag and <hook>, just with, like, a personality now π
π NAME
genxs β Mono's Xml Serializer Generator. that's it, that's the name, and honestly? iconic.
π SYNOPSIS
genxs configurationFile [destinationFolder]
two args, one optional, we move π«Ά
πΈ DESCRIPTION
okay so genxs is a tool for generating custom XML serialization writers and readers for classes. it writes the boring serialization code so you don't have to, no cap.
configurationFile is the configuration file which specifies several information, such as the class for which to generate the reader and writer, the name and namespace of the classes to generate, and a collection of hooks to apply. and here's the slay part: by using hooks it is possible to customize the behavior of the serializer without needing to modify the generated file, so you can safely regenerate it if the source class is modified. regenerating without fear? that's the dream fr fr.
destinationFolder specifies the folder where the files will be generated. like, where the magic lands on disk π¦
β οΈ NOTE: This tool only runs in the Mono runtime, since it uses some internal classes not available in other runtimes. so if you're on some other runtime, it's giving "not today" β this is a Mono-only situation, periodt.
π CONFIGURATION FILE FORMAT
the configuration file is an xml document based on the following grammar (? means optional, * means 0 or more):
<configuration>
<serializer class="name" assembly="name"> *
<reader>name</reader> ?
<writer>name</writer> ?
<namespace>name</namespace> ?
<outFileName>name</outFileName> ?
<readerHooks> ?
<hook ...> *
</readerHooks>
<writerHooks> ?
<hook ...> *
</writerHooks>
</serializer>
</configuration>
a configuration file can have multiple serializer elements, each of which specifies the class for which to generate a serializer together with several generation options. so like, one file, many serializers, we contain multitudes β¨
the source class is specified in the following attributes:
classβ name of the class (including namespace).assemblyβ assembly name. It can include the complete path.
generation options are specified in child elements:
readerβ name of the reader class.noReaderβ if"true", it does not generate reader class.writerβ name of the writer class.baseSerializerβ name of the base xml serializer class. This item is 2.0 only.implementationβ name of the serializer implementation class. This item is 2.0 only.noWriterβ if"true", it does not generate writer class.namespaceβ namespace of the reader and writer classes.generateAsInternalβ if"true", it generates classes as internal.outFileNameβ name of the generated file.readerHooksβ a list of hooks to apply to the reader.writerHooksβ a list of hooks to apply to the writer.
πͺ SPECIFYING HOOKS
using hooks you can customize the behavior of readers and writers. the hook is literally the main character of this whole page, iykyk. a hook specification follows this grammar:
<hook type="name">
<select> ?
<typeName>name</typeName> ?
<typeAttribute>name</typeAttribute> *
<typeMember>name</typeMember> ?
</select>
<replace>source code</replace> ?
<insertBefore>source code</insertBefore> ?
<insertAfter>source code</insertAfter> ?
</hook>
the type attribute specifies the context in which the hook is applied. It can be one of the following:
attributesβ hook is applied where attributes are serialized/deserialized.elementsβ hook is applied where elements are serialized/deserialized.unknownAttributeβ hook is applied where unknown attributes are processed.unknownElementβ hook is applied where unknown elements are processed.memberβ hook is applied where a member is serialized/deserialized.typeβ hook is applied for the whole type.
the select element specifies the classes and members to which the hook has to be added. it can contain the following elements:
typeNameβ the class with that name will be selected (must include namespace).typeAttributeβ all classes which have that attribute applied will be selected (specify the full attribute class name, including namespace). Several attribute names can be specified.typeMemberβ name of the class member for which the hook must be added.
the hook source code can be specified using any of the following elements:
replaceβ the provided source code will replace all serialization/deserialization operations in the hook context.insertBeforeβ the source code will be added before the hook context.insertAfterβ the source code will be added after the hook context.
when writing the code for a hook you can use some special variables that are defined during the code generation process. the variables are the following:
$TYPEβ name of the class being generated, without namespace.$FULLTYPEβ full name of the class being generated, including namespace.$OBJECTβ the object being serialized or deserialized. When using a replace reader hook of type"type", the hook code must assign the deserialized object to this variable. (yes bestie, must. that's not a suggestion, that's the assignment π )-I $ELEMENTβ name of the element of the object being serialized/deserialized. (and yes, the-Iis literally just sitting there in the original page, we are keeping it exactly as-is, no touchy π)$NAMESPACEβ namespace of the element of the object being serialized/deserialized.$MEMBERβ name of the member being serialized/deserialized. Only valid in the"member"context.
π HOOK EXAMPLES
the following example adds a call to a Validate method after the deserialization of any object:
<hook type="type">
<insertAfter>
System.Xml.Schema.XmlSchema.Validate$TYPE ($OBJECT);
</insertAfter>
</hook>
this example specifies the code to be used to deserialize the XmlSchema class:
<hook type="type">
<select>
<typeName>System.Xml.Schema.XmlSchema</typeName>
</select>
<replace>
$OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null);
</replace>
</hook>
that one specifies the code to be used to read XmlSchema instances:
<hook type="type">
<select>
<typeName>System.Xml.Schema.XmlSchema</typeName>
</select>
<replace>$OBJECT.Write (Writer);</replace>
</hook>
with this two hooks the serializer will print some information when serializing the class "MyClass":
<hook type="type">
<select>
<typeName>MyNamespace.MyClass</typeName>
</select>
<insertBefore>Console.WriteLine ("Serializing MyClass");</replace>
<insertAfter>Console.WriteLine ("MyClass serialized");</insertAfter>
</hook>
<hook type="member">
<select>
<typeName>MyNamespace.MyClass</typeName>
</select>
<insertAfter>
Console.WriteLine ("Serialized member $MEMBER");
</insertAfter>
</hook>
π«Ά okay real talk: that</replace>on theinsertBeforeline? that's exactly how it's written on the page. we are not fixing it, we are not touching it, we are copying it character for character. it's part of the lore now.
this hook writes an additional element for all types that have the custom attribute "MyAttribute":
<hook type="elements">
<select>
<typeAttribute>MyNamespace.MyAttribute</typeAttribute>
</select>
<insertAfter>
Writer.WriteStartElement ("privateData");
Writer.WriteString ($OBJECT.PrivateData);
Writer.WriteEndElement ();
</insertAfter>
</hook>
π CONFIGURATION FILE EXAMPLE
this is the configuration file used to generate the serializer for ServiceDescription β the full real deal, not a snippet, keep every line bestie:
<configuration>
<serializer class="System.Web.Services.Description.ServiceDescription" assembly="System.Web.Services">
<reader>ServiceDescriptionReaderBase</reader>
<writer>ServiceDescriptionWriterBase</writer>
<namespace>System.Web.Services.Description</namespace>
<outFileName>ServiceDescriptionSerializerBase.cs</outFileName>
<readerHooks>
<hook type="unknownElement">
<select>
<typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute>
</select>
<replace>ServiceDescription.ReadExtension (Reader, $OBJECT);</replace>
</hook>
<hook type="type">
<select>
<typeName>System.Xml.Schema.XmlSchema</typeName>
</select>
<replace>$OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null);</replace>
</hook>
</readerHooks>
<writerHooks>
<hook type="elements">
<select>
<typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute>
</select>
<insertBefore>ServiceDescription.WriteExtensions (Writer, $OBJECT);</insertBefore>
</hook>
<hook type="type">
<select>
<typeName>System.Xml.Schema.XmlSchema</typeName>
</select>
<replace>$OBJECT.Write (Writer);</replace>
</hook>
</writerHooks>
</serializer>
</configuration>
π AUTHORS
Lluis Sanchez Gual (lluis@ximian.com) β the actual author, giving us this whole tool, we say thank you π«‘
π LICENSE
GenXS is released under the terms of the GNU GPL. that's the license, respect it π
π SEE ALSO
and that's the whole page bestie, from genxs(1) at the top to genxs(1) at the bottom π no cap, every single detail is still in there, we just made it cute. go generate some serializers, you're gonna eat πΈβ¨
π¦ where this page comes from
- alpine 3.24: mono-doc 6.14.1-r1 Β· MIT
- arch rolling: mono 6.12.0.206-1 Β· GPL AND LGPL2.1 AND MPL
- debian bookworm: mono-devel 6.8.0.105+dfsg-3.3+deb12u1 Β· MIT
- debian trixie: mono-devel 6.12.0.199+dfsg-6 Β· MIT
- epel 10: mono-devel 6.14.1-1.el10_2 Β· MIT
- epel 9: mono-devel 6.12.0-5.el9 Β· MIT
- fedora 43: mono-devel 6.12.0-21.fc43 Β· MIT
- fedora 43: mono-devel 6.12.0-21.fc43 Β· MIT
- fedora 44: mono-devel 6.14.1-3.fc44 Β· MIT
- fedora 44: mono-devel 6.14.1-3.fc44 Β· MIT
- fedora 44: mono-devel 6.14.1-4.fc44 Β· MIT
- fedora 44: mono-devel 6.14.1-4.fc44 Β· MIT
- nixos 26.05: mono 6.14.1
- nixpkgs unstable: mono 6.14.1
- opensuse-leap 16.0: mono-devel 6.12.0-bp160.1.1 Β· LGPL-2.1-only
- opensuse-leap 16.0: mono-devel 6.12.0-bp160.1.1 Β· LGPL-2.1-only
- opensuse-leap 16.0: mono-devel 6.12.0-bp160.1.1 Β· LGPL-2.1-only
- opensuse-leap 16.0: mono-devel 6.12.0-bp160.1.1 Β· LGPL-2.1-only
- ubuntu jammy: mono-devel 6.8.0.105+dfsg-3.2 Β· MIT
- ubuntu noble: mono-devel 6.8.0.105+dfsg-3.6ubuntu2 Β· MIT
- ubuntu questing: mono-devel 6.12.0.199+dfsg-6
- ubuntu resolute: mono-devel 6.14.1+ds2-2 Β· MIT
- ubuntu stonking: mono-devel 6.14.1+ds2-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms