Skip to content

Commit

Permalink
Minor changes based on rosyln analyzer suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
manodasanW committed Oct 6, 2021
1 parent f16d9c4 commit d840c4b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/GuidGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>());
}
}

Expand Down
32 changes: 18 additions & 14 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static unsafe MarshalString CreateMarshaler(string value)
if (value == null) return null;

var m = new MarshalString();
Func<bool> dispose = () => { m.Dispose(); return false; };

static bool dispose(MarshalString m) { m.Dispose(); return false; }
try
{
m._gchandle = GCHandle.Alloc(value, GCHandleType.Pinned);
Expand All @@ -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;
Expand Down Expand Up @@ -140,7 +141,8 @@ public static unsafe MarshalerArray CreateMarshalerArray(string[] array)
{
return m;
}
Func<bool> dispose = () => { m.Dispose(); return false; };

bool dispose() { m.Dispose(); return false; }
try
{
var length = array.Length;
Expand Down Expand Up @@ -205,13 +207,13 @@ public static unsafe (int length, IntPtr data) FromManagedArray(string[] array)
}
IntPtr data = IntPtr.Zero;
int i = 0;
Func<bool> dispose = () =>
bool dispose()
{
DisposeAbiArray((i, data));
i = 0;
data = IntPtr.Zero;
return false;
};
}
try
{
var length = array.Length;
Expand All @@ -238,7 +240,7 @@ public static unsafe void CopyManagedArray(string[] array, IntPtr data)
}
DisposeAbiArrayElements((array.Length, data));
int i = 0;
Func<bool> dispose = () => { DisposeAbiArrayElements((i, data)); return false; };
bool dispose() { DisposeAbiArrayElements((i, data)); return false; }
try
{
var length = array.Length;
Expand Down Expand Up @@ -550,7 +552,8 @@ public void Dispose()
{
return m;
}
Func<bool> dispose = () => { m.Dispose(); return false; };

bool dispose() { m.Dispose(); return false; }
try
{
int length = array.Length;
Expand Down Expand Up @@ -628,13 +631,13 @@ public static unsafe void CopyAbiArray(T[] array, object box)
}
IntPtr data = IntPtr.Zero;
int i = 0;
Func<bool> dispose = () =>
bool dispose()
{
DisposeAbiArray((i, data));
i = 0;
data = IntPtr.Zero;
return false;
};
}
try
{
int length = array.Length;
Expand Down Expand Up @@ -664,7 +667,7 @@ public static unsafe void CopyAbiArray(T[] array, object box)
}
DisposeAbiArrayElements((array.Length, data));
int i = 0;
Func<bool> dispose = () => { DisposeAbiArrayElements((i, data)); return false; };
bool dispose() { DisposeAbiArrayElements((i, data)); return false; }
try
{
int length = array.Length;
Expand Down Expand Up @@ -736,7 +739,8 @@ public static unsafe MarshalerArray CreateMarshalerArray(T[] array, Func<T, IObj
{
return m;
}
Func<bool> dispose = () => { m.Dispose(); return false; };

bool dispose() { m.Dispose(); return false; }
try
{
int length = array.Length;
Expand Down Expand Up @@ -806,13 +810,13 @@ public static unsafe (int length, IntPtr data) FromManagedArray(T[] array, Func<
}
IntPtr data = IntPtr.Zero;
int i = 0;
Func<bool> dispose = () =>
bool dispose()
{
DisposeAbiArray((i, data));
i = 0;
data = IntPtr.Zero;
return false;
};
}
try
{
int length = array.Length;
Expand Down Expand Up @@ -840,7 +844,7 @@ public static unsafe void CopyManagedArray(T[] array, IntPtr data, Action<T, Int
}
DisposeAbiArrayElements((array.Length, data));
int i = 0;
Func<bool> dispose = () => { DisposeAbiArrayElements((i, data)); return false; };
bool dispose() { DisposeAbiArrayElements((i, data)); return false; }
try
{
int length = array.Length;
Expand Down
4 changes: 2 additions & 2 deletions src/WinRT.Runtime/TypeNameSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d840c4b

Please sign in to comment.