Json TypeInfoResolver GetCustomAttribute returning wrong result

public void ModifyTypeInfo(JsonTypeInfo ti)
{
if (ti.Kind != JsonTypeInfoKind.Object) return;


for (var i = 0; i < ti.Properties.Count; i++)
{
var property = ti.Properties[i];
if (
property.PropertyType.GetCustomAttribute<IpcExposeAttribute>() is null // problem is here
)
{
ti.Properties.RemoveAt(i--);
}
}
}
public void ModifyTypeInfo(JsonTypeInfo ti)
{
if (ti.Kind != JsonTypeInfoKind.Object) return;


for (var i = 0; i < ti.Properties.Count; i++)
{
var property = ti.Properties[i];
if (
property.PropertyType.GetCustomAttribute<IpcExposeAttribute>() is null // problem is here
)
{
ti.Properties.RemoveAt(i--);
}
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Property)]
public class IpcExposeAttribute : Attribute
{
public string? InstanceName { get; }

public IpcExposeAttribute(string instanceName)
{
InstanceName = instanceName;
}

public IpcExposeAttribute()
{
InstanceName = null;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Property)]
public class IpcExposeAttribute : Attribute
{
public string? InstanceName { get; }

public IpcExposeAttribute(string instanceName)
{
InstanceName = instanceName;
}

public IpcExposeAttribute()
{
InstanceName = null;
}
}
class Item(int id, string name)
{
[IpcExpose] public int Id2 { get; set; } = id;

public string Name2 { get; set; } = name;
}
class Item(int id, string name)
{
[IpcExpose] public int Id2 { get; set; } = id;

public string Name2 { get; set; } = name;
}
After checking with debugger, property.PropertyType.GetCustomAttribute<IpcExposeAttribute>() is null is always true (which results into empty serialization) I've tried doing a property.PropertyType.GetCustomAttributes() and it returns 6 attributes (SerializableAttribute, NullableContextAttribute, NullableAttribute, DefaultMemberAttribute, NonVersionableAttribute, TypeForwardedFromAttribute), but no signs of my custom attribute. Even passing true (although inheritance shouldn't matter in this case) in the GetCustomAttributes, results to no change whatsoever.
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server