Skip to content

Commit 4df7c75

Browse files
authored
Update README.md
1 parent 5da0335 commit 4df7c75

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
Roslyn generator that automatically implements ReadOnly interfaces for annotated types.
1212

13+
## Background
14+
15+
I found myself really wanting to have IReadOnly versions of my types for type-safety, similar to what C# provides with IReadOnlyList, IReadOnlyDictionary, ReadOnlySpan, etc., and similar to what is possible in C++ with const. I started setting up these types manually, but this quickly grew out of hand and was hard to manage.
16+
17+
This library aims to provide this functionality without too much extra boilerplate.
18+
1319
## Usage
1420

1521
### Simple cases, purely read only
@@ -115,7 +121,7 @@ public partial interface IReadOnlyNode {
115121
}
116122
```
117123

118-
### Forcing mutability
124+
#### Forcing mutability
119125

120126
If you don't want a type to be swapped out for its IReadOnly counterpart, you can force it to be kept by annotating the type with `readOnly.KeepMutableTypeAttribute`:
121127

@@ -157,3 +163,25 @@ public partial interface IReadOnlyBar {
157163
void KeepInParam(Foo value);
158164
}
159165
```
166+
167+
### Inheritance
168+
169+
If a type with a read only interface inherits from another class with a read only interface, the read only interface will also automatically set up the same inheritance:
170+
171+
**User code:**
172+
```cs
173+
using readOnly;
174+
175+
[GenerateReadOnly]
176+
public partial class Parent;
177+
178+
[GenerateReadOnly]
179+
public partial class Child : Parent;
180+
```
181+
182+
**Generated code:**
183+
```cs
184+
public partial interface IReadOnlyParent;
185+
186+
public partial interface IReadOnlyChild : IReadOnlyParent;
187+
```

0 commit comments

Comments
 (0)