'Axiomatic Semantics - How to calculate a weakest precondition of a program
Assuming the post-condition, how can I compute the weakest pre-condition of a program containing two statements?
For example :
a=x;
y = 0
{x = y + a}
Another example:
y = x;
y = x + x + y
{y = 3x ^ z> 0}
I tried to solve them but both questions resulted in pre-conditions or post-condition that are identical to the statement and I don't know if this is valid.
for example, the precondition of the last statement is "y=x" , thus it is the post condition of the preceding statement which is " y=x" as well
Solution 1:[1]
It is also possible to use DeserializeObject method which accepts a type. That way you don't need to write any type-specific parser, you just have to find out a type and provide it to that method. Something like this:
public Payload GetPayload(string type, string message)
{
switch (type)
{
case "fuel":
return JsonConvert.DeserializeObject(message, typeof(Fuel));
case "engine":
return JsonConvert.DeserializeObject(message, typeof(Engine));
default:
return null;
}
}
You can then decorate your entity classes with JsonProperties attributes (mapping basically) as indicated here (plus use that coverter):
[JsonConverter(typeof(JsonPathConverter))]
class Fuel : Payload
{
[JsonProperty("data.fueltype")]
public string FuelType{ get; set; }
[JsonProperty("data.mileage")]
public float Mileage { get; set; }
}
string message = "{\r\n\t\"type\": \"fuel\",\r\n\t\"data\":\r\n\t\t{\r\n\t\t\t\"fueltype\": \"petrol\",\r\n\t\t\t\"mileage\": 23.76,\r\n\t\t\t\"tankcapacity\": 37\r\n\t\t}\r\n}";
var type = GetMessageType(); // get type from message i.e. with JObject
var payload = GetPayload(type, message);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
