HelloWorld.Coordinate.Parse C# (CSharp) Method

Parse() public static method

从字符串中解析出坐标信息
public static Parse ( string expression ) : Coordinate
expression string 包含坐标信息的字符串
return Coordinate
        public static Coordinate Parse( string expression )
        {
            if ( expression == null )
            throw new ArgumentNullException( "expression" );

              var match = coordinateRegex.Match( expression );
              if ( match.Success == false )
            throw new FormatException();

              var x = int.Parse( match.Groups["x"].Value );
              var y = int.Parse( match.Groups["y"].Value );

              return Create( x, y );
        }

Usage Example

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType != typeof(Coordinate))
            {
                throw new NotSupportedException();
            }

            var str = serializer.Deserialize <string>(reader);

            return(Coordinate.Parse(str));
        }
All Usage Examples Of HelloWorld.Coordinate::Parse