A very complex LINQ expression

Source: Internet
Author: User

I recently wrote this method:

         //  The returned result is roughly aagp30pmdrvs56nk.          Public   String Getusbdisksnviadriveletter ( String  Strusbdiskdriveletter ){  VaR Searcher = New Managementobjectsearcher ( "  Select * From win32_logicaldisktopartition  "  );  Foreach (Managementobject DM In  Searcher. Get ()){  //  DM ["dependent"] is roughly \ JIANG-PC \ Root \ cimv2: win32_logicaldisk.deviceid = "H :"                  String Strdriveletter = getvalueinquotes (DM [ "  Dependent  "  ]. Tostring ());  If (Strdriveletter = Strusbdiskdriveletter ){  // DM ["antecedent"] is roughly \ JIANG-PC \ Root \ cimv2: win32_diskpartition.deviceid = "disk #1, partition #0"                      String [] Diskarray = getvalueinquotes (DM [ "  Antecedent  " ]. Tostring (). Split ( '  ,  '  );  String Drivenumber = diskarray [ 0 ]. Remove ( 0 , 6 ). Trim ();  VaR Disks = New Managementobjectsearcher ( "  Select * From win32_diskdrive  "  );  Foreach (Managementobject Disk In  Disks. Get ()){  //  Disk ["name"] is roughly \. \ physicaldrive1  // Disk ["interfacetype"] is roughly: USB                          If (Disk [ "  Name  " ]. Tostring () = ( "  \\\\. \ Physicaldrive  " + Drivenumber) & disk [ "  Interfacetype  " ]. Tostring () = "  USB  " ){  //  Disk ["pnpdeviceid"] is roughly: usbstor \ disk & ven_teclast & prod_coolflash (s) & rev_1100 \ aagp30pmdrvs56nk & 0                              Return Parseserialfromdeviceid (Disk [ "  Pnpdeviceid  "  ]. Tostring ());}}}}  Return   Null  ;} 

The resharper plug-in prompts me that this can be converted into a LINQ expression. How can I convert it? So after clicking it, it becomes:

        //  The returned result is roughly aagp30pmdrvs56nk.          Public   String Getusbdisksnviadriveletter ( String  Strusbdiskdriveletter ){  VaR Searcher = New Managementobjectsearcher ( "  Select * From win32_logicaldisktopartition  "  );  Return (From Managementobject DM In Searcher. Get () Let strdriveletter = getvalueinquotes (DM [ "  Dependent  " ]. Tostring ()) Where Strdriveletter = strusbdiskdriveletter Select Getvalueinquotes (DM [ "  Antecedent  " ]. Tostring (). Split ( '  ,  ' ) Into diskarraySelect Diskarray [ 0 ]. Remove ( 0 , 6 ). Trim () into drivenumber let disks = New Managementobjectsearcher ( "  Select * From win32_diskdrive  " ) From Managementobject Disk In Disks. Get () Where Disk [ "  Name " ]. Tostring () = ( "  \\\\. \ Physicaldrive  " + Drivenumber) & disk [ "  Interfacetype  " ]. Tostring () = "  USB  "   Select Parseserialfromdeviceid (Disk [ "  Pnpdeviceid  " ]. Tostring (). firstordefault ();} 

CodeIt seems to be much less. I thought it was another language, but frankly speaking, the readability is really poor ...... A long line.

It seems that resharper is too intelligent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.