コード例 #1
0
ファイル: Config.cs プロジェクト: KuroiLight/SlideSharp
 public static bool ReadFromDisk()
 {
     try
     {
         using (FileStream fs = new(_filename, FileMode.Open))
         {
             byte[] rawData = new byte[fs.Length];
             var    nBytes  = fs.Read(rawData, 0, (int)fs.Length);
             if (nBytes == 0)
             {
                 return(false);
             }
             var deserializedObject = TinyhandSerializer.Deserialize <Config>(rawData);
             if (deserializedObject is null)
             {
                 return(false);
             }
             _instance = deserializedObject;
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: archi-Doc/Tinyhand
    static void Main(string[] args)
    {
        // TinyhandModule_ConsoleApp1.Initialize(); // Initialize() method is required on some platforms (e.g Xamarin, Native AOT) which does not support ModuleInitializer attribute.

        var myClass = new MyClass()
        {
            Age = 10, FirstName = "hoge", LastName = "huga",
        };
        var b        = TinyhandSerializer.Serialize(myClass);
        var myClass2 = TinyhandSerializer.Deserialize <MyClass>(b);

        b = TinyhandSerializer.Serialize(new EmptyClass());            // Empty data
        var myClass3 = TinyhandSerializer.Deserialize <MyClass>(b);    // Create an instance and set non-null values of the members.

        var myClassRecon = TinyhandSerializer.Reconstruct <MyClass>(); // Create a new instance whose members have default values.
    }
コード例 #3
0
    public IdentifierReadonlyStruct SerializeDeserializeReadonlyStruct()
    {
        var t = new IdentifierReadonlyStruct(1234, 5678, 9101112, 13141516);

        return(TinyhandSerializer.Deserialize <IdentifierReadonlyStruct>(TinyhandSerializer.Serialize(t)));
    }
コード例 #4
0
    public IdentifierClass?SerializeDeserializeClass()
    {
        var t = new IdentifierClass(1234, 5678, 9101112, 13141516);

        return(TinyhandSerializer.Deserialize <IdentifierClass>(TinyhandSerializer.Serialize(t)));
    }
コード例 #5
0
 public Decimal DeserializeDecimal_TinyhandSerializer() => TinyhandSerializer.Deserialize <Decimal>(this.NativeDecimalByte);
コード例 #6
0
 public Guid DeserializeGuid_TinyhandSerializer() => TinyhandSerializer.Deserialize <Guid>(this.NativeGuidByte);