IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Instruction.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using System.Reflection;
4using System.Xml.Linq;
5
6using IKVM.Runtime;
7
9{
10
14 public abstract class Instruction : MapXmlElement
15 {
16
17 static readonly Dictionary<XName, MethodInfo> readMethodsByName;
18
22 static Instruction()
23 {
24 readMethodsByName = typeof(Instruction).Assembly.GetTypes()
25 .Where(i => i.IsSubclassOf(typeof(Instruction)))
26 .Where(i => i.GetCustomAttribute<InstructionAttribute>() is InstructionAttribute ia)
27 .Select(i => new { ElementName = MapXmlSerializer.NS + i.GetCustomAttribute<InstructionAttribute>().ElementName, Type = i })
28 .Select(i => new { i.ElementName, Method = i.Type.GetMethod("Read", BindingFlags.Public | BindingFlags.Static) })
29 .ToDictionary(i => i.ElementName, i => i.Method);
30 }
31
37 public static Instruction Read(XElement element)
38 {
39 if (readMethodsByName.TryGetValue(element.Name, out var m) == false)
40 throw new MapXmlException($"Could not find instruction type for '{element.Name}'.");
41
42 return (Instruction)m.Invoke(null, new[] { element });
43 }
44
50 internal abstract void Generate(CodeGenContext context, CodeEmitter ilgen);
51
52 }
53
54}
IKVM.Reflection.Type Type
Base class for MapXML instruction instances.
static Instruction Read(XElement element)
Reads the XML element into a new InstructionList instance.