public static SaveableDict <T, U> From(Dictionary <T, U> dict)
        {
            DictItem[] items = new DictItem[dict.Count];
            int        i     = 0;

            foreach (var pair in dict)
            {
                items[i] = new DictItem(pair.Key, pair.Value);
                i++;
            }

            return(new SaveableDict <T, U>(items));
        }
Beispiel #2
0
            private bool GetDictState(out CorruptionState keyState, out string infoKey, out CorruptionState valueState, out string infoValue)
            {
                infoKey    = string.Empty;
                infoValue  = string.Empty;
                keyState   = CorruptionState.None;
                valueState = CorruptionState.None;

                if (IsDict)
                {
                    if (_dictValue.Value.Items.Length > 0)
                    {
                        if (_keyEntry.TryGetExpectedDictTypes(out Type expectedKeyType, out Type expectedValueType))
                        {
                            DictItem item   = _dictValue.Value.Items[0];
                            Type     tKey   = item.KeySection.GetSafeValueType();
                            Type     tValue = item.ValueSection.GetSafeValueType();

                            keyState   = tKey != null && expectedKeyType.IsAssignableFrom(tKey) ? CorruptionState.None : CorruptionState.Error;
                            valueState = tValue != null && expectedValueType.IsAssignableFrom(tValue) ? CorruptionState.None : CorruptionState.Error;

                            if (keyState == CorruptionState.Error)
                            {
                                if (tKey == null)
                                {
                                    infoKey = TYPE_NOT_FOUND_INFO_MESSAGE;
                                }
                                else
                                {
                                    infoKey = string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, expectedKeyType.Name, tKey.Name);
                                }
                            }

                            if (valueState == CorruptionState.Error)
                            {
                                if (tValue == null)
                                {
                                    infoValue = TYPE_NOT_FOUND_INFO_MESSAGE;
                                }
                                else
                                {
                                    infoValue = string.Format(EXPECTED_TYPE_INFO_MESSAGE_F, expectedValueType.Name, tValue.Name);
                                }
                            }
                        }
                    }

                    return(true);
                }

                return(false);
            }