Skip to content

Commit ae8d2ed

Browse files
PowerShellTeamlzybkr
authored andcommitted
Refactor - convert to auto-property
Mostly using R# to automatically refactor, with some manual fixups where it wouldn't work automatically (e.g. xml comments on fields) or some it seemed to miss. Some minor code reformatting was also done on properties near other stuff I was manually inspecting.
1 parent bc4901b commit ae8d2ed

263 files changed

Lines changed: 4838 additions & 15846 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/MethodInvocationJobBase.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ internal MethodInvocationJobBase(CimJobContext jobContext, bool passThru, string
2626
Dbg.Assert(methodSubject != null, "Caller should verify methodSubject != null");
2727

2828
_passThru = passThru;
29-
_methodSubject = methodSubject;
29+
MethodSubject = methodSubject;
3030
_methodInvocationInfo = methodInvocationInfo;
3131
}
3232

33-
private readonly string _methodSubject;
3433
private readonly bool _passThru;
3534
private readonly MethodInvocationInfo _methodInvocationInfo;
3635

@@ -108,10 +107,7 @@ internal IEnumerable<MethodParameter> GetMethodOutputParameters()
108107
return outParameters;
109108
}
110109

111-
internal string MethodSubject
112-
{
113-
get { return _methodSubject; }
114-
}
110+
internal string MethodSubject { get; }
115111

