Skip to content

Commit 65f4948

Browse files
committed
Update csharp-add-servicestack-reference.md
1 parent 0cbd007 commit 65f4948

File tree

1 file changed

+55
-34
lines changed

1 file changed

+55
-34
lines changed

MyApp/_pages/csharp-add-servicestack-reference.md

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,61 @@ public partial class GetAnswers
215215
}
216216
```
217217

218+
### AddNullableAnnotations
219+
220+
Generate DTOs with nullable reference types, e.g:
221+
222+
```csharp
223+
public class Data
224+
{
225+
public int Value { get; set; }
226+
public int? OptionalValue { get; set; }
227+
public string Text { get; set; }
228+
public string? OptionalText { get; set; }
229+
public List<string> Texts { get; set; }
230+
public List<string>? OptionalTexts { get; set; }
231+
}
232+
```
233+
234+
Will generate DTOs, preserving properties with nullable reference type annotations:
235+
236+
```csharp
237+
public class Data
238+
{
239+
public virtual int Value { get; set; }
240+
public virtual int? OptionalValue { get; set; }
241+
public virtual string Text { get; set; }
242+
public virtual string? OptionalText { get; set; }
243+
public virtual List<string> Texts { get; set; } = [];
244+
public virtual List<string>? OptionalTexts { get; set; }
245+
}
246+
```
247+
248+
Optionally if your DTOs do not have nullable reference annotations enabled but you would still like to generate DTOs with them included, you can mark properties as required with the `[Required]` attribute, e.g:
249+
250+
```csharp
251+
public class Data
252+
{
253+
[Required]
254+
public string? Text { get; set; }
255+
[Required]
256+
public List<string>? Texts { get; set; }
257+
}
258+
```
259+
260+
Where it will generate otherwise optional properties as non-nullable reference types:
261+
262+
```csharp
263+
public class Data
264+
{
265+
[Required]
266+
public virtual string Text { get; set; }
267+
268+
[Required]
269+
public virtual List<string> Texts { get; set; } = [];
270+
}
271+
```
272+
218273
### AddReturnMarker
219274

220275
When true, annotates Request DTOs with an `IReturn<TResponse>` marker referencing the Response type ServiceStack infers your Service to return:
@@ -448,37 +503,3 @@ This lets you change the default DataContract XML namespace used for all C# name
448503
```
449504

450505
> Requires AddDataContractAttributes=true
451-
452-
## Xamarin Studio
453-
454-
With the new [ServiceStackXS Add-In](http://addins.monodevelop.com/Project/Index/154) your Service Consumers can now generate typed DTOs of your remote ServiceStack Services directly from within Xamarin Studio, which together with the **ServiceStack.Client** NuGet package provides an effortless way to enable an end-to-end Typed API from within Xamarin C# projects.
455-
456-
### Installing ServiceStackXS
457-
458-
Installation is straightforward if you've installed Xamarin Add-ins before, just go to `Xamarin Studio -> Add-In Manager...` from the Menu and then search for `ServiceStack` from the **Gallery**:
459-
460-
![](https://raw.githubusercontent.com/ServiceStack/Assets/master/img/servicestackvs/servicestack%20reference/ssxs-mac-install.gif)
461-
462-
#### Install from file
463-
464-
If you are having trouble with the Xamarin Studio gallery version, you can install addins from an `mpack` file from the same menu as shown above. Click `Install from file` and navigate to where you have downloaded the `mpack` file.
465-
466-
### Adding a ServiceStack Reference
467-
468-
Once installed, adding a ServiceStack Reference is very similar to [ServiceStackVS in VS.NET](/csharp-add-servicestack-reference#add-servicestack-reference) where you can just click on `Add -> Add ServiceStack Reference...` on the project's context menu to bring up the familiar Add Reference dialog. After adding the `BaseUrl` of the remote ServiceStack instance, click OK to add the generated DTO's to your project using the name specified:
469-
470-
![](https://raw.githubusercontent.com/ServiceStack/Assets/master/img/servicestackvs/servicestack%20reference/ssxs-mac-add-reference.gif)
471-
472-
### Updating the ServiceStack Reference
473-
474-
As file watching isn't supported yet, to refresh the generated DTOs, you'll need to right-click on it in the solution explorer and select `Update ServiceStack Reference` from the items context menu.
475-
476-
### Xamarin Studio for Linux
477-
478-
One of the nice benefits of creating an Xamarin Studio Add-in is that we're also able to bring the same experience to .NET Developers on Linux! Which works similar to OSX where you can install ServiceStackXS from the Add-in Gallery - Here's an example using Ubuntu:
479-
480-
![](https://raw.githubusercontent.com/ServiceStack/Assets/master/img/servicestackvs/servicestack%20reference/ssxs-ubuntu-install.gif)
481-
482-
Then **Add ServiceStack Reference** is accessible in the same way:
483-
484-
![](https://raw.githubusercontent.com/ServiceStack/Assets/master/img/servicestackvs/servicestack%20reference/ssxs-ubuntu-add-ref.gif)

0 commit comments

Comments
 (0)