Enable BHI1002 and fix noncompliance
"Do not use anonymous types (classes)"
This commit is contained in:
parent
eb4e8d6cd7
commit
a7db24490c
|
@ -5,7 +5,7 @@
|
|||
<Rule Id="BHI1001" Action="Error" />
|
||||
|
||||
<!-- Do not use anonymous types (classes) -->
|
||||
<Rule Id="BHI1002" Action="Hidden" />
|
||||
<Rule Id="BHI1002" Action="Error" />
|
||||
|
||||
<!-- Do not use query expression syntax -->
|
||||
<Rule Id="BHI1003" Action="Error" />
|
||||
|
|
|
@ -59,12 +59,8 @@ namespace BizHawk.BizInvoke
|
|||
public DelegateStorage(Type type)
|
||||
{
|
||||
var methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Select(m => new
|
||||
{
|
||||
Info = m,
|
||||
Attr = m.GetCustomAttributes(true).OfType<BizExportAttribute>().FirstOrDefault()
|
||||
})
|
||||
.Where(a => a.Attr != null);
|
||||
.Select(static m => (Info: m, Attr: m.GetCustomAttributes(true).OfType<BizExportAttribute>().FirstOrDefault()))
|
||||
.Where(static a => a.Attr is not null);
|
||||
|
||||
var typeBuilder = ImplModuleBuilder.DefineType($"Bizhawk.BizExvokeHolder{type.Name}", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Reflection.Emit;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
|
||||
namespace BizHawk.BizInvoke
|
||||
{
|
||||
|
@ -167,11 +168,7 @@ namespace BizHawk.BizInvoke
|
|||
}
|
||||
|
||||
var baseMethods = baseType.GetMethods(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Select(m => new
|
||||
{
|
||||
Info = m,
|
||||
Attr = m.GetCustomAttributes(true).OfType<BizImportAttribute>().FirstOrDefault()
|
||||
})
|
||||
.Select(static m => (Info: m, Attr: m.GetCustomAttributes(true).OfType<BizImportAttribute>().FirstOrDefault()))
|
||||
.Where(a => a.Attr != null)
|
||||
.ToList();
|
||||
|
||||
|
@ -181,19 +178,13 @@ namespace BizHawk.BizInvoke
|
|||
}
|
||||
|
||||
{
|
||||
var uo = baseMethods.FirstOrDefault(a => !a.Info.IsVirtual || a.Info.IsFinal);
|
||||
if (uo != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Method {uo.Info.Name} cannot be overriden!");
|
||||
}
|
||||
var uo = baseMethods.FirstOrNull(static a => !a.Info.IsVirtual || a.Info.IsFinal);
|
||||
if (uo is not null) throw new InvalidOperationException($"Method {uo.Value.Info.Name} cannot be overriden!");
|
||||
|
||||
// there's no technical reason to disallow this, but we wouldn't be doing anything
|
||||
// with the base implementation, so it's probably a user error
|
||||
var na = baseMethods.FirstOrDefault(a => !a.Info.IsAbstract);
|
||||
if (na != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Method {na.Info.Name} is not abstract!");
|
||||
}
|
||||
var na = baseMethods.FirstOrNull(static a => !a.Info.IsAbstract);
|
||||
if (na is not null) throw new InvalidOperationException($"Method {na.Value.Info.Name} is not abstract!");
|
||||
}
|
||||
|
||||
// hooks that will be run on the created proxy object
|
||||
|
|
|
@ -177,7 +177,7 @@ namespace BizHawk.BizInvoke
|
|||
{
|
||||
if (slots != null)
|
||||
{
|
||||
_slots = slots.Select((cb, i) => new { cb, i })
|
||||
_slots = slots.Select(static (cb, i) => (cb, i))
|
||||
.ToDictionary(a => a.cb, a => a.i, new ReferenceEqualityComparer());
|
||||
}
|
||||
_waterboxHost = waterboxHost;
|
||||
|
|
|
@ -335,11 +335,7 @@ namespace BizHawk.Client.Common
|
|||
var discs = m3u.Entries
|
||||
.Select(e => e.Path)
|
||||
.Where(p => Disc.IsValidExtension(Path.GetExtension(p)))
|
||||
.Select(path => new
|
||||
{
|
||||
d = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError)),
|
||||
p = path,
|
||||
})
|
||||
.Select(path => (p: path, d: DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError))))
|
||||
.Where(a => a.d != null)
|
||||
.Select(a => (IDiscAsset)new DiscAsset
|
||||
{
|
||||
|
@ -540,11 +536,7 @@ namespace BizHawk.Client.Common
|
|||
.ToList(),
|
||||
Discs = xmlGame.AssetFullPaths
|
||||
.Where(p => Disc.IsValidExtension(Path.GetExtension(p)))
|
||||
.Select(path => new
|
||||
{
|
||||
d = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, system, LoadErrorType.DiscError)),
|
||||
p = path,
|
||||
})
|
||||
.Select(path => (p: path, d: DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, system, LoadErrorType.DiscError))))
|
||||
.Where(a => a.d != null)
|
||||
.Select(a => (IDiscAsset)new DiscAsset
|
||||
{
|
||||
|
|
|
@ -9,6 +9,22 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class TasBranch
|
||||
{
|
||||
internal struct ForSerialization
|
||||
{
|
||||
public readonly int Frame;
|
||||
|
||||
public readonly DateTime TimeStamp;
|
||||
|
||||
public readonly Guid UniqueIdentifier;
|
||||
|
||||
public ForSerialization(int frame, DateTime timeStamp, Guid uniqueIdentifier)
|
||||
{
|
||||
Frame = frame;
|
||||
TimeStamp = timeStamp;
|
||||
UniqueIdentifier = uniqueIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
public int Frame { get; set; }
|
||||
public byte[] CoreData { get; set; }
|
||||
public IStringLog InputLog { get; set; }
|
||||
|
@ -20,6 +36,8 @@ namespace BizHawk.Client.Common
|
|||
public Guid Uuid { get; set; }
|
||||
public string UserText { get; set; }
|
||||
|
||||
internal ForSerialization ForSerial => new(Frame, TimeStamp, Uuid);
|
||||
|
||||
public TasBranch Clone() => (TasBranch)MemberwiseClone();
|
||||
}
|
||||
|
||||
|
@ -123,16 +141,7 @@ namespace BizHawk.Client.Common
|
|||
var nusertext = new IndexedStateLump(BinaryStateLump.BranchUserText);
|
||||
foreach (var b in this)
|
||||
{
|
||||
bs.PutLump(nheader, tw =>
|
||||
{
|
||||
// if this header needs more stuff in it, handle it sensibly
|
||||
tw.WriteLine(JsonConvert.SerializeObject(new
|
||||
{
|
||||
b.Frame,
|
||||
b.TimeStamp,
|
||||
UniqueIdentifier = b.Uuid
|
||||
}));
|
||||
});
|
||||
bs.PutLump(nheader, tw => tw.WriteLine(JsonConvert.SerializeObject(b.ForSerial)));
|
||||
|
||||
bs.PutLump(ncore, (Stream s) => s.Write(b.CoreData, 0, b.CoreData.Length));
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.CustomControls;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
|
||||
// TODO: There are some bad interactions between ScrollToIndex and MakeIndexVisible that are preventing things from working as intended.
|
||||
// But, the current behaviour is ok for now for what it is used for.
|
||||
|
@ -1891,8 +1892,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (_horizontalOrientation)
|
||||
{
|
||||
return _columns.VisibleColumns.Select((n, i) => new { Column = n, Index = i })
|
||||
.FirstOrDefault(item => (GetHColTop(item.Index) - _vBar.Value).RangeTo(GetHColBottom(item.Index) - _vBar.Value).Contains(pixel))
|
||||
return _columns.VisibleColumns.Select(static (n, i) => (Column: n, Index: i))
|
||||
.FirstOrNull(item => (GetHColTop(item.Index) - _vBar.Value).RangeTo(GetHColBottom(item.Index) - _vBar.Value).Contains(pixel))
|
||||
?.Column;
|
||||
}
|
||||
return _columns.VisibleColumns.FirstOrDefault(column => (column.Left - _hBar.Value).RangeTo(column.Right - _hBar.Value).Contains(pixel));
|
||||
|
|
|
@ -382,11 +382,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (!Engaged()) return _th.CreateTable();
|
||||
return _th.EnumerateToLuaTable(
|
||||
Tastudio.CurrentTasMovie.Branches.Select(b => new
|
||||
Tastudio.CurrentTasMovie.Branches.Select(b =>
|
||||
{
|
||||
Id = b.Uuid.ToString(),
|
||||
b.Frame,
|
||||
Text = UnFixString(b.UserText)
|
||||
var table = _th.CreateTable();
|
||||
table["Id"] = b.Uuid.ToString();
|
||||
table["Frame"] = b.Frame;
|
||||
table["Text"] = UnFixString(b.UserText);
|
||||
return table;
|
||||
}),
|
||||
indexFrom: 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue