Code Red > .NET

Check your assumptions . . .

(1/1)

kdub_nz:
Got caught because I didn't 'Check my assumptions' 

Writing a filefind and it kept failing.
Thank fully 'Hot Reload' saved me some time while trying to find the problem.

Tearing my hair out 'cause it couldn't find "acad.lsp"
. . . . my assumption was that I actually had an acad.lsp on the search path  :roll:

fwiw, the code :


--- Code - C#: ---        public static bool FindFilePath(string FileName, out string path)        {             try            {                path = HostApplicationServices.Current.FindFile(FileName, _db, FindFileHint.Default);            }            catch (System.Exception ex)            {                _ed.WriteMessage($"\nException in 'FindFilePath({FileName})' :: {ex.Message}\n" );                _ed.WriteMessage("Ensure the file exists and it's location is on the ACAD File Search Path and a Trusted Location");                path = string.Empty;                return false;            }            return true;        } 
usage:

--- Code - C#: ---            if (FindFilePath("D:\\SD201_Config.INI", out string filePath))            {                _ed.WriteMessage($"\nQualified file path : {filePath}");            } 

It's Alive!:
I admire your ability to write thorough, but yet direct, exceptions
I assume _db and _ed are static

kdub_nz:
Yes Dan, static in this testing case . . . just seemed simpler ; I'm basically lazy  :)

gile:
I would have prefixed the method with: 'Try' (e.g. TryFindFilePath) to be consistent with other methods which return a boolean and use out parameters (as Dictionary.TryGetValue).

kdub_nz:
Yes Gilles, that would be more suitable  :)
Thanks.

Navigation

[0] Message Index

Go to full version