private (ImageArrayType type, int rank) ParseTypeAndRank(string jsonString) { string responseString = jsonString.Substring(0, 50); MatchCollection matches = Regex.Matches(responseString, "^{\\s*\"Type\":\\s*(\\d),\"Rank\":\\s*(\\d*)", RegexOptions.IgnoreCase); ImageArrayType type = (ImageArrayType)int.Parse(matches[0].Groups[1].Value); int rank = int.Parse(matches[0].Groups[2].Value); return(type, rank); }
private static Array Parse2DImageResponse(IRestResponse response, ImageArrayType type) { switch (type) { case ImageArrayType.Int: var imageArrayInt2DResponse = JsonConvert.DeserializeObject <ImageArrayInt2DResponse>(response.Content); return(imageArrayInt2DResponse.HandleResponse <int[, ], ImageArrayInt2DResponse>()); case ImageArrayType.Short: var imageArrayShort2DResponse = JsonConvert.DeserializeObject <ImageArrayShort2DResponse>(response.Content); return(imageArrayShort2DResponse.HandleResponse <short[, ], ImageArrayShort2DResponse>()); case ImageArrayType.Double: var imageArrayDouble2DResponse = JsonConvert.DeserializeObject <ImageArrayDouble2DResponse>(response.Content); return(imageArrayDouble2DResponse.HandleResponse <double[, ], ImageArrayDouble2DResponse>()); default: throw new AlpacaInvalidValueException($"'ImageArrayType '{type} ({(int)type})' is not a valid value"); } }