Create a FeatureNotImplemented attribute, the intend of which is to apply to any unimplemented method of an ICoreService method/property, set some methods in Intellivision to this, and have CoreFeatureAnalysis look for the presence of this attribute and report unimplemented properties/methods

This commit is contained in:
adelikat 2014-11-24 00:38:29 +00:00
parent 56d425d49f
commit bded999177
4 changed files with 72 additions and 9 deletions

View File

@ -90,22 +90,54 @@ namespace BizHawk.Client.EmuHawk
ForeColor = isImplemented ? Color.Black : Color.Red
};
bool fullyImplementedInterface = isImplemented;
if (isImplemented)
{
foreach (var field in service.GetProperties())
foreach (var field in service.GetMethods().OrderBy(f => f.Name))
{
serviceNode.Nodes.Add(new TreeNode
try
{
Text = field.Name
});
var coreImplementation = core.CoreType.GetMethod(field.Name);
if (coreImplementation != null)
{
var i = coreImplementation.IsImplemented();
serviceNode.Nodes.Add(new TreeNode
{
Text = field.Name,
ImageKey = i ? "Good" : "Bad",
SelectedImageKey = i ? "Good" : "Bad",
StateImageKey = i ? "Good" : "Bad"
});
if (!i)
{
fullyImplementedInterface = false;
}
}
}
catch (Exception ex)
{
// TODO: SavestateBinary() and SaveStateBinary(BinaryWriter bw) cause an exception, need to look at signature too
}
}
foreach (var field in service.GetMethods())
foreach (var field in service.GetProperties().OrderBy(f => f.Name))
{
var i = field.IsImplemented();
serviceNode.Nodes.Add(new TreeNode
{
Text = field.Name
Text = field.Name,
ImageKey = i ? "Good" : "Bad",
SelectedImageKey = i ? "Good" : "Bad",
StateImageKey = i ? "Good" : "Bad"
});
if (!i)
{
fullyImplementedInterface = false;
}
}
}
else
@ -113,10 +145,12 @@ namespace BizHawk.Client.EmuHawk
missingImplementation = true;
}
serviceNode.StateImageKey = serviceNode.SelectedImageKey = serviceNode.ImageKey = fullyImplementedInterface ? "Good" : "Bad";
coreNode.Nodes.Add(serviceNode);
}
coreNode.ImageKey = missingImplementation ? "Bad" : "Good";
coreNode.StateImageKey = coreNode.SelectedImageKey = coreNode.ImageKey = missingImplementation ? "Bad" : "Good";
CoreTree.Nodes.Add(coreNode);
}

View File

@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
namespace BizHawk.Emulation.Common.IEmulatorExtensions
{
@ -13,5 +15,16 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
{
return core is IMemoryDomains;
}
// TODO: a better place for these
public static bool IsImplemented(this MethodInfo info)
{
return !info.GetCustomAttributes(false).OfType<FeatureNotImplemented>().Any();
}
public static bool IsImplemented(this PropertyInfo info)
{
return !info.GetCustomAttributes(false).OfType<FeatureNotImplemented>().Any();
}
}
}

View File

@ -1,4 +1,6 @@
namespace BizHawk.Emulation.Common
using System;
namespace BizHawk.Emulation.Common
{
/// <summary>
/// This interface specifies that an interface or implementation is a emulator core service, such as IDebuggable,
@ -8,4 +10,13 @@
public interface ICoreService
{
}
/// <summary>
/// Should be added to any field of an ICoreService that is not implemented. By Convention it should also throw a NotImplementedException
/// Any feature that does not have this attribute is assumed to be implemented
/// </summary>
public class FeatureNotImplemented : Attribute
{
public FeatureNotImplemented() { }
}
}

View File

@ -168,29 +168,34 @@ namespace BizHawk.Emulation.Cores.Intellivision
//IsLagFrame = false;
}
[FeatureNotImplemented]
public void SaveStateText(TextWriter writer)
{
throw new NotImplementedException();
}
[FeatureNotImplemented]
public void LoadStateText(TextReader reader)
{
throw new NotImplementedException();
}
[FeatureNotImplemented]
public void SaveStateBinary(BinaryWriter writer)
{
throw new NotImplementedException();
}
[FeatureNotImplemented]
public void LoadStateBinary(BinaryReader reader)
{
throw new NotImplementedException();
}
[FeatureNotImplemented]
public byte[] SaveStateBinary()
{
return new byte[0];
throw new NotImplementedException();
}
public bool BinarySaveStatesPreferred { get { return false; } }