116112
internal bool ShouldProcess()
117113
{

src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ internal abstract class PropertyValueFilter
332332
{
333333
protected PropertyValueFilter(string propertyName, object expectedPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch)
334334
{
335-
_propertyName = propertyName;
335+
PropertyName = propertyName;
336336
_behaviorOnNoMatch = behaviorOnNoMatch;
337-
_originalExpectedPropertyValue = expectedPropertyValue;
338-
_cimTypedExpectedPropertyValue = CimValueConverter.ConvertFromDotNetToCim(expectedPropertyValue);
337+
OriginalExpectedPropertyValue = expectedPropertyValue;
338+
CimTypedExpectedPropertyValue = CimValueConverter.ConvertFromDotNetToCim(expectedPropertyValue);
339339
}
340340

341341
public BehaviorOnNoMatch BehaviorOnNoMatch
@@ -352,17 +352,13 @@ public BehaviorOnNoMatch BehaviorOnNoMatch
352352
protected abstract BehaviorOnNoMatch GetDefaultBehaviorWhenNoMatchesFound(object cimTypedExpectedPropertyValue);
353353
private BehaviorOnNoMatch _behaviorOnNoMatch;
354354

355-
public string PropertyName { get { return _propertyName; } }
356-
private readonly string _propertyName;
355+
public string PropertyName { get; }
357356

358-
public object CimTypedExpectedPropertyValue { get { return _cimTypedExpectedPropertyValue; } }
359-
private readonly object _cimTypedExpectedPropertyValue;
357+
public object CimTypedExpectedPropertyValue { get; }
360358

361-
public object OriginalExpectedPropertyValue { get { return _originalExpectedPropertyValue; } }
362-
private readonly object _originalExpectedPropertyValue;
359+
public object OriginalExpectedPropertyValue { get; }
363360

364-
public bool HadMatch { get { return _hadMatch; } }
365-
private bool _hadMatch;
361+
public bool HadMatch { get; private set; }
366362

367363
public bool IsMatch(CimInstance o)
368364
{
@@ -371,27 +367,27 @@ public bool IsMatch(CimInstance o)
371367
return false;
372368
}
373369

374-
CimProperty propertyInfo = o.CimInstanceProperties[_propertyName];
370+
CimProperty propertyInfo = o.CimInstanceProperties[PropertyName];
375371
if (propertyInfo == null)
376372
{
377373
return false;
378374
}
379375
object actualPropertyValue = propertyInfo.Value;
380376

381-
if (_cimTypedExpectedPropertyValue == null)
377+
if (CimTypedExpectedPropertyValue == null)
382378
{
383-
_hadMatch = _hadMatch || (actualPropertyValue == null);
379+
HadMatch = HadMatch || (actualPropertyValue == null);
384380
return actualPropertyValue == null;
385381
}
386382

387383
CimValueConverter.AssertIntrinsicCimValue(actualPropertyValue);
388-
CimValueConverter.AssertIntrinsicCimValue(_cimTypedExpectedPropertyValue);
384+
CimValueConverter.AssertIntrinsicCimValue(CimTypedExpectedPropertyValue);
389385

390-
actualPropertyValue = ConvertActualValueToExpectedType(actualPropertyValue, _cimTypedExpectedPropertyValue);
391-
Dbg.Assert(IsSameType(actualPropertyValue, _cimTypedExpectedPropertyValue), "Types of actual vs expected property value should always match");
386+
actualPropertyValue = ConvertActualValueToExpectedType(actualPropertyValue, CimTypedExpectedPropertyValue);
387+
Dbg.Assert(IsSameType(actualPropertyValue, CimTypedExpectedPropertyValue), "Types of actual vs expected property value should always match");
392388

393389
bool isMatch = this.IsMatchingValue(actualPropertyValue);
394-
_hadMatch = _hadMatch || isMatch;
390+
HadMatch = HadMatch || isMatch;
395391
return isMatch;
396392
}
397393

@@ -409,7 +405,7 @@ private object ConvertActualValueToExpectedType(object actualPropertyValue, obje
409405
var errorMessage = string.Format(
410406
CultureInfo.InvariantCulture,
411407
CmdletizationResources.CimJob_MismatchedTypeOfPropertyReturnedByQuery,
412-
_propertyName,
408+
PropertyName,
413409
actualPropertyValue.GetType().FullName,
414410
expectedPropertyValue.GetType().FullName);
415411
throw CimJobException.CreateWithoutJobContext(

src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,25 @@ public class JoinPathCommand : CoreCommandWithCredentialsBase
2424
/// </summary>
2525
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
2626
[Alias("PSPath")]
27-
public string[] Path
28-
{
29-
get
30-
{
31-
return _paths;
32-
} // get
33-
34-
set
35-
{
36-
_paths = value;
37-
} // set
38-
} // Path
27+
public string[] Path { get; set; }
3928

4029
/// <summary>
4130
/// Gets or sets the childPath parameter to the command
4231
/// </summary>
4332
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)]
4433
[AllowNull]
4534
[AllowEmptyString]
46-
public string ChildPath
47-
{
48-
get
49-
{
50-
return _childPath;
51-
} // get
52-
53-
set
54-
{
55-
_childPath = value;
56-
} // set
57-
} // childPath
35+
public string ChildPath { get; set; } = String.Empty;
5836

5937
/// <summary>
6038
/// Determines if the path should be resolved after being joined
6139
/// </summary>
6240
/// <value></value>
6341
[Parameter]
64-
public SwitchParameter Resolve
65-
{
66-
get
67-
{
68-
return _resolve;
69-
} // get
70-
71-
set
72-
{
73-
_resolve = value;
74-
} //set
75-
} // Resolve
42+
public SwitchParameter Resolve { get; set; }
7643

7744
#endregion Parameters
7845

79-
#region parameter data
80-
81-
/// <summary>
82-
/// The path to resolve
83-
/// </summary>
84-
private string[] _paths;
85-
86-
/// <summary>
87-
/// The child part of the path to be joined with the Path paramter
88-
/// </summary>
89-
private string _childPath = String.Empty;
90-
91-
/// <summary>
92-
/// Determines if the path should be resolved after being joined.
93-
/// </summary>
94-
private bool _resolve;
95-
96-
#endregion parameter data
97-
9846
#region Command code
9947

10048
/// <summary>
@@ -104,7 +52,7 @@ public SwitchParameter Resolve
10452
protected override void ProcessRecord()
10553
{
10654
Dbg.Diagnostics.Assert(
107-
_paths != null,
55+
Path != null,
10856
"Since Path is a mandatory parameter, paths should never be null");
10957

11058
foreach (string path in Path)

0 commit comments

Comments
 (0)