RODL sample (.NET)
Overview
This sample demonstrates two things that could be useful for advanced developers:
- Parsing a RODL file and getting access to the RODL library object model
- Generating
Interface
,Invoker
andImplementation
code using the same facility as the Service Builder does internally.
Getting started
- Compile the project. It is a console application.
- Run the application with the RODL file name passed as a command-line parameter.
- The RODL file content is displayed on the console.
- Check the generated code.
Examine the code
- See how to get library elements in
Main.cs
file.
{
// ...
Console.WriteLine("Loading "+args[0]);
Console.WriteLine();
RodlLibrary lLibrary = new RodlLibrary(args[0]);
// ...
Console.WriteLine("Library "+lLibrary.Name);
Console.WriteLine(lLibrary.Structs.Count+" structs");
Console.WriteLine(lLibrary.Arrays.Count+" arrays");
// ...
foreach (RodlStruct s in lLibrary.Structs)
{
Console.WriteLine("Struct "+s.Name);
foreach (RodlField f in s)
{
Console.WriteLine(" Field "+f.Name+" datatype "+f.DataType);
}
Console.WriteLine();
}
// The same loops are for other RODL elements
// ...
}
- See how to generate code for the selected RODL library (
GenerateCode
function). Notice that it uses theCodeDomProvider
instance to generate the code in the concrete programming language.
// For C# use
// new Microsoft.CSharp.CSharpCodeProvider()
// call to obtain a CodeDomProvider instance
static void GenerateCode(RodlLibrary aLibrary, string aFilename, CodeDomProvider aProvider)
{
string lBase = Path.GetDirectoryName(aFilename);
string lNamespace = null;
if (aLibrary.Namespace == null || aLibrary.Namespace == "")
lNamespace = "Your.Namespace.Here";
// _Intf code generation
CodeGen.WriteToFile(
new CodeGen_Intf().GenerateCompileUnit(aLibrary, lNamespace, true),
aProvider,
Path.Combine(Path.GetDirectoryName(aFilename), aLibrary.Name+"_Intf."+aProvider.FileExtension));
// Use the same call to GenerateCompileUnit for invoker, events and services implementation.
// ...
}