public static Create ( string name, string type, string value ) : |
||
name | string | ハンドル名。 |
type | string | タイプ。 |
value | string | 値。 |
Результат |
private static IEnumerable <DrumPreset> DrumLoad(XDocument document) { var preset = document.Elements("ux").Select(e => e.Elements("preset")).Select(e => e.Elements("drum")).FirstOrDefault(); if (preset == null) { throw new ArgumentException(); } var notes = preset.Elements("note"); foreach (var note in notes) { var number = note.GetAttribute(PresetReader.xnumber); var note_number = note.GetAttribute(PresetReader.xnote); int num = 0, note_num = 0; if (!int.TryParse(number, out num)) { throw new ArgumentException(); } if (!int.TryParse(note_number, out note_num)) { throw new ArgumentException(); } yield return(new DrumPreset(num, note_num, note.Elements() .Where(h => h.Name.LocalName.ToLower() != "final") .Select(h => HandleCreator.Create(h.Name.LocalName.ToLower(), h.GetAttribute(PresetReader.xtype), h.GetAttribute(PresetReader.xvalue))))); } }
private static IEnumerable <ProgramPreset> Load(XDocument document) { var preset = document.Elements("ux").Select(e => e.Elements("preset")).FirstOrDefault(); if (preset == null) { throw new ArgumentException(); } var programs = preset.Elements("program"); foreach (var program in programs) { var number = program.GetAttribute(PresetReader.xnumber); var str_msb = program.GetAttribute(PresetReader.xmsb); var str_lsb = program.GetAttribute(PresetReader.xlsb); int num = 0, msb = 0, lsb = 0; if (!int.TryParse(number, out num)) { throw new ArgumentException(); } if (!string.IsNullOrWhiteSpace(str_msb) && !int.TryParse(str_msb, out msb)) { throw new ArgumentException(); } if (!string.IsNullOrWhiteSpace(str_lsb) && !int.TryParse(str_lsb, out lsb)) { throw new ArgumentException(); } if (program.Elements(PresetReader.xfinal).Count() > 1) { throw new ArgumentException(); } yield return(new ProgramPreset(num, msb, lsb, program.Elements() .Where(h => h.Name.LocalName.ToLower() != "final") .Select(h => HandleCreator.Create(h.Name.LocalName.ToLower(), h.GetAttribute(PresetReader.xtype), h.GetAttribute(PresetReader.xvalue))), program.Elements(PresetReader.xfinal) .SelectMany(f => f.Elements()) .Select(h => HandleCreator.Create(h.Name.LocalName.ToLower(), h.GetAttribute(PresetReader.xtype), h.GetAttribute(PresetReader.xvalue))))); } }