- 积分
- 25214
- 明经币
- 个
- 注册时间
- 2003-6-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2014-3-5 10:54:02
|
显示全部楼层
/// <summary>
/// 从句柄转换成ObjectId
/// Version : 2010.03.29 Sieben
/// </summary>
/// <param name="handle">句柄,可以是Handle,string,int,long数据类型</param>
/// <returns>成功返回句柄所对应的ObjectId,否则返回ObjectId.Null</returns>
public static ObjectId HandleToObjectId(object handle)
{
try
{
if (handle == null) return ObjectId.Null;
ObjectId tId2 = ObjectId.Null;
if (handle is Handle)
return sc.db.GetObjectId(false, (Handle)handle, 0);
else if (handle is string)
{
string tStr = handle.ToString().Trim();
if (tStr == "")
return ObjectId.Null;
else if (tStr == "0")
return ObjectId.Null;
else
{
long lNum = Convert.ToInt64(tStr, 16);
if (lNum == 0L)
return ObjectId.Null;
else
return sc.db.GetObjectId(false, new Handle(lNum), 0);
}
}
else if (handle is int || handle is long)
{
long lNum = (long)handle;
if (lNum == 0L)
return ObjectId.Null;
else
return sc.db.GetObjectId(false, new Handle(lNum), 0);
}
else
return ObjectId.Null;
}
catch
{
return ObjectId.Null;
}
} |
|