ardalis / ardalis/SmartEnum

Open to PR for additional doc examples?

Open
#162 1 comment 0 reactions 1 assignee Claimed by @pdevito3 View on GitHub
docs help wanted
Dominant language
C#
Stars
2.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

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:

```c#
public abstract class FeatureType : SmartEnum
{
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;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.