Question About System.IO.FileInfo

Using (or providing) Microsoft.NET Classes

Question About System.IO.FileInfo

Postby PGilbert on Sun Aug 22, 2010 12:56 pm

If I do the following:

      fi←⎕NEW System.IO.FileInfo(⊂'c:\windows\explorer.exe')

      fi.Length ⍝ Size of the file
2870272

      1+fi.Length ⍝ Does not work because...
DOMAIN ERROR
      1+fi.Length
     ∧

      fi.Length.GetType ⍝ ...Length is an object System.Int64
System.Int64

My question is: What is the best way to convert this System.Int64 to an APL number ?

The following are working:

      1+⍎⍕fi.Length
2870273

      1+⍎fi.Length.ToString ⍬
2870273

      1+System.Int32.Parse (⊂fi.Length.ToString ⍬)
2870273

but don't look very efficient.

Thanks,

Pierre Gilbert

Using: v12.1 - Unicode
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Question About System.IO.FileInfo

Postby Morten|Dyalog on Sun Aug 22, 2010 1:15 pm

John Daintree, who is the chief architect of the "Dyalog .Net Bridge", is returning from vacation on Tuesday. I'll ask him why we don't just cast Int64 values (so long as the conversion does not lose precision). I can't immediately think of a good reason, but there may be one that I'm not aware of. Hopefully, you won't have to use a work-around very long.

I think my preferred workaround would be (Convert.ToDouble fi.Length). Convert.ToInt32 would be OK if you donn't have *big* files :-).

As previously mentioned, we *will* cast Int64 to the new 128-bit Decimal type in v13.0.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: Question About System.IO.FileInfo

Postby stignielsen on Tue Sep 21, 2010 8:31 am

I have made a function to do various conversions of .Net types that will cast it to best suitable APL type. Maybe that can be used for inspiration?

Code: Select all
 r←dotnetConvNum dotnetnum;
⍝ Convert dotnet numeric value to the best corresponding representation in APL.

 :Select dotnetnum.GetType
 :Case System.Int64
    :If ¯1=dotnetnum.CompareTo System.Convert.ToInt64 System.Int32.MaxValue
       r←System.Convert.ToInt32 dotnetnum
    :Else
       r←System.Convert.ToDouble dotnetnum
    :EndIf
 :Else
    r←⍬
 :EndSelect
User avatar
stignielsen
 
Posts: 4
Joined: Mon Sep 20, 2010 12:58 pm


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest