Exemple #1
0
        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);
            }
        }