You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you please provide assistance with a use case we are facing?
We are currently exploring ways to avoid defining all deriving classes of a smart enum as static properties, as we are concerned about the potential for creating invalid states.
Specifically, we have two types: Offers and AcceptedOffers. In order to obtain an AcceptedOffer, one must first accept an Offer using the Accept() method. Our objective is to ensure that creating AcceptedOffers through any other means is not possible.
However this does not work when using the entity framwork because that relies on having a static property available for loading.
Is it feasible to modify the functionality of ConfigureSmartEnum() so that it can also discover private properties? Perhaps by introducing a modifier in an overload to maintain backward compatibility?
Alternatively, do smart enums offer an option to utilize reflection and list all derived classes in the assembly?
Would you be open to accepting pull requests if we were to implement any of these ideas?
Here's an example that showcases our use case:
publicabstractclassDokumenttyp:SmartEnum<Dokumenttyp>{publicstaticreadonlyDokumenttypOffers=new Offers();// TODO: We want to be able to remove this static propertypublicstaticreadonlyDokumenttypAcceptedOffer=new AcceptedOffer();protectedDokumenttyp(stringname,intvalue):base(name, value){}publicboolCanBeAccepted{get;protectedinit;}publicboolIsPublished{get;protectedset;}publicboolCanBePublished{get;protectedset;}publicabstractResult<Dokumenttyp>Accept();publicabstractResult<Dokumenttyp>Publish();}
internalclassOffer:Dokumenttyp{internalOffer():base("Offer",1){CanBeAccepted=true;CanBePublished=false;IsPublished=false;}publicoverrideResult<Dokumenttyp>Accept(){return Result
.Success<Dokumenttyp>(new AcceptedOffer());}publicoverrideResult<Dokumenttyp>Publish(){return Result.Failure<Dokumenttyp>("Please first accept the offer");}}
internalclassAcceptedOffer:Dokumenttyp{internalAcceptedOffer():base("AcceptedOffer",2){CanBeAccepted=false;CanBePublished=true;IsPublished=false;}publicoverrideResult<Dokumenttyp>Accept(){return Result.Failure<Dokumenttyp>("The original offer has already been accepted");}publicoverrideResult<Dokumenttyp>Publish(){CanBePublished=false;IsPublished=true;returnthis;}}
The text was updated successfully, but these errors were encountered:
Could you please provide assistance with a use case we are facing?
We are currently exploring ways to avoid defining all deriving classes of a smart enum as static properties, as we are concerned about the potential for creating invalid states.
Specifically, we have two types:
Offers
andAcceptedOffers
. In order to obtain anAcceptedOffer
, one must first accept anOffer
using theAccept()
method. Our objective is to ensure that creatingAcceptedOffers
through any other means is not possible.However this does not work when using the entity framwork because that relies on having a static property available for loading.
Is it feasible to modify the functionality of
ConfigureSmartEnum()
so that it can also discover private properties? Perhaps by introducing a modifier in an overload to maintain backward compatibility?Alternatively, do smart enums offer an option to utilize reflection and list all derived classes in the assembly?
Would you be open to accepting pull requests if we were to implement any of these ideas?
Here's an example that showcases our use case:
The text was updated successfully, but these errors were encountered: