Skip to content

Commit 5135601

Browse files
committed
Simplified readme
1 parent b7baada commit 5135601

27 files changed

+722
-531
lines changed

AutoCtor.slnx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<File Path=".github/workflows/publish.yml" />
1616
</Folder>
1717
<Project Path="src/AutoCtor.Attributes/AutoCtor.Attributes.csproj" />
18-
<Project Path="src/AutoCtor.Example/AutoCtor.Example.csproj" />
1918
<Project Path="src/AutoCtor.Roslyn3.11/AutoCtor.Roslyn3.11.csproj" />
2019
<Project Path="src/AutoCtor.Roslyn4.0/AutoCtor.Roslyn4.0.csproj" />
2120
<Project Path="src/AutoCtor.Roslyn4.4/AutoCtor.Roslyn4.4.csproj" />

readme.md

Lines changed: 345 additions & 173 deletions
Large diffs are not rendered by default.

readme.source.md

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,77 @@ toc
4444

4545
https://nuget.org/packages/AutoCtor/
4646

47-
## Usage
47+
## Examples
4848

49-
### Your code
49+
### Basic
5050

5151
snippet: Basic
5252

53-
### What gets generated
53+
<details><summary>What gets generated</summary>
5454

55-
snippet: BasicGeneratedCode
55+
snippet: Basic.ExamplesGeneratedCode#Basic.g.verified.cs
5656

57-
<a href='#toc' title='Back to Contents'>Back to Contents</a>
58-
## More Features
57+
</details>
58+
59+
### Inherited
60+
61+
snippet: Inherited
62+
63+
<details><summary>What gets generated</summary>
64+
65+
snippet: Inherited.ExamplesGeneratedCode#Inherited.g.verified.cs
66+
67+
</details>
68+
69+
### Properties
5970

60-
### Post constructor Initialisation
71+
snippet: Properties
72+
73+
<details><summary>What gets generated</summary>
74+
75+
snippet: Properties.ExamplesGeneratedCode#Properties.g.verified.cs
76+
77+
</details>
78+
79+
<a href='#toc' title='Back to Contents'>Back to Contents</a>
80+
## Post Constructor Initialization
6181

6282
You can mark a method to be called at the end of the constructor with the attribute `[AutoPostConstruct]`. This method must return void.
6383

6484
snippet: PostConstruct
6585

66-
snippet: PostConstructGeneratedCode
86+
<details><summary>What gets generated</summary>
6787

68-
### Keyed Services
88+
snippet: PostConstruct.ExamplesGeneratedCode#PostConstruct.g.verified.cs
6989

70-
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[AutoKeyedService]` and it will be included in the constructor.
90+
</details>
91+
92+
### Extra Parameters
7193

72-
snippet: KeyedService
94+
Post construct methods can also take parameters. The generated constructor will include these parameters.
7395

74-
snippet: KeyedServiceGeneratedCode
96+
snippet: PostConstructWithParameter
7597

76-
### Initialize with parameters
98+
<details><summary>What gets generated</summary>
7799

78-
Post constructor methods can also take parameters. These parameters will be passed in from the constructor.
100+
snippet: PostConstructWithParameter.ExamplesGeneratedCode#PostConstructWithParameter.g.verified.cs
79101

80-
snippet: PostConstructWithParameters
102+
</details>
81103

82-
snippet: PostConstructWithParametersGeneratedCode
104+
### `out`/`ref` Parameters
83105

84-
### Initialize readonly fields with ref or out
106+
Parameters marked with `out` or `ref` are set back to any fields that match the same type. This can be used to set readonly fields with more complex logic.
85107

86-
If a parameter is marked `ref` or `out` and matches the type of a readonly field, it can set that field during construction.
108+
snippet: PostConstructWithOutParameter
87109

88-
snippet: PostConstructWithOutParameters
110+
<details><summary>What gets generated</summary>
89111

90-
snippet: PostConstructWithOutParametersGeneratedCode
112+
snippet: PostConstructWithOutParameter.ExamplesGeneratedCode#PostConstructWithOutParameter.g.verified.cs
91113

92-
### Argument Guards
114+
</details>
115+
116+
<a href='#toc' title='Back to Contents'>Back to Contents</a>
117+
## Argument Guards
93118

94119
Null guards for the arguments to the constructor can be added in 2 ways.
95120

@@ -105,39 +130,39 @@ In your project you can add a `AutoCtorGuards` property.
105130
</Project>
106131
```
107132

108-
In each `AutoConstruct` attribute you can add a setting to enable/disable guards.
133+
**OR**
109134

