예제 #1
0
 //Todo: Enumerate all base calsses, extracting out their ResourceType to generate a "fall-back" array for the "rt" property
 public byte[] Serialise(IOicSerialisableResource resource, OicMessageContentType contentType)
 {
     using (var writer = new MemoryStream())
     {
         Serialise(writer, resource, contentType);
         return(writer.ToArray());
     }
 }
예제 #2
0
        //Todo: Enumerate all base calsses, extracting out their ResourceType to generate a "fall-back" array for the "rt" property
        public void Serialise(Stream stream, IOicSerialisableResource resource, OicMessageContentType contentType)
        {
            switch (contentType)
            {
            case OicMessageContentType.ApplicationJson:
                StreamWriter sw = new StreamWriter(stream);
                JsonSerializer.CreateDefault().Serialize(sw, resource);
                sw.Flush();
                break;

            case OicMessageContentType.ApplicationCbor:
                new JsonSerializer().Serialize(new CborDataWriter(stream), resource);
                break;

            default:
                throw new NotImplementedException($"Can not serialise unsupported content type ({contentType:G})");
            }
            stream.Flush();
        }