public static SWinKeyInfo[] GetWinKeyInfos(IKey inWinKeyParent, CWindowTypeDescrs inWindowTypeDescrs, ILogPrinter inLogger) { int count = inWinKeyParent.GetChildCount(); List <SWinKeyInfo> res = new List <SWinKeyInfo>(count); for (int i = 0; i < count; i++) { IKey window_key = inWinKeyParent.GetChild(i); var info = new SWinKeyInfo(); info.WinKey = window_key; info.Name = Utils.GetWindowNameFromKey(window_key, i.ToString(), inLogger); string[] a = Utils.TryGetParamsByNameFromSubKey("Type", window_key, inLogger, true, 1); if (a.Length > 0) { string stype = a[0]; NamedId?id = inWindowTypeDescrs.GetWinType(stype); if (id.HasValue) { info.WinType = id.Value; res.Add(info); } else { inLogger.LogError(string.Format("Undefined type. Key [{0}]!", window_key.GetPath())); } } } return(res.ToArray()); }
public static string[] TryGetParamsByNameFromSubKey(string inKeyName, IKey inKey, ILogPrinter inLogger, bool inSubKeyMustBe, params int[] inParamCounts) { IKey sub_key = inKey.FindChildByName(inKeyName, StringComparison.InvariantCultureIgnoreCase); if (sub_key == null) { if (inSubKeyMustBe) { inLogger.LogError(string.Format("Can't find subkey by name. Key [{0}] must have subkey {1}!", inKey.GetPath(), inKeyName)); } return(null); } int value_count = sub_key.GetValuesCount(); if (!inParamCounts.ContainsCheck(value_count)) { string counts = inParamCounts.ToString(", "); inLogger.LogError(string.Format("Subkey [{0}] must have [{1}] counts of values, but was found {2}", sub_key.GetPath(), counts, value_count)); return(null); } var a = new string[value_count]; for (int i = 0; i < value_count; i++) { a[i] = sub_key.GetValueAsString(i); } return(a); }
object DeserializeAtomic(object inInstance, IKey inKey, Type type, int inStructDeep, ILogPrinter inLogger) { object instance; IKey key = inKey; if (key.GetValuesCount() == 0) { instance = ReflectionHelper.GetDefaultValue(type, _reflectionProvider, inLogger); } else if (key.GetValuesCount() > 1) { var sb = new StringBuilder(); sb.Append("\""); for (int i = 0; i < key.GetValuesCount(); ++i) { if (i > 0) { sb.Append(","); } sb.Append(key.GetValueAsString(i)); } sb.Append("\""); LogError(inLogger, string.Format("Need one value for type {1}. Key: {0} [{3}]; Values: {2} ", key, type.Name, sb, key.GetPath())); instance = ReflectionHelper.GetDefaultValue(type, _reflectionProvider, inLogger); } else { string key_value = key.GetValueAsString(0); if (!ReflectionHelper.StringToAtomicValue(key_value, type, out instance, _reflectionProvider, inLogger)) { LogError(inLogger, string.Format("Key {0} [{3}] with value {1} can't convert value to type {2}", key, key_value, type.Name, key.GetPath())); instance = ReflectionHelper.GetDefaultValue(type, _reflectionProvider, inLogger); } } return(instance); }
object DeserializeArray(IKey inKey, Type type, int inStructDeep, ILogPrinter inLogger) { if (inKey.IsEmpty) { return(null); } IKey key = inKey; Array multi_dim_array = null; Type declaredItemType = type.GetElementType(); bool is_atomic_elems = declaredItemType.IsAtomic(); bool is_array_elems = declaredItemType.IsArray; int[] dims; if (is_array_elems) { dims = new int[] { key.GetChildCount() } } ; else { dims = FindArrayDimension(key, is_atomic_elems); } if (dims.Length == 0) { return(null); } object instance = Array.CreateInstance(declaredItemType, dims); multi_dim_array = instance as Array; CMultiArrayIndexer indexer = new CMultiArrayIndexer(multi_dim_array); while (indexer.MoveNext()) { IKey dim_child = GetKeyByArrayIndex(key, indexer.Current); if (dim_child == null) { LogError(inLogger, string.Format("Cant get value for multi array index {0}", indexer)); } else { object obj_value; int last_index = indexer.Current[indexer.Current.Length - 1]; if (is_atomic_elems) { string str_value; if (dim_child.GetValuesCount() == 0) { str_value = string.Empty; } else { str_value = dim_child.GetValueAsString(last_index); } if (!ReflectionHelper.StringToAtomicValue(str_value, declaredItemType, out obj_value, _reflectionProvider, inLogger)) { LogError(inLogger, string.Format("Key {0} [{3}] for collection with element type {1} can't convert value {2}", key, declaredItemType.Name, str_value, key.GetPath())); } } else { IKey child = dim_child.GetChild(last_index); obj_value = DeserializeInternal(null, child, declaredItemType, 0, inStructDeep + 1, inLogger); } multi_dim_array.SetValue(obj_value, indexer.Current); } } return(instance); }
public void DeserializationFromCscd(IKey key, ILogPrinter inLogger) { if (key.GetValuesCount() == 0) { inLogger.LogError(string.Format("NamedId.CscdConverter: Key {0} hasnt value!", key.GetPath())); return; } string n = key.GetValue(0).ToString(); NamedId nid = GetNamedId(n); id = nid.id; name = nid.name; }