C# returns the specified property of the object object

Take an object of type object returning its Shape property as an example.

        /// <summary>
        /// Returns the specified property of the Object object
        /// </summary>
        /// <param name="obj">Incoming object</param>
        /// <returns>Returned properties</returns>
        private GeoJSON.Net.Geometry.Point GetShape(object obj)
        {
            System.Reflection.PropertyInfo a = null;
            foreach (System.Reflection.PropertyInfo pi in obj.GetType().GetProperties())
            {
                if (pi.CanWrite)
                {
                    if (0 == string.Compare("Shape", pi.Name, true))
                    {
                        a = pi;
                        break;
                    }
                }
            }
            if (null == a)
            {
                return null;
            }
            return a.GetValue(obj) as GeoJSON.Net.Geometry.Point;
        }


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325548102&siteId=291194637