SmartEnum icon indicating copy to clipboard operation
SmartEnum copied to clipboard

Open to PR for additional doc examples?

Open pdevito3 opened this issue 4 years ago • 1 comments

Hey Steve, I just banged my head against the wall for several hours trying to get a consuming property to work for this. Wanted to double check if you were open to PRs expanding the docs in this case before i spent the time on it. See below for another example that could be added:

public abstract class FeatureType : SmartEnum<FeatureType>
{
    public static readonly FeatureType GetRecord = new GetRecordType();

    protected FeatureType(string name, int value) : base(name, value)
    {
    }
    public abstract string Url(string url = null);
    
    private class GetRecordType : FeatureType
    {
        public GetRecordType() : base(nameof(GetRecord), 1) {}

        public override string Url(string url = null)
            => url ?? "myurl";
    }
}

public class Feature
{
    private FeatureType _featureType { get; set; }
    public string Type
    {
        get => _featureType.Name;
        set
        {
            if (!FeatureType.TryFromName(value, true, out var parsed))
            {
                throw new Exception(value);
            }
            _featureType = parsed;
        }
    }

    private string _url = null;
    public string Url
    {
        get => _featureType.Url(_url);
        set => _url = value;
    }
}

pdevito3 avatar Aug 07 '21 18:08 pdevito3

Yes, please! Sorry your issue came through while I was on vacation. For now docs are pretty limited and probably best to just add into the README. It might be good in the future to do something like I've done with Ardalis.Specification:

https://ardalis.github.io/Specification/

using GitHub pages.

ardalis avatar Aug 18 '21 00:08 ardalis