/// <summary> /// 转换成指定类型的 /// </summary> /// <param name="element"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T CastType <T>(this object element) { try { return((T)element); } catch (Exception e) { LogTool.LogException(e); throw; } }
/// <summary> /// 获取环境指定类型 /// </summary> /// <param name="context"></param> /// <typeparam name="TContext"></typeparam> /// <returns></returns> public static TContext GetContext <TContext>(this IContext context) where TContext : class, IContext { try { return((TContext)context); } catch (Exception e) { LogTool.LogException(e); throw; } }
/// <summary> /// 获取当前StateMgr的指定类型 /// </summary> /// <param name="stateMgr">stateMgr类型</param> /// <typeparam name="T">stateMgr类型</typeparam> /// <returns></returns> public static T GetStateMgr <T>(this IStateMgr stateMgr) where T : class, IStateMgr { try { return(stateMgr as T); } catch (Exception e) { LogTool.LogException(e); throw; } }
public TGoalMgr GetGoalMgr <TGoalMgr>() where TGoalMgr : class { try { return(this as TGoalMgr); } catch (Exception e) { LogTool.LogException(e); throw; } }
public TAgent GetAgent <TAgent>() where TAgent : class, IAgent <TAction, TGoal> { try { return(this as TAgent); } catch (Exception e) { LogTool.LogException(e); throw; } }