diff --git a/Example.Backend/Printer.cs b/Example.Backend/Printer.cs index 78bac1c..85bd58a 100644 --- a/Example.Backend/Printer.cs +++ b/Example.Backend/Printer.cs @@ -10,7 +10,7 @@ namespace Example.Backend { public string Name; - public decimal Resource { get; set; } + public double Resource { get; set; } = 100d; public string GetName() { @@ -22,6 +22,7 @@ namespace Example.Backend // throw new Exception("The method or operation is not implemented."); var page = new Page { Text = text }; OnPrint?.Invoke(page); + Resource /= 1.5; return page; } diff --git a/Example.Frontend/ClientBasedPrinter.cs b/Example.Frontend/ClientBasedPrinter.cs index 754973c..4c9bea7 100644 --- a/Example.Frontend/ClientBasedPrinter.cs +++ b/Example.Frontend/ClientBasedPrinter.cs @@ -8,7 +8,7 @@ namespace Example.Frontend { public class ClientBasedPrinter : IPrinter { - public decimal Resource { get; set; } + public double Resource { get; set; } public string GetName() { diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index fdab3b8..07fa4ab 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -75,6 +75,12 @@ class Program var page = disposingPrinter.Print("Test Page", false, CancellationToken.None).GetAwaiter().GetResult(); Console.WriteLine("Page printed"); Console.WriteLine(page.ToString()); + + Console.WriteLine($"Printer resource : {disposingPrinter.Resource}"); + Console.WriteLine("Restoring resource"); + disposingPrinter.Resource = 100; + Console.WriteLine($"Printer resource again : {disposingPrinter.Resource}"); + var data = page.GetData(); Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data)); diff --git a/Example.Shared/IPrinter.cs b/Example.Shared/IPrinter.cs index c1743db..a94aae4 100644 --- a/Example.Shared/IPrinter.cs +++ b/Example.Shared/IPrinter.cs @@ -9,7 +9,7 @@ namespace Example.Shared [SharedObjectInterface] public interface IPrinter : IDisposable, IShared { - decimal Resource { get; set; } + double Resource { get; set; } string GetName(); Task Print(string text, bool someParameter, CancellationToken cancellationToken); event Action OnPrint; diff --git a/mROA.Cbor/CborSerializationToolkit.cs b/mROA.Cbor/CborSerializationToolkit.cs index 847f2cc..12016df 100644 --- a/mROA.Cbor/CborSerializationToolkit.cs +++ b/mROA.Cbor/CborSerializationToolkit.cs @@ -56,13 +56,13 @@ namespace mROA.Cbor { if (nonCasted == null) return null; - + if (nonCasted.GetType() == type) return nonCasted; if (nonCasted is PreParsedValue preParsed) return preParsed.ToObject(type, context); - return null; + return Convert.ChangeType(nonCasted, type); } private void WriteData(object? obj, CborWriter writer, IEndPointContext? context) @@ -214,6 +214,9 @@ namespace mROA.Cbor return reader.ReadDouble(); case CborReaderState.SinglePrecisionFloat: return reader.ReadSingle(); + case CborReaderState.HalfPrecisionFloat: + return type == typeof(float) ? reader.ReadSingle() : reader.ReadDouble(); + case CborReaderState.StartArray: if (type == null) return ReadList(reader, null, context); @@ -308,7 +311,6 @@ namespace mROA.Cbor if (type.IsInterface) { - var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(type); var so = Activator.CreateInstance(sharedShell) as diff --git a/mROA.Codegen/mROASourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs index 469023e..44217d5 100644 --- a/mROA.Codegen/mROASourceGenerator.cs +++ b/mROA.Codegen/mROASourceGenerator.cs @@ -436,6 +436,7 @@ namespace mROA.Codegen {level}{{ {level} IsVoid = false, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), +{level} ParameterTypes = new Type[] {{ typeof({method.Parameters.First().Type.ToDisplayString()}) }}, {level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), {level} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name} = {Caster((method.AssociatedSymbol as IPropertySymbol)!.Type, "parameters[0]")}, {level}}}";