public void Apply(CSStruct s) { foreach (var pf in Fields) { foreach (var f in s.Fields) { if (f.Name == pf.Name) { pf.Apply(f); } } } }
void WriteHandle(StreamWriter writer, CSStruct s) { writer.WriteLine(" public struct {0} : IEquatable<{0}> {{", s.Name); foreach (var f in s.Fields) { writer.WriteLine(" public {0} {1};", f.Type, f.Name); } writer.WriteLine( @" public static {0} Null {{ get; }} = new {0}(); public override bool Equals(object other) {{ if (other is {0}) {{ return Equals(({0})other); }} return false; }} public bool Equals({0} other) {{ return other.native == native; }} public static bool operator == ({0} a, {0} b) {{ return a.Equals(b); }} public static bool operator != ({0} a, {0} b) {{ return !(a == b); }} public override int GetHashCode() {{ return native.GetHashCode(); }}", s.Name); writer.WriteLine(" }"); writer.WriteLine(); }
public CSSpec(Spec spec, Patch patch) { Structs = new List <CSStruct>(); Enums = new List <CSEnum>(); Commands = new List <CSCommand>(); EnumMap = new Dictionary <string, CSEnum>(); FlagsMap = new Dictionary <string, string>(); foreach (var s in spec.Structs) { if (spec.ExtensionTypes.Contains(s.Name) && !spec.IncludedTypes.Contains(s.Name)) { continue; } var css = new CSStruct(s); Structs.Add(css); } foreach (var e in spec.Enums) { if (spec.ExtensionTypes.Contains(e.Name) && !spec.IncludedTypes.Contains(e.Name)) { continue; } var cse = new CSEnum(e); if (cse.Name.Contains("Flags")) { cse.Values.Add(new CSEnumValue(cse.Name, "None", "0")); } Enums.Add(cse); EnumMap.Add(cse.Name, cse); } foreach (var c in spec.Commands) { if (!spec.IncludedCommands.Contains(c.Name)) { continue; } var csc = new CSCommand(spec, c); Commands.Add(csc); } foreach (var s in Structs) { foreach (var ps in patch.Structs) { if (ps.Name == s.Name) { ps.Apply(s); } } } foreach (var c in Commands) { foreach (var pc in patch.Commands) { if (pc.Name == c.Name) { pc.Apply(c); } } } FixEnums(); }