From d840c4b3955be2020b139bede2b2628b004ef221 Mon Sep 17 00:00:00 2001 From: Manodasan Wignarajah Date: Sun, 3 Oct 2021 14:05:59 -0700 Subject: [PATCH] Minor changes based on rosyln analyzer suggestions. --- src/WinRT.Runtime/GuidGenerator.cs | 2 +- src/WinRT.Runtime/Marshalers.cs | 32 ++++++++++++++++------------ src/WinRT.Runtime/TypeNameSupport.cs | 4 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/WinRT.Runtime/GuidGenerator.cs b/src/WinRT.Runtime/GuidGenerator.cs index 3fa0063bc..c77d533d6 100644 --- a/src/WinRT.Runtime/GuidGenerator.cs +++ b/src/WinRT.Runtime/GuidGenerator.cs @@ -31,7 +31,7 @@ public static string GetSignature(Type type) var sigMethod = helperType.GetMethod("GetGuidSignature", BindingFlags.Static | BindingFlags.Public); if (sigMethod != null) { - return (string)sigMethod.Invoke(null, new Type[] { }); + return (string)sigMethod.Invoke(null, Array.Empty()); } } diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 3842b3b15..621b356cd 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -48,7 +48,8 @@ public static unsafe MarshalString CreateMarshaler(string value) if (value == null) return null; var m = new MarshalString(); - Func dispose = () => { m.Dispose(); return false; }; + + static bool dispose(MarshalString m) { m.Dispose(); return false; } try { m._gchandle = GCHandle.Alloc(value, GCHandleType.Pinned); @@ -60,7 +61,7 @@ public static unsafe MarshalString CreateMarshaler(string value) }; return m; } - catch (Exception) when (dispose()) + catch (Exception) when (dispose(m)) { // Will never execute return default; @@ -140,7 +141,8 @@ public static unsafe MarshalerArray CreateMarshalerArray(string[] array) { return m; } - Func dispose = () => { m.Dispose(); return false; }; + + bool dispose() { m.Dispose(); return false; } try { var length = array.Length; @@ -205,13 +207,13 @@ public static unsafe (int length, IntPtr data) FromManagedArray(string[] array) } IntPtr data = IntPtr.Zero; int i = 0; - Func dispose = () => + bool dispose() { DisposeAbiArray((i, data)); i = 0; data = IntPtr.Zero; return false; - }; + } try { var length = array.Length; @@ -238,7 +240,7 @@ public static unsafe void CopyManagedArray(string[] array, IntPtr data) } DisposeAbiArrayElements((array.Length, data)); int i = 0; - Func dispose = () => { DisposeAbiArrayElements((i, data)); return false; }; + bool dispose() { DisposeAbiArrayElements((i, data)); return false; } try { var length = array.Length; @@ -550,7 +552,8 @@ public void Dispose() { return m; } - Func dispose = () => { m.Dispose(); return false; }; + + bool dispose() { m.Dispose(); return false; } try { int length = array.Length; @@ -628,13 +631,13 @@ public static unsafe void CopyAbiArray(T[] array, object box) } IntPtr data = IntPtr.Zero; int i = 0; - Func dispose = () => + bool dispose() { DisposeAbiArray((i, data)); i = 0; data = IntPtr.Zero; return false; - }; + } try { int length = array.Length; @@ -664,7 +667,7 @@ public static unsafe void CopyAbiArray(T[] array, object box) } DisposeAbiArrayElements((array.Length, data)); int i = 0; - Func dispose = () => { DisposeAbiArrayElements((i, data)); return false; }; + bool dispose() { DisposeAbiArrayElements((i, data)); return false; } try { int length = array.Length; @@ -736,7 +739,8 @@ public static unsafe MarshalerArray CreateMarshalerArray(T[] array, Func dispose = () => { m.Dispose(); return false; }; + + bool dispose() { m.Dispose(); return false; } try { int length = array.Length; @@ -806,13 +810,13 @@ public static unsafe (int length, IntPtr data) FromManagedArray(T[] array, Func< } IntPtr data = IntPtr.Zero; int i = 0; - Func dispose = () => + bool dispose() { DisposeAbiArray((i, data)); i = 0; data = IntPtr.Zero; return false; - }; + } try { int length = array.Length; @@ -840,7 +844,7 @@ public static unsafe void CopyManagedArray(T[] array, IntPtr data, Action dispose = () => { DisposeAbiArrayElements((i, data)); return false; }; + bool dispose() { DisposeAbiArrayElements((i, data)); return false; } try { int length = array.Length; diff --git a/src/WinRT.Runtime/TypeNameSupport.cs b/src/WinRT.Runtime/TypeNameSupport.cs index 7a73e671b..24157f781 100644 --- a/src/WinRT.Runtime/TypeNameSupport.cs +++ b/src/WinRT.Runtime/TypeNameSupport.cs @@ -250,7 +250,7 @@ private static bool TryAppendSimpleTypeName(Type type, StringBuilder builder, Ty { return false; } - builder.Append(">"); + builder.Append('>'); return true; } if (type == typeof(byte)) @@ -355,7 +355,7 @@ private static bool TryAppendTypeName(Type type, StringBuilder builder, TypeName builder.Append("Windows.Foundation.IReferenceArray`1<"); if (TryAppendTypeName(type.GetElementType(), builder, flags & ~TypeNameGenerationFlags.GenerateBoxedName)) { - builder.Append(">"); + builder.Append('>'); return true; } return true;