public SerializableValue PickChild(SerializableValue target, string language = TranslationManager.DefaultLanguage) { SerializableValue PickStringValue(string name) { switch (name) { case "Length": return(new IntegerValue { value = _integerValues.Max(e => e.Key) }); case "ArrayCount": return(new IntegerValue { value = _integerValues.Count }); case "KeyCount": return(new IntegerValue { value = _stringValues.Count }); default: return(_stringValues.ContainsKey(name) ? _stringValues[name] : null); } } SerializableValue result; switch (target) { case IntegerValue integerMemoryValue: result = _integerValues.ContainsKey(integerMemoryValue.value) ? _integerValues[integerMemoryValue.value] : null; break; case StringValue stringMemoryValue: result = PickStringValue(stringMemoryValue.value); break; case IIntegerConverter integerConverter: var integerValue = integerConverter.ConvertToInteger(language); result = _integerValues.ContainsKey(integerValue) ? _integerValues[integerValue] : null; break; case IStringConverter stringConverter: result = PickStringValue(stringConverter.ConvertToString(language)); break; default: result = PickStringValue(target.ToString()); break; } return(result ?? Add(target, new NullValue(), language)); }
public SerializableValue PickChild(SerializableValue name) { SerializableValue result; switch (name) { case FloatValue floatMemoryValue: result = _floatValues.ContainsKey(floatMemoryValue.Value) ? _floatValues[floatMemoryValue.Value] : null; break; case IntegerValue integerMemoryValue: result = _integerValues.ContainsKey(integerMemoryValue.Value) ? _integerValues[integerMemoryValue.Value] : null; break; case StringValue stringMemoryValue: result = _stringValues.ContainsKey(stringMemoryValue.Value) ? _stringValues[stringMemoryValue.Value] : null; break; case IFloatConverter floatConverter: var floatValue = floatConverter.ConvertToFloat(); result = _floatValues.ContainsKey(floatValue) ? _floatValues[floatValue] : null; break; case IIntegerConverter integerConverter: var integerValue = integerConverter.ConvertToInteger(); result = _integerValues.ContainsKey(integerValue) ? _integerValues[integerValue] : null; break; case IStringConverter stringConverter: var stringValue = stringConverter.ConvertToString(); result = _stringValues.ContainsKey(stringValue) ? _stringValues[stringValue] : null; break; default: var defaultStringValue = name.ToString(); result = _stringValues.ContainsKey(defaultStringValue) ? _stringValues[defaultStringValue] : null; break; } return(result ?? Add(name, new NullValue())); }
public ReferenceValue Add(SerializableValue name, SerializableValue value, string language = TranslationManager.DefaultLanguage) { void CheckKeyName(string key) { if (key == "Length" || key == "ArrayCount" || key == "KeyCount") { throw new NotSupportedException("Unable to set value in object: Length/ArrayCount/KeyCount is keyword"); } } WriteBackReferenceValue result; switch (name) { case IntegerValue integerMemoryValue: if (_integerValues.ContainsKey(integerMemoryValue.value)) { result = _integerValues[integerMemoryValue.value]; } else { result = new WriteBackReferenceValue(_writeBackDelegate) { ReferenceTarget = value }; _integerValues.Add(integerMemoryValue.value, result); } break; case StringValue stringMemoryValue: CheckKeyName(stringMemoryValue.value); if (_stringValues.ContainsKey(stringMemoryValue.value)) { result = _stringValues[stringMemoryValue.value]; } else { result = new WriteBackReferenceValue(_writeBackDelegate) { ReferenceTarget = value }; _stringValues.Add(stringMemoryValue.value, result); } break; case IIntegerConverter integerConverter: var integerValue = integerConverter.ConvertToInteger(language); if (_integerValues.ContainsKey(integerValue)) { result = _integerValues[integerValue]; } else { result = new WriteBackReferenceValue(_writeBackDelegate) { ReferenceTarget = value }; _integerValues.Add(integerValue, result); } break; case IStringConverter stringConverter: var stringValue = stringConverter.ConvertToString(language); CheckKeyName(stringValue); if (_stringValues.ContainsKey(stringValue)) { result = _stringValues[stringValue]; } else { result = new WriteBackReferenceValue(_writeBackDelegate) { ReferenceTarget = value }; _stringValues.Add(stringValue, result); } break; default: var defaultStringValue = name.ToString(); CheckKeyName(defaultStringValue); if (_stringValues.ContainsKey(defaultStringValue)) { result = _stringValues[defaultStringValue]; } else { result = new WriteBackReferenceValue(_writeBackDelegate) { ReferenceTarget = value }; _stringValues.Add(defaultStringValue, result); } break; } return(result); }
/// <inheritdoc /> public SerializableValue SubtractWith(SerializableValue target, string language) { var targetString = target is IStringConverter stringTarget?stringTarget.ConvertToString(language) : target.ToString(); return(new StringValue { Value = Value.Replace(targetString, "") }); }
/// <inheritdoc /> public SerializableValue AddWith(SerializableValue target, string language) { var targetString = target is IStringConverter stringTarget?stringTarget.ConvertToString(language) : target.ToString(); return(new StringValue { Value = $"{Value}{targetString}" }); }
public ReferenceValue Add(SerializableValue name, SerializableValue value) { ReferenceValue result; switch (name) { case FloatValue floatMemoryValue: if (_floatValues.ContainsKey(floatMemoryValue.Value)) { result = _floatValues[floatMemoryValue.Value]; } else { result = new ReferenceValue { Value = value }; _floatValues.Add(floatMemoryValue.Value, result); } break; case IntegerValue integerMemoryValue: if (_integerValues.ContainsKey(integerMemoryValue.Value)) { result = _integerValues[integerMemoryValue.Value]; } else { result = new ReferenceValue { Value = value }; _integerValues.Add(integerMemoryValue.Value, result); } break; case StringValue stringMemoryValue: if (_stringValues.ContainsKey(stringMemoryValue.Value)) { result = _stringValues[stringMemoryValue.Value]; } else { result = new ReferenceValue { Value = value }; _stringValues.Add(stringMemoryValue.Value, result); } break; case IFloatConverter floatConverter: var floatValue = floatConverter.ConvertToFloat(); if (_floatValues.ContainsKey(floatValue)) { result = _floatValues[floatValue]; } else { result = new ReferenceValue { Value = value }; _floatValues.Add(floatValue, result); } break; case IIntegerConverter integerConverter: var integerValue = integerConverter.ConvertToInteger(); if (_integerValues.ContainsKey(integerValue)) { result = _integerValues[integerValue]; } else { result = new ReferenceValue { Value = value }; _integerValues.Add(integerValue, result); } break; case IStringConverter stringConverter: var stringValue = stringConverter.ConvertToString(); if (_stringValues.ContainsKey(stringValue)) { result = _stringValues[stringValue]; } else { result = new ReferenceValue { Value = value }; _stringValues.Add(stringValue, result); } break; default: var defaultStringValue = name.ToString(); if (_stringValues.ContainsKey(defaultStringValue)) { result = _stringValues[defaultStringValue]; } else { result = new ReferenceValue { Value = value }; _stringValues.Add(defaultStringValue, result); } break; } return(result); }
public SerializableValue SubtractWith(SerializableValue target, string language = TranslationManager.DefaultLanguage) { var targetString = target is IStringConverter stringTarget?stringTarget.ConvertToString(language) : target.ToString(); return(new StringValue { value = value.Replace(targetString, "") }); }
public SerializableValue AddWith(SerializableValue target, string language = TranslationManager.DefaultLanguage) { var targetString = target is IStringConverter stringTarget?stringTarget.ConvertToString(language) : target.ToString(); return(new StringValue { value = $"{value}{targetString}" }); }