以object类型的对象返回其Shape属性为例。
/// <summary>
/// 返回Object对象的指定属性
/// </summary>
/// <param name="obj">传入的对象</param>
/// <returns>返回的属性</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;
}
本文介绍了一种通过反射机制从任意对象中获取指定属性'Shape'的方法,并将其转换为GeoJSON.NET.Geometry.Point类型的具体实现。
626

被折叠的 条评论
为什么被折叠?



