public object Convert(object value) { if (value is Color c) { return(c); } if (value is string s) { var res = FromString(s); if (res is Color) { return(res); } } else if (value is IEnumerable en) { return(FromArray(en)); } if (value == null) { return(SpecialNames.CantParse); } var fl = floatDs.Convert(value); if (fl is float f) { return(new Color(f, f, f)); } return(FromString(value?.ToString())); }
public object FromString(string value) { if (string.IsNullOrWhiteSpace(value)) { return(SpecialNames.CantParse); } var values = value.Split(splitters); if (values.Length == 1) { var pr = FloatParser.Convert(values[0]); if (pr is float fl) { return(SingleValueMode(fl)); } } if (values.Length == 2) { var pr1 = FloatParser.Convert(values[0]); var pr2 = FloatParser.Convert(values[1]); if (pr1 is float fl1) { if (pr2 is float fl2) { return(new Vector3(fl1, fl2, 0)); } } } if (values.Length == 3) { var pr1 = FloatParser.Convert(values[0]); var pr2 = FloatParser.Convert(values[1]); var pr3 = FloatParser.Convert(values[2]); if (pr1 is float fl1) { if (pr2 is float fl2) { if (pr3 is float fl3) { return(new Vector3(fl1, fl2, fl3)); } } } } return(SpecialNames.CantParse); }
public object FromString(string value) { if (string.IsNullOrWhiteSpace(value)) { return(SpecialNames.CantParse); } var sp = ParseFromPositioningLiteral(value); if (sp is YogaValue2 s) { return(s); } var values = value.Split(splitters); if (values.Length == 1) { var pr = YogaValueParser.Convert(values[0]); if (pr is YogaValue fl) { return(new YogaValue2(fl, fl)); } } if (values.Length == 2) { var pr1 = YogaValueParser.Convert(values[0]); var pr2 = YogaValueParser.Convert(values[1]); if (pr1 is YogaValue fl1) { if (pr2 is YogaValue fl2) { return(new YogaValue2(fl1, fl2)); } } } return(SpecialNames.CantParse); }
public object Convert(object value) { var res = baseConverter?.Convert(value); if (res != null && !Equals(res, SpecialNames.CantParse)) { return(res); } if (value is string s) { return(FromString(s)); } return(SpecialNames.CantParse); }
public object FromString(string value) { if (string.IsNullOrWhiteSpace(value)) { return(ImageReference.None); } if (FileRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.File, FileRegex.Replace(value, ""))); } if (HttpRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.Url, value)); } if (GlobalRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.Global, GlobalRegex.Replace(value, ""))); } if (ProceduralRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.Procedural, ProceduralRegex.Replace(value, ""))); } if (ResourceRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.Resource, ResourceRegex.Replace(value, ""))); } if (PathRegex.IsMatch(value)) { return(new ImageReference(AssetReferenceType.Path, value)); } var dataMatch = DataRegex.Match(value); if (dataMatch.Success) { var mime = dataMatch.Groups["mime"].Value; var encoding = dataMatch.Groups["encoding"].Value; var data = dataMatch.Groups["data"].Value; return(new ImageReference(AssetReferenceType.Data, data)); } var color = ColorConverter.Convert(value); if (color is Color c) { return(new ImageReference(AssetReferenceType.Procedural, c)); } return(new ImageReference(AssetReferenceType.Auto, value)); }
public object Convert(object value) { return(converter.Convert(value)); }