Author Topic: Check your assumptions . . .  (Read 358 times)

0 Members and 1 Guest are viewing this topic.

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Check your assumptions . . .
« on: November 20, 2022, 02:07:43 AM »
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#: [Select]
  1.         public static bool FindFilePath(string FileName, out string path)
  2.         {
  3.             try
  4.             {
  5.                 path = HostApplicationServices.Current.FindFile(FileName, _db, FindFileHint.Default);
  6.             }
  7.             catch (System.Exception ex)
  8.             {
  9.                 _ed.WriteMessage($"\nException in 'FindFilePath({FileName})' :: {ex.Message}\n" );
  10.                 _ed.WriteMessage("Ensure the file exists and it's location is on the ACAD File Search Path and a Trusted Location");
  11.                 path = string.Empty;
  12.                 return false;
  13.             }
  14.             return true;
  15.         }
  16.  

usage:
Code - C#: [Select]
  1.             if (FindFilePath("D:\\SD201_Config.INI", out string filePath))
  2.             {
  3.                 _ed.WriteMessage($"\nQualified file path : {filePath}");
  4.             }
  5.  
« Last Edit: November 20, 2022, 02:16:36 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7486
  • AKA Daniel
Re: Check your assumptions . . .
« Reply #1 on: November 20, 2022, 03:20:41 AM »
I admire your ability to write thorough, but yet direct, exceptions
I assume _db and _ed are static
Retired

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Re: Check your assumptions . . .
« Reply #2 on: November 20, 2022, 04:08:45 AM »
Yes Dan, static in this testing case . . . just seemed simpler ; I'm basically lazy  :)
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober

gile

  • Water Moccasin
  • Posts: 2406
  • Marseille, France
Re: Check your assumptions . . .
« Reply #3 on: November 20, 2022, 04:48:26 AM »
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).
Speaking English as a French Frog

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Re: Check your assumptions . . .
« Reply #4 on: November 20, 2022, 04:58:12 AM »
Yes Gilles, that would be more suitable  :)
Thanks.
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober