Serializing an OutSystems Record abstracting Integration API's

Serializing an OutSystems Record abstracting Integration API's

  
Hi all,

I had some requests about generalizing integration API's when using different Records or RecordLists.

As you may know, OutSystems data type system is strongly typed to ensure automated refactoring in case of modification and enhance consistency checking during "Verify".

In order to abstract and generalize the use of generic Records from your Extensions or even Service Studio, I wrote an Extension that transforms a Record of a given compound data type (either based on a single Structure or a single Entity).

The extension uses .NET's System.Reflection to retrieve metadata about any generic record and transforms it into a [Name, Value] pair. Here goes the code sample for the SerializeRecord method:

public void MssSerializeRecord ( System.Object ssrecord, out OutSystems.NssSerializer.RLRecordItemRecordList ssserializedRecord) {

ssserializedRecord = new RLRecordItemRecordList();

// Gets the data structure inside the generic Record in ssrecord
object structure = ssrecord.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)[0].GetValue(ssrecord);
// Gets the fields of the record structure
FieldInfo[] structAttrs = structure.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);

// Iterates each of the fields and dumps the name and value for each of them
for (int iAttr = 0; iAttr < structAttrs.Length; iAttr++) {
RCRecordItemRecord recItem = new RCRecordItemRecord();
recItem.ssSTRecordItem.ssName = structAttrs[iAttr].Name.Substring(2);
recItem.ssSTRecordItem.ssValue = structAttrs[iAttr].GetValue(structure).ToString();
ssserializedRecord.Append(recItem);
}
}

The Extension and a Sample eSpace (for version 3.1) that illustrates the behavior is available in attachment.
Now, with eSpace Sample too!