C
C#14mo ago
SWEETPONY

❔ ✅ How to get true properties from object?

I have following object:
public class AccessGroupRulesDto
{
[JsonProperty( PropertyName = "allow_access_when_blocked" )]
public bool AllowAccessWhenBlocked { get; set; }

[JsonProperty( PropertyName = "allow_access_on_antipassback" )]
public bool AllowAccessOnAntipassback { get; set; }

[JsonProperty( PropertyName = "allow_exit_out_of_schedule_access" )]
public bool AllowExitOutOfScheduleAccess { get; set; }

[JsonProperty( PropertyName = "allow_entry_out_of_schedule_access" )]
public bool AllowEntryOutOfScheduleAccess { get; set; }

[JsonProperty( PropertyName = "allow_access_by_one_factor" )]
public bool AllowAccessByOneFactor { get; set; }

[JsonProperty( PropertyName = "allow_turning_off_sound_open_door" )]
public bool AllowTurningOffSoundOpenDoor { get; set; }

[JsonProperty( PropertyName = "guest_access" )]
public bool GuestAccess { get; set; }

[JsonProperty( PropertyName = "guard_control" )]
public bool GuardControl { get; set; }

[JsonProperty( PropertyName = "alarm_remove" )]
public bool AlarmRemove { get; set; }

[JsonProperty( PropertyName = "group_access_mode" )]
public GroupAccessMode GroupAccessMode { get; set; }
}
public class AccessGroupRulesDto
{
[JsonProperty( PropertyName = "allow_access_when_blocked" )]
public bool AllowAccessWhenBlocked { get; set; }

[JsonProperty( PropertyName = "allow_access_on_antipassback" )]
public bool AllowAccessOnAntipassback { get; set; }

[JsonProperty( PropertyName = "allow_exit_out_of_schedule_access" )]
public bool AllowExitOutOfScheduleAccess { get; set; }

[JsonProperty( PropertyName = "allow_entry_out_of_schedule_access" )]
public bool AllowEntryOutOfScheduleAccess { get; set; }

[JsonProperty( PropertyName = "allow_access_by_one_factor" )]
public bool AllowAccessByOneFactor { get; set; }

[JsonProperty( PropertyName = "allow_turning_off_sound_open_door" )]
public bool AllowTurningOffSoundOpenDoor { get; set; }

[JsonProperty( PropertyName = "guest_access" )]
public bool GuestAccess { get; set; }

[JsonProperty( PropertyName = "guard_control" )]
public bool GuardControl { get; set; }

[JsonProperty( PropertyName = "alarm_remove" )]
public bool AlarmRemove { get; set; }

[JsonProperty( PropertyName = "group_access_mode" )]
public GroupAccessMode GroupAccessMode { get; set; }
}
I'd like to return all properties where bool is not false how can I do it?
5 Replies
SWEETPONY
SWEETPONY14mo ago
I can do smth like.. rules.ToJsonString(true); and it will return all jsonpropertynames with their values but I need only true values
Sossenbinder
Sossenbinder14mo ago
I guess your options are to either write something to filter this property by property yourself Or use reflection
JakenVeina
JakenVeina14mo ago
what would you expect the return to look like?
SWEETPONY
SWEETPONY14mo ago
thanks for helping
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.