Skip to content

Commit 6564004

Browse files
committed
Autoformat with var when type is apparent false
1 parent 02e7de7 commit 6564004

File tree

1,324 files changed

+9243
-16503
lines changed

Some content is hidden

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

1,324 files changed

+9243
-16503
lines changed

.editorconfig

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ csharp_indent_switch_labels = true
1212
csharp_indent_case_contents = true
1313
csharp_indent_labels = one_less_than_current
1414

15-
# Style rules
16-
# Can't be in .globalconfig because dotnet format doesn't respect that https://github.com/dotnet/format/issues/1643
17-
dotnet_diagnostic.IDE0039.severity = none
1815
# Globalization rules
1916
dotnet_code_quality.CA1305.excluded_symbol_names = T:System.Byte|T:System.SByte|T:System.Int16|T:System.UInt16|T:System.Int32|T:System.UInt32|T:System.Int64|T:System.UInt64|T:System.String|T:System.Text.StringBuilder|T:System.Convert
2017

18+
# Style rules
19+
# Can't be in .globalconfig because dotnet format doesn't respect that https://github.com/dotnet/format/issues/1643
2120
# Remove unnecessary cast
2221
dotnet_diagnostic.IDE0004.severity = warning
2322
# Remove unnecessary import
@@ -52,6 +51,8 @@ dotnet_diagnostic.IDE0032.severity = suggestion
5251
dotnet_diagnostic.IDE0034.severity = suggestion
5352
# Use pattern matching to avoid is check followed by a cast (without variable)
5453
dotnet_diagnostic.IDE0038.severity = warning
54+
# Use a local function instead of an anonymous function
55+
dotnet_diagnostic.IDE0039.severity = none
5556
# Use is null check
5657
dotnet_diagnostic.IDE0041.severity = warning
5758
# Deconstruct variable declaration
@@ -112,7 +113,7 @@ dotnet_diagnostic.IDE0260.severity = suggestion
112113
# Use nameof
113114
dotnet_diagnostic.IDE0280.severity = error
114115

115-
csharp_style_var_when_type_is_apparent = true
116+
csharp_style_var_when_type_is_apparent = false
116117
csharp_style_var_elsewhere = true
117118

118119
csharp_style_expression_bodied_methods = when_on_single_line

src/BizHawk.BizInvoke/BizExvoker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class BizExvoker
2323

