/// <summary>
        /// Project point to map spatial reference.
        /// </summary>
        /// <param name="point">Point to project</param>
        /// <param name="xConv">Delegate for convert x coordinate.</param>
        /// <param name="yConv">Delegate for convert y coordinate.</param>
        /// <param name="wkid">Spatial reference ID.</param>
        /// <returns>Projected point.</returns>
        private static Point _ProjectPoint(Point point, ConverterDelegate xConv, ConverterDelegate yConv, int?wkid)
        {
            double x = xConv(point.X);
            double y = yConv(point.Y);

            Point result = new Point(x, y);

            return(result);
        }
Esempio n. 2
0
        private object GetValue(object obj, string propertyPath, ConverterDelegate converter, Type targetType, object parameter, out bool success)
        {
            success = true;

            if (converter == null)
            {
                return(GetValue(obj, propertyPath));
            }

            return(converter(GetValue(obj, propertyPath), targetType, parameter, out success));
        }
Esempio n. 3
0
 public virtual T Get <T>(ConverterDelegate <T> converter)
 {
     try
     {
         return(converter(value));
     }
     catch
     {
         throw new ParseException($"Failed to convert '{name}' = {typeof(T).Name}({value})");
     }
 }
        /// <summary>
        /// Project polyline to map spatial reference.
        /// </summary>
        /// <param name="polyline">Polyline to project.</param>
        /// <param name="xConv">Delegate for convert x coordinate.</param>
        /// <param name="yConv">Delegate for convert y coordinate.</param>
        /// <param name="wkid">Spatial reference ID.</param>
        /// <returns>Projected polyline.</returns>
        private static Polyline _ProjectPolyline(Polyline polyline, ConverterDelegate xConvFunc, ConverterDelegate yConvFunc, int wkid)
        {
            Point[] points          = polyline.GetPoints(0, polyline.TotalPointCount);
            Point[] projectedPoints = new Point[polyline.TotalPointCount];

            for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
            {
                Point point = points[pointIndex];
                projectedPoints[pointIndex] = _ProjectPoint(point, xConvFunc, yConvFunc, wkid);
            }

            Polyline projectedPolyline = new Polyline(polyline.Groups, projectedPoints);

            return(projectedPolyline);
        }
Esempio n. 5
0
 public override T[] GetArray <T>(ConverterDelegate <T> converter)
 {
     try
     {
         return(base.GetArray <T>(converter));
     }
     catch
     {
         if (wasParsed)
         {
             throw new ParseException($"Failed to convert '{name}' = {typeof(T).Name}[]({value})");
         }
         else
         {
             value = defaultValue;
             return(base.GetArray <T>(converter));
         }
     }
 }
Esempio n. 6
0
        public virtual T[] GetArray <T>(ConverterDelegate <T> converter)
        {
            try
            {
                if (value.Length > 0)
                {
                    var arr = Util.ParseArray(value);
                    var ret = from s in arr select converter(s);

                    return(ret.ToArray());
                }
                else
                {
                    return new T[] {}
                };
            }
            catch
            {
                throw new ParseException($"Failed to convert '{name}' = {typeof(T).Name}[]({value})");
            }
        }
Esempio n. 7
0
        public List <T> GetAll <T>(string sql, ConverterDelegate <T> convert, object[] parms = null)
        {
            VerificaConexao();

            sql = string.Format(sql, "@");

            _factory.Command.CommandText = sql;
            _factory.Command.SetParameters(parms);

            var list   = new List <T>();
            var reader = _factory.Command.ExecuteReader();

            while (reader.Read())
            {
                var obj = convert(reader);
                list.Add(obj);
            }
            reader.Close();

            return(list);
        }
Esempio n. 8
0
        public T Get <T>(string sql, ConverterDelegate <T> convert, object[] parms = null)
        {
            VerificaConexao();

            sql = string.Format(sql, "@");

            _factory.Command.CommandText = sql;
            _factory.Command.SetParameters(parms);

            T t = default(T);

            var reader = _factory.Command.ExecuteReader();

            if (reader.Read())
            {
                t = convert(reader);
            }

            reader.Close();

            return(t);
        }
 internal ConvertOptionsBuilder(ConvertOptionsBuilder other, Type targetType, ConverterDelegate converter)
 {
     _optionSets = other._optionSets;
     _converters = other._converters.SetItem(targetType, converter);
 }
 /// <summary>
 /// Add a custom converter to this <see cref="ConvertOptionsBuilder"/>
 /// </summary>
 /// <returns>A new <see cref="ConvertOptionsBuilder"/> with updated settings</returns>
 public ConvertOptionsBuilder WithConverter <T>(ConverterDelegate <T> @delegate)
 => new ConvertOptionsBuilder(this, typeof(T), (value, options) => @delegate(value, options));
Esempio n. 11
0
 public ConvertOptionsBuilder WithConverter <T>(ConverterDelegate <T> @delegate) => throw null;
 /// <summary>
 ///     Adds a converter for a type to be able to use that type in a command.
 /// </summary>
 /// <typeparam name="T">Type of the object you want to use in your commands</typeparam>
 /// <param name="amountArgumentsNeeded">Amount of arguments needed for that commands (e.g. Vector3 needs <u>3</u> because of X, Y and Z)</param>
 /// <param name="converter">
 ///     The function to convert the arguments to the type you want to have.<br/>
 ///     The <see cref="ArraySegment{T}"/> of <see cref="string"/> exactly contains the arguments (length = <paramref name="amountArgumentsNeeded"/>) used for this type.<br/>
 ///     Return of the converter needs to be of type <typeparamref name="T"/>
 ///     Use the CancelEventArgs if you want to output the error message by yourself (like "Player not found").
 /// </param>
 public static void SetConverter <T>(this Command _, int amountArgumentsNeeded, ConverterDelegate converter)
 => ArgumentsConverter.Instance.SetConverter(typeof(T), amountArgumentsNeeded, converter);