示例#1
0
        ///////////////////////////////////////////////////////////////////////

        public static string GetPath(
            Interpreter interpreter, /* OPTIONAL */
            Assembly assembly
            )                        /* CANNOT RETURN NULL */
        {
            //
            // NOTE: Fetch the base directory for the current application
            //       domain.  This will be used to check if the candidate
            //       assembly paths are underneath it.  It is now possible
            //       to override the value used here via the environment.
            //
            string path0 = GetAnchorPath();

            if (path0 == null)
            {
                path0 = GlobalState.GetAppDomainBaseDirectory();
            }

            //
            // NOTE: First, try to use the current path to the assembly,
            //       checking to make sure that it resides underneath the
            //       base directory for the application domain.
            //
            string path1 = GetCurrentPath(assembly);

            if (PathOps.IsUnderPath(interpreter, path1, path0))
            {
                return(path1);
            }

            //
            // NOTE: Second, try to use the original path to the assembly,
            //       checking to make sure that it resides underneath the
            //       base directory for the application domain.
            //
            string path2 = GetOriginalPath(assembly);

            if (PathOps.IsUnderPath(interpreter, path2, path0))
            {
                return(path2);
            }

            //
            // NOTE: At this point, we have failed to figure out a path for
            //       this assembly that actually resides within the current
            //       application domain.  This condition is not impossible;
            //       however, it should not happen for the core library
            //       assembly itself.
            //
            DebugOps.Complain(interpreter, ReturnCode.Error, String.Format(
                                  "could not determine a path for assembly {1} underneath " +
                                  "the application domain path {0}", FormatOps.DisplayPath(
                                      path0), FormatOps.DisplayAssemblyName(assembly)));

            //
            // NOTE: This method cannot return null; therefore, the legacy
            //       return value will be used instead (i.e. the current
            //       path to the assembly).
            //
            return(path1);
        }