private void AddToData(P21Instance p21Instance) { if (p21Instance.EIN == 0) { MessageBox.Show("what?"); } _dataSection.TryAdd(p21Instance.EIN, p21Instance); var name = p21Instance.GetType().Name; if (!_dataByType.ContainsKey(name)) { _dataByType.TryAdd(name, new ConcurrentDictionary<uint, P21Instance>()); } _dataByType[p21Instance.GetType().Name].TryAdd(p21Instance.EIN, p21Instance); }
private void ConvertAttribute(Parameter att, P21Instance p21Instance) { if (att.ParameterType == SParamType.UNSET) return; var attName = att.SchemaAttDef.Name; FieldInfo fieldInfo = p21Instance.GetType().GetField(attName); object attribute = ConvertSwitch(p21Instance, att); if (attribute == null) return; if (fieldInfo.FieldType.IsClass) fieldInfo.SetValue(p21Instance, attribute); else { if (fieldInfo.FieldType == attribute.GetType()) { fieldInfo.SetValue(p21Instance, attribute); } else { Type tSelect = fieldInfo.FieldType; var selectAtt = Activator.CreateInstance(tSelect); tSelect.GetField("Value").SetValue(selectAtt, attribute); fieldInfo.SetValue(p21Instance, selectAtt); } } }
public static uint Add(uint index, P21Instance p21Instance) { if (p21Instance == null) return 0; if (Instance._dataSection.ContainsKey(index)) return 0; if (!Instance._dataSection.TryAdd(index, p21Instance)) return 0; var name = p21Instance.GetType().Name; if (!Instance._dataByType.ContainsKey(name)) { Instance._dataByType.TryAdd(name, new ConcurrentDictionary<uint, P21Instance>()); } Instance._dataByType[p21Instance.GetType().Name].TryAdd(p21Instance.EIN, p21Instance); p21Instance.EIN = index; foreach (FieldInfo field in p21Instance.GetType().GetFields()) { var ins = field.GetValue(p21Instance) as P21Instance; if (ins != null) { Add(ins); continue; } if (field.FieldType.IsValueType) { var sel = field.GetValue(p21Instance); var selval = sel.GetType().GetField("Value"); if (selval != null) { var select = selval.GetValue(sel) as P21Instance; if (select != null) { Add(select); continue; } } } if (!field.FieldType.IsGenericType) continue; var listIns = field.GetValue(p21Instance) as IList; if (listIns == null) continue; foreach (var instance in listIns) { //if(instance == null) continue; if (instance.GetType().IsSubclassOf(typeof(P21Instance))) { Add((P21Instance)instance); continue; } var valField = instance.GetType().GetField("Value"); if (valField != null) { var select = valField.GetValue(instance) as P21Instance; if (select != null) { Add(select); continue; } } } //string a = listIns.ToString(); } return p21Instance.EIN; }