2424
static BizExvoker()
2525
{
26-
var aname = new AssemblyName("BizExvokeProxyAssembly");
26+
AssemblyName aname = new AssemblyName("BizExvokeProxyAssembly");
2727
ImplAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(aname, AssemblyBuilderAccess.Run);
2828
ImplModuleBuilder = ImplAssemblyBuilder.DefineDynamicModule("BizExvokerModule");
2929
}
@@ -85,7 +85,7 @@ public ExvokerImpl(object o, DelegateStorage d, ICallingConventionAdapter a)
8585
{
8686
foreach (var sdt in d.DelegateTypes)
8787
{
88-
var del = Delegate.CreateDelegate(sdt.DelegateType, o, sdt.Method);
88+
Delegate del = Delegate.CreateDelegate(sdt.DelegateType, o, sdt.Method);
8989
Delegates.Add(del); // prevent garbage collection of the delegate, which would invalidate the pointer
9090
EntryPoints.Add(sdt.EntryPointName, a.GetFunctionPointerForDelegate(del));
9191
}

src/BizHawk.BizInvoke/BizInvokeUtilities.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ public static TypeBuilder CreateDelegateType(MethodInfo method, CallingConventio
4747
for (int i = 0; i < paramInfos.Length; i++)
4848
{
4949
var p = delegateInvoke.DefineParameter(i + 1, ParameterAttributes.None, paramInfos[i].Name);
50-
foreach (var a in paramInfos[i].GetCustomAttributes(false))
50+
foreach (object? a in paramInfos[i].GetCustomAttributes(false))
5151
{
5252
p.SetCustomAttribute(GetAttributeBuilder(a));
5353
}
5454
}
5555

5656
{
5757
var p = delegateInvoke.DefineParameter(0, ParameterAttributes.Retval, method.ReturnParameter!.Name);
58-
foreach (var a in method.ReturnParameter.GetCustomAttributes(false))
58+
foreach (object? a in method.ReturnParameter.GetCustomAttributes(false))
5959
{
6060
p.SetCustomAttribute(GetAttributeBuilder(a));
6161
}
6262
}
6363

64-
delegateInvoke.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
65-
66-
// add the [UnmanagedFunctionPointer] to the delegate so interop will know how to call it
67-
var attr = new CustomAttributeBuilder(
64+
delegateInvoke.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
65+
66+
// add the [UnmanagedFunctionPointer] to the delegate so interop will know how to call it
67+
CustomAttributeBuilder attr = new CustomAttributeBuilder(
6868
typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new[] { typeof(CallingConvention) })!,
6969
new object[] { nativeCall });
7070
delegateType.SetCustomAttribute(attr);

src/BizHawk.BizInvoke/BizInvoker.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public InvokerImpl(
5252

5353
public object Create(IImportResolver dll, IMonitor? monitor, ICallingConventionAdapter adapter)
5454
{
55-
var ret = Activator.CreateInstance(_implType)!;
55+
object ret = Activator.CreateInstance(_implType)!;
5656
_connectCallingConventionAdapter(ret, adapter);
5757
foreach (var f in _hooks)
5858
{
@@ -93,7 +93,7 @@ public object Create(IImportResolver dll, IMonitor? monitor, ICallingConventionA
9393

9494
static BizInvoker()
9595
{
96-
var aname = new AssemblyName("BizInvokeProxyAssembly");
96+
AssemblyName aname = new AssemblyName("BizInvokeProxyAssembly");
9797
ImplAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(aname, AssemblyBuilderAccess.Run);
9898
ImplModuleBuilder = ImplAssemblyBuilder.DefineDynamicModule("BizInvokerModule");
9999
ClassFieldOffset = BizInvokerUtilities.ComputeClassFirstFieldOffset();
@@ -109,7 +109,7 @@ static BizInvoker()
109109
public static T GetInvoker<T>(IImportResolver dll, ICallingConventionAdapter adapter)
110110
where T : class
111111
{
112-
var nonTrivialAdapter = adapter.GetType() != CallingConventionAdapters.Native.GetType();
112+
bool nonTrivialAdapter = adapter.GetType() != CallingConventionAdapters.Native.GetType();
113113
InvokerImpl impl;
114114
lock (Impls) impl = Impls.GetValueOrPut(
115115
typeof(T),
@@ -126,7 +126,7 @@ public static T GetInvoker<T>(IImportResolver dll, ICallingConventionAdapter ada
126126
public static T GetInvoker<T>(IImportResolver dll, IMonitor monitor, ICallingConventionAdapter adapter)
127127
where T : class
128128
{
129-
var nonTrivialAdapter = adapter.GetType() != CallingConventionAdapters.Native.GetType();
129+
bool nonTrivialAdapter = adapter.GetType() != CallingConventionAdapters.Native.GetType();
130130
InvokerImpl impl;
131131
lock (Impls) impl = Impls.GetValueOrPut(
132132
typeof(T),
@@ -153,7 +153,7 @@ private static InvokerImpl CreateProxy(Type baseType, bool monitor, bool nonTriv
153153
}
154154

155155
var baseConstructor = baseType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null) ?? throw new InvalidOperationException("Base type must have a zero arg constructor");
156-
var baseMethods = baseType.GetMethods(BindingFlags.Instance | BindingFlags.Public)
156+
List<(MethodInfo Info, BizImportAttribute Attr)> baseMethods = baseType.GetMethods(BindingFlags.Instance | BindingFlags.Public)
157157
.Select(static m => (Info: m, Attr: m.GetCustomAttributes(true).OfType<BizImportAttribute>().FirstOrDefault()))
158158
.Where(a => a.Attr != null)
159159
.ToList();
@@ -174,7 +174,7 @@ private static InvokerImpl CreateProxy(Type baseType, bool monitor, bool nonTriv
174174
}
175175

176176
// hooks that will be run on the created proxy object
177-
var postCreateHooks = new List<Action<object, IImportResolver, ICallingConventionAdapter>>();
177+
List<Action<object, IImportResolver, ICallingConventionAdapter>> postCreateHooks = new List<Action<object, IImportResolver, ICallingConventionAdapter>>();
178178

179179
var type = ImplModuleBuilder.DefineType($"Bizhawk.BizInvokeProxy{baseType.Name}", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, baseType);
180180

@@ -184,7 +184,7 @@ private static InvokerImpl CreateProxy(Type baseType, bool monitor, bool nonTriv
184184

185185
foreach (var (Info, Attr) in baseMethods)
186186
{
187-
var entryPointName = Attr!.EntryPoint ?? Info.Name;
187+
string entryPointName = Attr!.EntryPoint ?? Info.Name;
188188

189189
var hook = Attr.Compatibility
190190
? ImplementMethodDelegate(type, Info, Attr.CallingConvention, entryPointName, monitorField, nonTrivialAdapter)
@@ -331,7 +331,7 @@ private static Action<object, IImportResolver, ICallingConventionAdapter> Implem
331331
{
332332
var paramInfos = baseMethod.GetParameters();
333333
var paramTypes = paramInfos.Select(p => p.ParameterType).ToArray();
334-
var paramLoadInfos = new List<ParameterLoadInfo>();
334+
List<ParameterLoadInfo> paramLoadInfos = new List<ParameterLoadInfo>();
335335
var returnType = baseMethod.ReturnType;
336336
if (returnType != typeof(void) && !returnType.IsPrimitive && !returnType.IsPointer && !returnType.IsEnum)
337337
{
@@ -376,7 +376,7 @@ private static Action<object, IImportResolver, ICallingConventionAdapter> Implem
376376

377377
bool WantsWinAPIBool()
378378
{
379-
var attrs = baseMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(MarshalAsAttribute), false);
379+
object[] attrs = baseMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(MarshalAsAttribute), false);
380380
return attrs.Length > 0 && ((MarshalAsAttribute)attrs[0]).Value is UnmanagedType.Bool;
381381
}
382382

src/BizHawk.BizInvoke/BizInvokerUtilities.cs

+9-12
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,15 @@ private class CF
5050
/// Computes the byte offset of the first field of any class relative to a class pointer.
5151
/// </summary>
5252
/// <returns></returns>
53-
public static int ComputeClassFirstFieldOffset()
54-
{
55-
return ComputeFieldOffset(typeof(CF).GetField("FirstField"));
56-
}
53+
public static int ComputeClassFirstFieldOffset() => ComputeFieldOffset(typeof(CF).GetField("FirstField"));
5754

5855
/// <summary>
5956
/// Compute the byte offset of the first byte of string data (UTF16) relative to a pointer to the string.
6057
/// </summary>
6158
/// <returns></returns>
6259
public static int ComputeStringOffset()
6360
{
64-
var s = new string(Array.Empty<char>());
61+
string s = new string(Array.Empty<char>());
6562
int ret;
6663
fixed(char* fx = s)
6764
{
@@ -77,7 +74,7 @@ public static int ComputeStringOffset()
7774
/// <returns></returns>
7875
public static int ComputeValueArrayElementOffset()
7976
{
80-
var arr = new int[4];
77+
int[] arr = new int[4];
8178
int ret;
8279
fixed (int* p = arr)
8380
{
@@ -94,8 +91,8 @@ public static int ComputeValueArrayElementOffset()
9491
/// <returns></returns>
9592
public static int ComputeObjectArrayElementOffset()
9693
{
97-
var obj = new object[4];
98-
var method = new DynamicMethod("ComputeObjectArrayElementOffsetHelper", typeof(int), new[] { typeof(object[]) }, typeof(string).Module, true);
94+
object[] obj = new object[4];
95+
DynamicMethod method = new DynamicMethod("ComputeObjectArrayElementOffsetHelper", typeof(int), new[] { typeof(object[]) }, typeof(string).Module, true);
9996
var il = method.GetILGenerator();
10097
var local = il.DeclareLocal(typeof(object[]), true);
10198
il.Emit(OpCodes.Ldarg_0);
@@ -109,7 +106,7 @@ public static int ComputeObjectArrayElementOffset()
109106
il.Emit(OpCodes.Sub);
110107
il.Emit(OpCodes.Conv_I4);
111108
il.Emit(OpCodes.Ret);
112-
var del = (Func<object[], int>)method.CreateDelegate(typeof(Func<object[], int>));
109+
Func<object[], int> del = (Func<object[], int>)method.CreateDelegate(typeof(Func<object[], int>));
113110
return del(obj);
114111
}
115112

@@ -124,8 +121,8 @@ public static int ComputeFieldOffset(FieldInfo fi)
124121
throw new NotImplementedException("Only supported for class fields right now");
125122
}
126123

127-
var obj = FormatterServices.GetUninitializedObject(fi.DeclaringType);
128-
var method = new DynamicMethod("ComputeFieldOffsetHelper", typeof(int), new[] { typeof(object) }, typeof(string).Module, true);
124+
object obj = FormatterServices.GetUninitializedObject(fi.DeclaringType);
125+
DynamicMethod method = new DynamicMethod("ComputeFieldOffsetHelper", typeof(int), new[] { typeof(object) }, typeof(string).Module, true);
129126
var il = method.GetILGenerator();
130127
var local = il.DeclareLocal(fi.DeclaringType, true);
131128
il.Emit(OpCodes.Ldarg_0);
@@ -138,7 +135,7 @@ public static int ComputeFieldOffset(FieldInfo fi)
138135
il.Emit(OpCodes.Sub);
139136
il.Emit(OpCodes.Conv_I4);
140137
il.Emit(OpCodes.Ret);
141-
var del = (Func<object, int>)method.CreateDelegate(typeof(Func<object, int>));
138+
Func<object, int> del = (Func<object, int>)method.CreateDelegate(typeof(Func<object, int>));
142139
return del(obj);
143140
}
144141
}

0 commit comments

Comments
 (0)