Skip to content

Commit 8b2f329

Browse files
committed
Use the source generator in the example
1 parent 77d618d commit 8b2f329

File tree

5 files changed

+54
-178
lines changed

5 files changed

+54
-178
lines changed

examples/LibStored.Net.Example.Console/ExampleStore.cs

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

examples/LibStored.Net.Example.Console/ExampleSync1.cs

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

examples/LibStored.Net.Example.Console/LibStored.Net.Example.Console.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,24 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13+
<!-- When using the LibStored.Net the LibStored.Net.Generator is already included. So this reference is not needed. -->
14+
<ProjectReference Include="..\..\src\LibStored.Net.Generator\LibStored.Net.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
1315
<ProjectReference Include="..\..\src\LibStored.Net\LibStored.Net.csproj" />
1416
<ProjectReference Include="..\LibStored.Net.Example.ServiceDefaults\LibStored.Net.Example.ServiceDefaults.csproj" />
1517
</ItemGroup>
1618

19+
<PropertyGroup>
20+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
21+
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<!-- Exclude the output of source generators from the compilation -->
26+
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<AdditionalFiles Include="Stores\*Store.json" />
31+
</ItemGroup>
32+
1733
</Project>

examples/LibStored.Net.Example.Console/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
7676
{
7777
string value = args.PropertyName switch
7878
{
79-
nameof(ExampleSync1.I) => store.Store().I.Get().ToString(),
80-
nameof(ExampleSync1.D) => store.Store().D.Get().ToString(CultureInfo.InvariantCulture),
79+
nameof(ExampleSync1.I) => store.Store().I.ToString(),
80+
nameof(ExampleSync1.D) => store.Store().D.ToString(CultureInfo.InvariantCulture),
8181
_ => string.Empty,
8282
};
8383
_logger.LogInformation("Property changed: {PropertyName} = {Value}", args.PropertyName, value);
@@ -145,7 +145,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
145145
int bytesReceived = syncLayer.ReceiveAll();
146146
_logger.LogTrace("Sync Received {Bytes} bytes", bytesReceived);
147147

148-
int number = store.Store().I.Get();
148+
int number = store.Store().I;
149149
_logger.LogInformation("I: {Number}", number);
150150
};
151151
}
@@ -162,19 +162,19 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
162162
// Only the server should increment the number
163163
if (connectionStringServer is not null && connectionStringClient is null)
164164
{
165-
int number = store.Store().I.Get();
165+
int number = store.Store().I;
166166
int newNumber = number + 1;
167-
store.Store().I.Set(newNumber);
167+
store.Store().I = newNumber;
168168
_logger.LogInformation("I set to: {Number}", newNumber);
169169
}
170170

171171
// Update from the middle node, so that both server and client can increment the fraction.
172172
if (connectionStringServer is not null && connectionStringClient is not null)
173173
{
174174
// increment from the middle node.
175-
double fraction = store.Store().D.Get();
175+
double fraction = store.Store().D;
176176
fraction++;
177-
store.Store().D.Set(fraction);
177+
store.Store().D = fraction;
178178
_logger.LogInformation("D set to: {Number}", fraction);
179179
}
180180
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "ExampleSync1",
3+
"hash": "681a3ece584568efcf5879a64b688fc19e620577",
4+
"init": "",
5+
"littleEndian": true,
6+
"variables": [
7+
{
8+
"name": "d",
9+
"cname": "d",
10+
"type": "double",
11+
"size": 8,
12+
"offset": 0
13+
},
14+
{
15+
"name": "i",
16+
"cname": "i",
17+
"type": "int32",
18+
"size": 4,
19+
"offset": 8
20+
}
21+
],
22+
"functions": [
23+
{
24+
"name": "sync ExampleSync2",
25+
"cname": "sync_ExampleSync2",
26+
"type": "bool",
27+
"size": 1,
28+
"function": 1
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)