public ValueExpression GetNormalizedReferenceValue(ValueExpression originalValue, string resourceType) { if (originalValue == null) { return(null); } var value = originalValue.ToString(); if (string.IsNullOrWhiteSpace(value)) { return(originalValue); } if (!value.Contains("/") && !string.IsNullOrWhiteSpace(resourceType)) { return(new StringValue($"{resourceType}/{value}")); } if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var uri)) { var key = KeyExtensions.ExtractKey(uri); if (_localhost.GetKeyKind(key) != KeyKind.Foreign) // Don't normalize external references (https://github.com/FirelyTeam/spark/issues/244). { var refUri = _localhost.RemoveBase(uri); return(new StringValue(refUri.ToString().TrimStart('/'))); } } return(originalValue); }
// This code might have a better place somewhere else: //mh public static FM.Quantity ToModelQuantity(this ValueExpression expression) { var q = QuantityValue.Parse(expression.ToString()); var quantity = new FM.Quantity { Value = q.Number, System = q.Namespace, Unit = q.Unit, Code = q.Unit }; return(quantity); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append("{set name=\"") .Append(Name).Append("\" value=\"") .Append(ValueExpression.ToString()) .Append("\"/}"); return(sb.ToString()); }
public void ExpressionPropertyTests_ValueExpression() { var data = new { test = new { x = 13 } }; var val = new ValueExpression("test"); Assert.Equal("=`test`", val.ExpressionText); Assert.Null(val.Value); Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); var(result, error) = val.TryGetValue(data); Assert.Equal("test", result); Assert.Null(error); val = new ValueExpression("=test"); Assert.Equal("=test", val.ExpressionText); Assert.Null(val.Value); Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.Equal(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result)); Assert.Null(error); val = new ValueExpression(data.test); Assert.Null(val.ExpressionText); Assert.NotNull(val.Value); Assert.Equal(JsonConvert.SerializeObject(data.test, settings), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.Equal(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result)); Assert.Null(error); val = new ValueExpression("Hello ${test.x}"); Assert.Equal("=`Hello ${test.x}`", val.ExpressionText); Assert.Null(val.Value); Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.Equal("Hello 13", result); Assert.Null(error); // slashes are the chars val = new ValueExpression("c:\\test\\test\\test"); (result, error) = val.TryGetValue(data); Assert.Equal("c:\\test\\test\\test", result); Assert.Null(error); // tabs are the chars val = new ValueExpression("c:\test\test\test"); (result, error) = val.TryGetValue(data); Assert.Equal("c:\test\test\test", result); Assert.Null(error); }
public void ExpressionPropertyTests_ValueExpression() { var data = new { test = new { x = 13 } }; var val = new ValueExpression("test"); Assert.IsNull(val.Expression); Assert.IsNotNull(val.Value); Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); var(result, error) = val.TryGetValue(data); Assert.AreEqual("test", result); Assert.IsNull(error); val = new ValueExpression("=test"); Assert.IsNotNull(val.Expression); Assert.IsNull(val.Value); Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.AreEqual(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result)); Assert.IsNull(error); val = new ValueExpression(data.test); Assert.IsNull(val.Expression); Assert.IsNotNull(val.Value); Assert.AreEqual(JsonConvert.SerializeObject(data.test, settings), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.AreEqual(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result)); Assert.IsNull(error); val = new ValueExpression("Hello @{test.x}"); Assert.IsNull(val.Expression); Assert.IsNotNull(val.Value); Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString()); (result, error) = val.TryGetValue(data); Assert.AreEqual("Hello 13", result); Assert.IsNull(error); }
public override String ToString() { return(this.OvName + "." + this.AttributeName + " := " + ValueExpression.ToString()); }