Skip to content

Commit 41ab20c

Browse files
authored
Mark applicable structs as readonly and use in-modifier (PowerShell#13919)
1 parent 817e6b0 commit 41ab20c

26 files changed

Lines changed: 135 additions & 135 deletions

File tree

src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ protected override void ProcessRecord()
327327
}
328328
}
329329

330-
provider.WriteEvent(ref ed, _payload);
330+
provider.WriteEvent(in ed, _payload);
331331
}
332332
else
333333
{
334-
provider.WriteEvent(ref ed);
334+
provider.WriteEvent(in ed);
335335
}
336336
}
337337

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public PSObject AttachNotes(PSObject content)
336336
/// A struct to hold the path information and the content readers/writers
337337
/// for an item.
338338
/// </summary>
339-
internal struct ContentHolder
339+
internal readonly struct ContentHolder
340340
{
341341
internal ContentHolder(
342342
PathInfo pathInfo,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected override void ProcessRecord()
277277
/// true if no error occured
278278
/// false if there was an error
279279
/// </returns>
280-
private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext currentContext)
280+
private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext currentContext)
281281
{
282282
var fsReader = holder.Reader as FileSystemContentReaderWriter;
283283
Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter");

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static class ComInterfaces
1818
/// string fields at all, nothing is lost.
1919
/// </remarks>
2020
[StructLayout(LayoutKind.Sequential)]
21-
internal struct StartUpInfo
21+
internal readonly struct StartUpInfo
2222
{
2323
public readonly UInt32 cb;
2424
private readonly IntPtr lpReserved;
@@ -141,7 +141,7 @@ internal interface IPropertyStore
141141
/// <param name="pv"></param>
142142
/// <returns></returns>
143143
[PreserveSig]
144-
HResult GetValue([In] ref PropertyKey key, [Out] PropVariant pv);
144+
HResult GetValue([In] in PropertyKey key, [Out] PropVariant pv);
145145

146146
/// <summary>
147147
/// Sets the value of a property in the store.
@@ -150,7 +150,7 @@ internal interface IPropertyStore
150150
/// <param name="pv"></param>
151151
/// <returns></returns>
152152
[PreserveSig]
153-
HResult SetValue([In] ref PropertyKey key, [In] PropVariant pv);
153+
HResult SetValue([In] in PropertyKey key, [In] PropVariant pv);
154154

155155
/// <summary>
156156
/// Commits the changes.

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.PowerShell
1010
/// Defines a unique key for a Shell Property.
1111
/// </summary>
1212
[StructLayout(LayoutKind.Sequential, Pack = 4)]
13-
internal struct PropertyKey : IEquatable<PropertyKey>
13+
internal readonly struct PropertyKey : IEquatable<PropertyKey>
1414
{
1515
#region Public Properties
1616
/// <summary>

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static void CreateElevatedEntry(string title)
9797
flags |= 0x00002000; // SLDF_RUNAS_USER
9898
shellLinkDataList.SetFlags(flags);
9999
var PKEY_TITLE = new PropertyKey(new Guid("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"), 2);
100-
hResult = nativePropertyStore.SetValue(ref PKEY_TITLE, new PropVariant(title));
100+
hResult = nativePropertyStore.SetValue(in PKEY_TITLE, new PropVariant(title));
101101
if (hResult < 0)
102102
{
103103
pCustDestList.AbortList();

src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace System.Diagnostics.Eventing
99
{
1010
[StructLayout(LayoutKind.Explicit, Size = 16)]
11-
public struct EventDescriptor
11+
public readonly struct EventDescriptor
1212
{
1313
[FieldOffset(0)]
1414
private readonly ushort _id;

src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ public bool WriteMessageEvent(string eventMessage)
488488
/// </param>
489489
/// <param name="eventPayload">
490490
/// </param>
491-
public bool WriteEvent(ref EventDescriptor eventDescriptor, params object[] eventPayload)
491+
public bool WriteEvent(in EventDescriptor eventDescriptor, params object[] eventPayload)
492492
{
493-
return WriteTransferEvent(ref eventDescriptor, Guid.Empty, eventPayload);
493+
return WriteTransferEvent(in eventDescriptor, Guid.Empty, eventPayload);
494494
}
495495

496496
/// <summary>
@@ -504,7 +504,7 @@ public bool WriteEvent(ref EventDescriptor eventDescriptor, params object[] even
504504
/// </param>
505505
[System.Security.SecurityCritical]
506506
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
507-
public bool WriteEvent(ref EventDescriptor eventDescriptor, string data)
507+
public bool WriteEvent(in EventDescriptor eventDescriptor, string data)
508508
{
509509
uint status = 0;
510510

@@ -534,7 +534,7 @@ public bool WriteEvent(ref EventDescriptor eventDescriptor, string data)
534534
userData.DataPointer = (ulong)pdata;
535535

536536
status = UnsafeNativeMethods.EventWriteTransfer(_regHandle,
537-
ref eventDescriptor,
537+
in eventDescriptor,
538538
(activityId == Guid.Empty) ? null : &activityId,
539539
null,
540540
1,
@@ -565,7 +565,7 @@ public bool WriteEvent(ref EventDescriptor eventDescriptor, string data)
565565
/// pointer do the event data
566566
/// </param>
567567
[System.Security.SecurityCritical]
568-
protected bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, IntPtr data)
568+
protected bool WriteEvent(in EventDescriptor eventDescriptor, int dataCount, IntPtr data)
569569
{
570570
uint status = 0;
571571

@@ -575,7 +575,7 @@ protected bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, In
575575

576576
status = UnsafeNativeMethods.EventWriteTransfer(
577577
_regHandle,
578-
ref eventDescriptor,
578+
in eventDescriptor,
579579
(activityId == Guid.Empty) ? null : &activityId,
580580
null,
581581
(uint)dataCount,
@@ -602,7 +602,7 @@ protected bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, In
602602
/// <param name="eventPayload">
603603
/// </param>
604604
[System.Security.SecurityCritical]
605-
public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload)
605+
public bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload)
606606
{
607607
uint status = 0;
608608

@@ -719,7 +719,7 @@ public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid related
719719
}
720720

721721
status = UnsafeNativeMethods.EventWriteTransfer(_regHandle,
722-
ref eventDescriptor,
722+
in eventDescriptor,
723723
(activityId == Guid.Empty) ? null : &activityId,
724724
(relatedActivityId == Guid.Empty) ? null : &relatedActivityId,
725725
(uint)argCount,
@@ -737,7 +737,7 @@ public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid related
737737
}
738738

739739
[System.Security.SecurityCritical]
740-
protected bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data)
740+
protected bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data)
741741
{
742742
uint status = 0;
743743

@@ -747,7 +747,7 @@ protected bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid rela
747747
{
748748
status = UnsafeNativeMethods.EventWriteTransfer(
749749
_regHandle,
750-
ref eventDescriptor,
750+
in eventDescriptor,
751751
(activityId == Guid.Empty) ? null : &activityId,
752752
&relatedActivityId,
753753
(uint)dataCount,

src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ [In][Out] ref long registrationHandle
132132
// Control (Is Enabled) APIs
133133
[DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventEnabled", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
134134
[SecurityCritical]
135-
internal static extern int EventEnabled([In] long registrationHandle, [In] ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor);
135+
internal static extern int EventEnabled([In] long registrationHandle, [In] in System.Diagnostics.Eventing.EventDescriptor eventDescriptor);
136136

137137
[DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventProviderEnabled", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
138138
[SecurityCritical]
@@ -143,7 +143,7 @@ [In][Out] ref long registrationHandle
143143
[SecurityCritical]
144144
internal static extern unsafe uint EventWrite(
145145
[In] long registrationHandle,
146-
[In] ref EventDescriptor eventDescriptor,
146+
[In] in EventDescriptor eventDescriptor,
147147
[In] uint userDataCount,
148148
[In] void* userData
149149
);
@@ -162,7 +162,7 @@ [In] void* userData
162162
[SecurityCritical]
163163
internal static extern unsafe uint EventWriteTransfer(
164164
[In] long registrationHandle,
165-
[In] ref EventDescriptor eventDescriptor,
165+
[In] in EventDescriptor eventDescriptor,
166166
[In] Guid* activityId,
167167
[In] Guid* relatedActivityId,
168168
[In] uint userDataCount,

src/Microsoft.PowerShell.Security/security/CertificateProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public int ExpiringInDays
123123
/// The structure contains punycode name and unicode name.
124124
/// </summary>
125125
[SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
126-
public struct DnsNameRepresentation
126+
public readonly struct DnsNameRepresentation
127127
{
128128
/// <summary>
129129
/// Punycode version of DNS name.
@@ -3064,7 +3064,7 @@ public X509StoreLocation(StoreLocation location)
30643064
/// The structure contains friendly name and EKU oid.
30653065
/// </summary>
30663066
[SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
3067-
public struct EnhancedKeyUsageRepresentation
3067+
public readonly struct EnhancedKeyUsageRepresentation
30683068
{
30693069
/// <summary>
30703070
/// Localized friendly name of EKU.

0 commit comments

Comments
 (0)