110-
snippet: Guards
135+
In each `AutoConstruct` attribute you can add a setting to enable/disable guards.
111136

112-
snippet: GuardsGeneratedCode
137+
snippet: Guarded
113138

114-
### Property Initialisation
139+
<details><summary>What gets generated</summary>
115140

116-
AutoCtor can set properties that are considered as read only properties.
141+
snippet: Guarded.ExamplesGeneratedCode#Guarded.g.verified.cs
117142

118-
snippet: PropertyExamples
143+
</details>
119144

120145
<a href='#toc' title='Back to Contents'>Back to Contents</a>
121-
## More examples
146+
## Keyed Services
122147

123-
You can also initialise readonly fields, and AutoCtor will not include them in the constructor.
124-
125-
snippet: PresetField
148+
When using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[AutoKeyedService]` and it will be included in the constructor.
126149

127-
snippet: PresetFieldGeneratedCode
150+
snippet: Keyed
128151

129-
If there is a single base constructor with parameters, AutoCtor will include that base constructor in the constructor it creates.
152+
<details><summary>What gets generated</summary>
130153

131-
snippet: Inherit
154+
snippet: Keyed.ExamplesGeneratedCode#Keyed.g.verified.cs
132155

133-
snippet: InheritGeneratedCode
156+
</details>
134157

135158
<a href='#toc' title='Back to Contents'>Back to Contents</a>
136-
## Embedding the attributes in your project
159+
## Other
160+
161+
### Embedding The Attributes
137162

138163
By default, the `[AutoConstruct]` attributes referenced in your project are contained in an external dll. It is also possible to embed the attributes directly in your project. To do this, you must do two things:
139164

140-
1. Define the MSBuild constant `AUTOCTOR_EMBED_ATTRIBUTES`. This ensures the attributes are embedded in your project.
165+
1. Define the constant `AUTOCTOR_EMBED_ATTRIBUTES`. This ensures the attributes are embedded in your project.
141166
2. Add `compile` to the list of excluded assets in your `<PackageReference>` element. This ensures the attributes in your project are referenced, instead of the _AutoCtor.Attributes.dll_ library.
142167

143168
Your project file should look like this:
@@ -147,7 +172,7 @@ Your project file should look like this:
147172

148173
<PropertyGroup>
149174
<!-- Define the MSBuild constant -->
150-
<DefineConstants>AUTOCTOR_EMBED_ATTRIBUTES</DefineConstants>
175+
<DefineConstants>$(DefineConstants);AUTOCTOR_EMBED_ATTRIBUTES</DefineConstants>
151176
</PropertyGroup>
152177

153178
<!-- Add the package -->
@@ -159,24 +184,26 @@ Your project file should look like this:
159184
</Project>
160185
```
161186

162-
<a href='#toc' title='Back to Contents'>Back to Contents</a>
163-
## Preserving usage of the `[AutoConstruct]` attribute
187+
<details><summary>What gets generated</summary>
188+
189+
snippet: GeneratedAttributeTests.AttributeGeneratedCode#AutoConstructAttribute.g.verified.cs
190+
191+
</details>
192+
193+
### Keeping Attributes In Code
164194

165195
The `[AutoConstruct]` attributes are decorated with the `[Conditional]` attribute, so their usage will not appear in the build output of your project. If you use reflection at runtime you will not find the `[AutoConstruct]` attributes.
166196

167-
If you wish to preserve these attributes in the build output, you can define the `AUTOCTOR_USAGES` MSBuild variable.
197+
If you wish to preserve these attributes in the build output, add the define constant `AUTOCTOR_USAGES`.
168198

169199
```xml
170200
<Project Sdk="Microsoft.NET.Sdk">
171201

172202
<PropertyGroup>
173203
<!-- Define the MSBuild constant -->
174-
<DefineConstants>AUTOCTOR_USAGES</DefineConstants>
204+
<DefineConstants>$(DefineConstants);AUTOCTOR_USAGES</DefineConstants>
175205
</PropertyGroup>
176206

177-
<!-- Add the package -->
178-
<PackageReference Include="AutoCtor" PrivateAssets="all" />
179-
180207
</Project>
181208
```
182209

src/AutoCtor.Attributes/AutoCtor.Attributes.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<RootNamespace>AutoCtor</RootNamespace>
66
<IsPackable>true</IsPackable>
7+
<DevelopmentDependency>true</DevelopmentDependency>
78
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
89
</PropertyGroup>
910

src/AutoCtor.Example/AutoCtor.Example.csproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/AutoCtor.Example/BasicExamples.cs

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)