kalten
kalten
CC#
Created by kalten on 9/9/2024 in #help
Support generic method NativeAOT JsonTypedInfo all together
Using a Utf8JsonReader seem to work too
private T GetAA<T>(JsonTypeInfo<T> jTypeInfo)
{
string json = "{\"Data\": {\"Name\":\"World\", \"Id\":2 }}";
Utf8JsonReader reader = new(Encoding.UTF8.GetBytes(json));
reader.Read();
reader.Read();

var propertyName = reader.GetString();
if (propertyName != nameof(ModelA.Data))
throw new Exception("Invalid property name");

reader.Read();

var data = JsonSerializer.Deserialize<T>(ref reader, jTypeInfo);

return data;
}
private T GetAA<T>(JsonTypeInfo<T> jTypeInfo)
{
string json = "{\"Data\": {\"Name\":\"World\", \"Id\":2 }}";
Utf8JsonReader reader = new(Encoding.UTF8.GetBytes(json));
reader.Read();
reader.Read();

var propertyName = reader.GetString();
if (propertyName != nameof(ModelA.Data))
throw new Exception("Invalid property name");

reader.Read();

var data = JsonSerializer.Deserialize<T>(ref reader, jTypeInfo);

return data;
}
But Utf8JsonReader is not usable in an async context
3 replies
CC#
Created by kalten on 9/9/2024 in #help
Support generic method NativeAOT JsonTypedInfo all together
I found a solution by using a temporary JsonElement type
private T GetB<T>(JsonTypeInfo<T> jTypeInfo)
{
string json = "{\"Data\": {\"Name\":\"World\", \"Id\":2 }}";
JsonElement r = JsonSerializer.Deserialize(json, LibJsonContext.Default.ModelBT)!.Data;
return SerializeUserModel<T>(r, jTypeInfo)!;
}

private T SerializeUserModel<T>(JsonElement jElement, JsonTypeInfo<T> jTypeInfo)
{
return jElement.Deserialize<T>(jTypeInfo)!;
}
private T GetB<T>(JsonTypeInfo<T> jTypeInfo)
{
string json = "{\"Data\": {\"Name\":\"World\", \"Id\":2 }}";
JsonElement r = JsonSerializer.Deserialize(json, LibJsonContext.Default.ModelBT)!.Data;
return SerializeUserModel<T>(r, jTypeInfo)!;
}

private T SerializeUserModel<T>(JsonElement jElement, JsonTypeInfo<T> jTypeInfo)
{
return jElement.Deserialize<T>(jTypeInfo)!;
}
But not sure about the efficiency of it
3 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
Just to let you know, I published the code as a gist here https://gist.github.com/latop2604/73bd7d8008e7ed925f5713fda9201ced
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
AOT work like a charm
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I need to leave, 4am here. And I still need to go to work. Have a good night (or day)
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
and lot of polish
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I still neet to check is still work with AOT
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I hope one day I will have the same level of knowledge as you. I'm feeling so dumb next to you (even with my 10y of xp in dotnet)
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I really want to say thank you very much
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I would never be able to find all of that by myself
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
What a ride!
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
No description
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
no error
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
I end up with
using VARTYPE = System.Runtime.InteropServices.VarEnum;
///...
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct PROPVARIANT
{
/// <summary>Value type tag.</summary>
[FieldOffset(0)] public VARTYPE vt;

/// <summary>Reserved for future use.</summary>
[FieldOffset(2)] public ushort wReserved1;

/// <summary>Reserved for future use.</summary>
[FieldOffset(4)] public ushort wReserved2;

/// <summary>Reserved for future use.</summary>
[FieldOffset(6)] public ushort wReserved3;

/// <summary>The decimal value when VT_DECIMAL.</summary>
[FieldOffset(0)] internal decimal _decimal;

/// <summary>The raw data pointer.</summary>
[FieldOffset(8)] internal IntPtr _ptr;

/// <summary>The FILETIME when VT_FILETIME.</summary>
[FieldOffset(8)] internal System.Runtime.InteropServices.ComTypes.FILETIME _ft;

/// <summary>The BLOB when VT_BLOB</summary>
[FieldOffset(8)] internal Vanara.PInvoke.Ole32.BLOB _blob;

/// <summary>The value when a numeric value less than 8 bytes.</summary>
[FieldOffset(8)] internal ulong _ulong;

/// <summary>Initializes a new instance of the <see cref="PROPVARIANT"/> class as VT_EMPTY.</summary>
public PROPVARIANT()
{

}
public PROPVARIANT(string value)
{
ArgumentNullException.ThrowIfNull(value);
vt = VarEnum.VT_LPWSTR;
_ptr = Marshal.StringToCoTaskMemUni(value);
}

public VarEnum VarType { get => (VarEnum)vt; set => vt = (VARTYPE)value; }
}
using VARTYPE = System.Runtime.InteropServices.VarEnum;
///...
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct PROPVARIANT
{
/// <summary>Value type tag.</summary>
[FieldOffset(0)] public VARTYPE vt;

/// <summary>Reserved for future use.</summary>
[FieldOffset(2)] public ushort wReserved1;

/// <summary>Reserved for future use.</summary>
[FieldOffset(4)] public ushort wReserved2;

/// <summary>Reserved for future use.</summary>
[FieldOffset(6)] public ushort wReserved3;

/// <summary>The decimal value when VT_DECIMAL.</summary>
[FieldOffset(0)] internal decimal _decimal;

/// <summary>The raw data pointer.</summary>
[FieldOffset(8)] internal IntPtr _ptr;

/// <summary>The FILETIME when VT_FILETIME.</summary>
[FieldOffset(8)] internal System.Runtime.InteropServices.ComTypes.FILETIME _ft;

/// <summary>The BLOB when VT_BLOB</summary>
[FieldOffset(8)] internal Vanara.PInvoke.Ole32.BLOB _blob;

/// <summary>The value when a numeric value less than 8 bytes.</summary>
[FieldOffset(8)] internal ulong _ulong;

/// <summary>Initializes a new instance of the <see cref="PROPVARIANT"/> class as VT_EMPTY.</summary>
public PROPVARIANT()
{

}
public PROPVARIANT(string value)
{
ArgumentNullException.ThrowIfNull(value);
vt = VarEnum.VT_LPWSTR;
_ptr = Marshal.StringToCoTaskMemUni(value);
}

public VarEnum VarType { get => (VarEnum)vt; set => vt = (VARTYPE)value; }
}
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
The PROPVARIANT class from vanara is pretty huge
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
[In, Out]
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
No description
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
Better yes
140 replies
CC#
Created by kalten on 2/13/2024 in #help
JumpList PublishAOT
Ah yes
140 replies