public static ControlBaseData Greate(int id, Dictionary <string, string> values) { if (!derivedClasses.TryGetValue(values[nameof(Type)], out ControlBaseData factory)) { throw new ArgumentException($"Tипа {values[nameof(Type)]} нет", nameof(values)); } ControlBaseData controlBase = factory.CreateInstanceCore(id); controlBase.SetValues(values); return(controlBase); }
protected static void AddDerivedClasses(ControlBaseData control) { if (derivedClasses.TryGetValue(control.Type.TypeName, out ControlBaseData controlBase)) { if (control.GetType() != controlBase.GetType()) { throw new ArgumentException($"Тип {controlBase.GetType()} с таким ControlType.TypeName={controlBase.Type} уже добавлен, но отличается от переданного.", nameof(control)); } } else { derivedClasses.Add(control.Type.TypeName, control); } }
public Dictionary <int, ControlBaseData> GetData() { Dictionary <int, ControlBaseData> dict = new Dictionary <int, ControlBaseData>(); HashSet <string> names = new HashSet <string>(); foreach (var item in data) { string name = item.Value[nameof(ControlData.Name)]; if (names.Contains(name)) { throw new Exception("У элементов одинаковые имена."); } names.Add(name); ControlBaseData control = ControlBaseData.Greate(item.Key, item.Value); dict.Add(control.Id, control); } return(dict); }