internal object ResolvePath(string pathText, PluginTreeNode origin, ObtainMode obtainMode) { if (string.IsNullOrWhiteSpace(pathText)) { throw new ArgumentNullException(nameof(pathText)); } var expression = PluginPath.Parse(pathText); var node = origin.Find(expression.Path); if (node == null) { throw new PluginException($"Not found the PluginTreeNode with '{expression.Path}' path."); } try { //获取指定路径的目标对象 object target = node.UnwrapValue(obtainMode, this, null); if (target != null && expression.Members.Length > 0) { return(Reflection.MemberAccess.GetMemberValue <object>(target, expression.Members)); } return(target); } catch (Exception ex) { var fileName = string.Empty; if (origin != null && origin.Plugin != null) { fileName = System.IO.Path.GetFileName(origin.Plugin.FilePath); } throw new PluginException(string.Format("Resolve target error from '{0}' path in '{1}' plugin file.", pathText, fileName), ex); } }
/// <summary> /// 查找指定路径的插件树节点。 /// </summary> /// <param name="path">指定的路径。</param> /// <returns>如果查找成功则返回对应的插件树节点对象,否则返回空(null)。</returns> /// <exception cref="System.ArgumentNullException">当<paramref name="path"/>参数为空或全空格字符串。</exception> public PluginTreeNode Find(string path) { return(_rootNode.Find(path)); }