public static Optional <double[]> TryReadComponents(string value, int componentCount) { try { var parsedeValue = AtomicValueParser.ParseFloatVector <float>(value, componentCount, FileSourceInfo.Unknown); return(parsedeValue.Components.Select(c => (double)c.Value).ToArray()); } catch (Exception) { return(Optional.None()); } /* * var parts = value.Split(","); * var components = new double[parts.Length]; * * for (int i = 0; i < parts.Length; i++) * { * if (!double.TryParse(parts[i], NumberStyles.Any, CultureInfo.InvariantCulture, out components[i])) * return Optional.None(); * } * * if (components.Length == componentCount) * return components; * * if (components.Length == 1) * { * var uniformResult = new double[componentCount]; * for (int i = 0; i < componentCount; i++) * uniformResult[i] = components[0]; * return uniformResult; * } */ }
static AtomicValue ParseArbitraryValue(string s, Reflection.IDataType dt, FileSourceInfo src) { if (s.StartsWith('\'') && s.EndsWith('\'')) { return(new String(s.Trim('\''), src)); } if (s.StartsWith('"') && s.EndsWith('"')) { return(new String(s.Trim('"'), src)); } if (s == "true") { return(new Bool(true, src)); } if (s == "false") { return(new Bool(false, src)); } var p = s.Split(','); if (p.Length > 1) { return(AtomicValueParser.ParseFloatVector <Single>(s, p.Length, src)); } if (s.Contains("#")) { return(AtomicValueParser.ParseHexVector <float>(s, 4, src)); } if (s.Contains("px") || s.Contains("%") || s.Contains("pt")) { if (p.Length == 2) { return(AtomicValueParser.ParseSize2(s, src)); } else { return(AtomicValueParser.ParseSize(s, src)); } } if (char.IsLetter(s[0])) { return(new GlobalReferenceValue(s, dt, src)); } return(AtomicValueParser.ParseFloat <Double>(s, src)); }