// Generated from executable documentation examples. Edit the source region, then regenerate. using System; using System.IO; using System.IO.Pipelines; using System.Linq; using System.Buffers; using System.Collections.Generic; using System.Dynamic; using System.Globalization; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using CStructSharp; using CStructSharp.Codecs; using CStructSharp.Diagnostics; using CStructSharp.Introspection; using CStructSharp.Values; internal static partial class Program { public static void Main() { MapPoco(); Console.WriteLine("PASS map-poco"); } private static void MapPoco() { var layout = new CStruct("struct point { int16 x; int16 y; };"); Point point = layout.ReadValue(new byte[] { 0xFE, 0xFF, 0x05, 0x00 }, "point"); Equal((short)-2, point.X); Equal((short)5, point.Y); } private static void Equal(T expected, T actual) { if (!EqualityComparer.Default.Equals(expected, actual)) { throw new InvalidOperationException($"Expected '{expected}', received '{actual}'."); } } public sealed class Point : ICStructMapped { public short X { get; set; } public short Y { get; set; } // The mapper names the layout members it reads; Get converts each one with range checks. public static Point ReadFrom(StructValue source) { return new Point { X = source.Get("x"), Y = source.Get("y") }; } public static void WriteTo(Point value, StructValue target) { target["x"] = value.X; target["y"] = value.Y; } // Runs before any other code in the assembly; the [CStructMapped] generator emits the same registration. [ModuleInitializer] internal static void Register() { MappedTypes.Register(); } } }