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

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • 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

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

gile

  • Gator
  • Posts: 2507
  • 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_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.