bool Clear(ref PObject plist) { if (Type != null) { switch (Type.ToLowerInvariant()) { case "string": plist = new PString(string.Empty); break; case "array": plist = new PArray(); break; case "dict": plist = new PDictionary(); break; case "bool": plist = new PBoolean(false); break; case "real": plist = new PReal(0); break; case "integer": plist = new PNumber(0); break; case "date": plist = new PDate(DateTime.Now); break; case "data": plist = new PData(new byte[1]); break; default: Log.LogError(7045, null, $"Unrecognized Type: {Type}"); return(false); } } else { plist = PObject.Create(plist.Type); } return(true); }
bool CreateValue(string type, string text, out PObject value) { DateTime date = DateTime.Now; bool boolean = false; double real = 0; int integer = 0; value = null; switch (type.ToLowerInvariant()) { case "string": value = new PString(text); return(true); case "array": value = new PArray(); return(true); case "dict": value = new PDictionary(); return(true); case "bool": if (text == null || !bool.TryParse(text, out boolean)) { boolean = false; } value = new PBoolean(boolean); return(true); case "real": if (text != null && !double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out real)) { Log.LogError(7045, null, "Unrecognized Real Format"); return(false); } value = new PReal(real); return(true); case "integer": if (text != null && !int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out integer)) { Log.LogError(7045, null, "Unrecognized Integer Format"); return(false); } value = new PNumber(integer); return(true); case "date": if (text != null && !DateTime.TryParse(text, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { Log.LogError(7045, null, "Unrecognized Date Format"); return(false); } value = new PDate(date); return(true); case "data": if (text != null) { value = new PData(Encoding.UTF8.GetBytes(Value)); } else { value = new PData(new byte[0]); } return(true); default: Log.LogError(7045, null, $"Unrecognized Type: {type}"); value = null; return(false); } }