Skip to content

Commit 664e243

Browse files
authored
Merge pull request Caliburn-Micro#937 from Caliburn-Micro/936-fix-build-warnings
Refactor ViewModel fields and add XML documentation
2 parents 7e7f64c + e48a096 commit 664e243

File tree

14 files changed

+117
-75
lines changed

14 files changed

+117
-75
lines changed

samples/features/Features.Avalonia/ViewModels/ShellViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public class ShellViewModel : Screen, IHandle<FeatureViewModel>
1010
private SimpleContainer _container;
1111
private INavigationService _navigationService;
1212

13+
// supressing warning for _navigationService not having a value in the constructor
14+
// need NavigationFrame to be passed in from the view
15+
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
1316
public ShellViewModel(IEventAggregator eventAggregator, SimpleContainer container)
17+
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
1418
{
1519
_eventAggregator = eventAggregator;
1620
_eventAggregator.SubscribeOnPublishedThread(this);

samples/features/Features.CrossPlatform.Shared/ViewModels/ActionsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ActionsViewModel : Screen
99
private string _output;
1010
public ActionsViewModel()
1111
{
12-
Output="Caliburn Micro";
12+
_output = "Caliburn Micro";
1313
}
1414

1515
public void Clear() => Output = string.Empty;

samples/features/Features.CrossPlatform.Shared/ViewModels/Events/EventSourceViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading;
1+
using System.Threading;
32
using Caliburn.Micro;
43
using Features.CrossPlatform.Messages;
54

@@ -8,17 +7,18 @@ namespace Features.CrossPlatform.ViewModels.Events
87
public class EventSourceViewModel : Screen
98
{
109
private readonly IEventAggregator eventAggregator;
11-
private string text;
10+
private string _text;
1211

1312
public EventSourceViewModel(IEventAggregator eventAggregator)
1413
{
1514
this.eventAggregator = eventAggregator;
15+
_text = string.Empty;
1616
}
1717

1818
public string Text
1919
{
20-
get { return text; }
21-
set { Set(ref text, value); }
20+
get { return _text; }
21+
set { Set(ref _text, value); }
2222
}
2323

2424
public async void Publish()

samples/features/Features.CrossPlatform.Shared/ViewModels/NavigationTargetViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ public class NavigationTargetViewModel : Screen
66
{
77
private string _text;
88
private bool _isEnabled;
9-
9+
public NavigationTargetViewModel()
10+
{
11+
_text = string.Empty;
12+
}
1013
public string Text
1114
{
1215
get { return _text; }

src/Caliburn.Micro.Avalonia/Caliburn.Micro.Avalonia.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
<PropertyGroup>
1414
<DefineConstants>AVALONIA</DefineConstants>
15+
<Title>Caliburn.Micro Avalonia UI</Title>
16+
<PackageIcon>CaliburnIcon.png</PackageIcon>
17+
<PackageReadmeFile>README.md</PackageReadmeFile>
1518
</PropertyGroup>
1619

1720
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'" />
@@ -46,6 +49,17 @@
4649
<Compile Include="..\Caliburn.Micro.Platform\Platforms\netcore-avalonia\WindowManager.cs" Link="Platforms\netcore-avalonia\WindowManager.cs" />
4750
</ItemGroup>
4851

52+
<ItemGroup>
53+
<None Include="..\..\CaliburnIcon.png">
54+
<Pack>True</Pack>
55+
<PackagePath>\</PackagePath>
56+
</None>
57+
<None Include="..\..\README.md">
58+
<Pack>True</Pack>
59+
<PackagePath>\</PackagePath>
60+
</None>
61+
</ItemGroup>
62+
4963
<ItemGroup>
5064
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
5165
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.146" />

src/Caliburn.Micro.Core.Tests/ConductorWithCollectionOneActiveTests.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ private class ActivateScreen : Screen
3939
public int ActivateCalledCount { get; private set; }
4040
public bool AutoContinue { get; set; }
4141

42+
[Obsolete("Please use OnActivatedAsync instead.")]
4243
protected override async Task OnActivateAsync(CancellationToken cancellationToken)
4344
{
4445
ActivateCalledCount++;
4546
await Task.Delay(100, cancellationToken);
4647
if (AutoContinue)
4748
RequestContinue?.Invoke(this, EventArgs.Empty);
4849
}
50+
51+
protected override async Task OnActivatedAsync(CancellationToken cancellationToken)
52+
{
53+
ActivateCalledCount++;
54+
await Task.Delay(100, cancellationToken);
55+
if (AutoContinue)
56+
RequestContinue?.Invoke(this, EventArgs.Empty);
57+
}
4958
}
5059

5160
private class ActivatedScreen : Screen
@@ -54,12 +63,12 @@ private class ActivatedScreen : Screen
5463

5564
public int ActivateCalledCount { get; private set; }
5665
public bool AutoContinue { get; set; }
57-
66+
5867
protected override async Task OnActivatedAsync(CancellationToken cancellationToken)
5968
{
6069
ActivateCalledCount++;
6170
await Task.Delay(100, cancellationToken);
62-
if(AutoContinue)
71+
if (AutoContinue)
6372
RequestContinue?.Invoke(this, EventArgs.Empty);
6473
}
6574
}
@@ -123,7 +132,7 @@ public async Task CanCloseIsTrueWhenItemsAreClosable()
123132
conductor.Items.Add(conducted);
124133

125134
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
126-
var canClose =await conductor.CanCloseAsync(CancellationToken.None);
135+
var canClose = await conductor.CanCloseAsync(CancellationToken.None);
127136

128137
Assert.True(canClose);
129138
Assert.False(conducted.IsClosed);
@@ -141,7 +150,7 @@ public async Task CanCloseIsTrueWhenItemsAreNotClosableAndCloseStrategyCloses()
141150
IsClosable = true
142151
};
143152
conductor.Items.Add(conducted);
144-
await((IActivate)conductor).ActivateAsync(CancellationToken.None);
153+
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
145154
var canClose = await conductor.CanCloseAsync(CancellationToken.None);
146155

147156
Assert.True(canClose);
@@ -166,17 +175,17 @@ public async Task ActivateWhileActivateOneLevel()
166175
var conductor = new Conductor<IScreen>.Collection.OneActive();
167176
var viewModel1 = new ActivateScreen()
168177
{
169-
DisplayName = "ViewModel 1",
178+
DisplayName = "ViewModel 1",
170179
AutoContinue = true
171180
};
172181
conductor.Items.Add(viewModel1);
173182
var viewModel2 = new ActivateScreen() { DisplayName = "ViewModel 2" };
174183
conductor.Items.Add(viewModel2);
175184
viewModel1.RequestContinue += (sender, e) => { conductor.ActivateItemAsync(viewModel2).Wait(); };
176-
185+
177186
await conductor.ActivateAsync();
178187
await conductor.ActivateItemAsync(viewModel1);
179-
188+
180189
Assert.False(viewModel1.IsActive);
181190
Assert.Equal(1, viewModel1.ActivateCalledCount);
182191
Assert.True(viewModel2.IsActive);
@@ -189,17 +198,17 @@ public async Task ActivatedWhileActivatedOneLevel()
189198
var conductor = new Conductor<IScreen>.Collection.OneActive();
190199
var viewModel1 = new ActivatedScreen()
191200
{
192-
DisplayName = "ViewModel 1",
201+
DisplayName = "ViewModel 1",
193202
AutoContinue = true
194203
};
195204
conductor.Items.Add(viewModel1);
196205
var viewModel2 = new ActivatedScreen() { DisplayName = "ViewModel 2" };
197206
conductor.Items.Add(viewModel2);
198207
viewModel1.RequestContinue += (sender, e) => { conductor.ActivateItemAsync(viewModel2).Wait(); };
199-
208+
200209
await conductor.ActivateAsync();
201210
await conductor.ActivateItemAsync(viewModel1);
202-
211+
203212
Assert.False(viewModel1.IsActive);
204213
Assert.Equal(1, viewModel1.ActivateCalledCount);
205214
Assert.True(viewModel2.IsActive);
@@ -223,7 +232,7 @@ public async Task ActivateWhileActivateStackedLevels()
223232
await outerConductor.ActivateAsync();
224233
await outerConductor.ActivateItemAsync(innerConductor);
225234
await innerConductor.ActivateItemAsync(viewModel1);
226-
235+
227236
await outerConductor.ChangeActiveItemAsyncPublic(somePage, false);
228237
Assert.True(somePage.IsActive);
229238
viewModel1.AutoContinue = true;
@@ -235,7 +244,7 @@ public async Task ActivateWhileActivateStackedLevels()
235244
Assert.True(viewModel2.IsActive);
236245
Assert.Equal(1, viewModel2.ActivateCalledCount);
237246
}
238-
247+
239248
[Fact(Skip = "ActiveItem currently set regardless of IsActive value. See http://caliburnmicro.codeplex.com/discussions/276375")]
240249
public async Task ChildrenAreNotActivatedIfConductorIsNotActive()
241250
{
@@ -326,7 +335,7 @@ public async Task ActiveItemSetterShouldSetThePropertySynchronouslyWhenOnDeactiv
326335
conductor.Items.Add(conducted1);
327336
var conducted2 = new Screen();
328337
conductor.Items.Add(conducted2);
329-
await((IActivate)conductor).ActivateAsync(CancellationToken.None);
338+
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
330339
conductor.ActiveItem = conducted1;
331340
conductor.ActiveItem = conducted2;
332341
Assert.NotNull(conductor.ActiveItem);

src/Caliburn.Micro.Core.Tests/ScreenExtentionTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public override Task<bool> CanCloseAsync(CancellationToken cancellationToken = d
101101
return Task.FromResult(IsClosable);
102102
}
103103

104+
[Obsolete("Use OnActivateAsync instead.")]
104105
protected override async Task OnActivateAsync(CancellationToken cancellationToken)
105106
{
106107
if (deactivationDelay.HasValue)
@@ -110,6 +111,20 @@ protected override async Task OnActivateAsync(CancellationToken cancellationToke
110111

111112
await base.OnActivateAsync(cancellationToken);
112113

114+
115+
WasActivated = true;
116+
IsClosable = false;
117+
}
118+
119+
protected override async Task OnActivatedAsync(CancellationToken cancellationToken)
120+
{
121+
if (deactivationDelay.HasValue)
122+
{
123+
await Task.Delay(deactivationDelay.Value, cancellationToken).ConfigureAwait(false);
124+
}
125+
126+
await base.OnActivatedAsync(cancellationToken);
127+
113128
WasActivated = true;
114129
IsClosable = false;
115130
}

src/Caliburn.Micro.Core/SimpleContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ public bool HasHandler(Type service, string key)
172172
/// <returns>All the instances or an empty enumerable if none are found.</returns>
173173
public IEnumerable<object> GetAllInstances(Type service, string key = null)
174174
{
175-
var entries = GetEntry(service, key);
175+
var currentEntry = GetEntry(service, key);
176176

177-
if (entries == null)
177+
if (currentEntry == null)
178178
{
179179
return new object[0];
180180
}
181181

182-
var instances = entries.Select(e => e(this));
182+
var instances = currentEntry.Select(e => e(this));
183183

184184
foreach (var instance in instances)
185185
{

src/Caliburn.Micro.Platform.Core/StringSplitter.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ public static string[] SplitParameters(string parameters)
8989
{
9090
var current = parameters[i];
9191

92-
if (current == '"' || current == '\'')
92+
if ((current == '"' || current == '\'') && (i == 0 || parameters[i - 1] != '\\'))
9393
{
94-
if (i == 0 || parameters[i - 1] != '\\')
95-
{
96-
isInString = !isInString;
97-
}
94+
isInString = !isInString;
9895
}
9996

10097
if (!isInString)

src/Caliburn.Micro.Platform/BindingScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static BindingScope()
5353
AddChildResolver<CommandBar>(ResolveCommandBar);
5454
AddChildResolver<Button>(e => ResolveFlyoutBase(e.Flyout));
5555
AddChildResolver<FrameworkElement>(e => ResolveFlyoutBase(FlyoutBase.GetAttachedFlyout(e)));
56-
AddChildResolver<SplitView>(e => new[] { e.Pane as DependencyObject, e.Content as DependencyObject });
56+
AddChildResolver<SplitView>(e => new[] { e.Pane, e.Content });
5757
#endif
5858
}
5959

0 commit comments

Comments
 (0)