What need I do to get this code to work in a Portable Class Library?

后端 未结 4 1403
一向
一向 2020-12-21 19:28

I\'m wondering if the Portable Class Library is even more restricted in functionality than the Compact Framework.

I\'m trying to port a CF/Windows CE app (runs on a

相关标签:
4条回答
  • 2020-12-21 20:12

    Since in a PCL I was unable to get a StreamWriter from a string (it required a stream), I created a simple interface to get some of the data from the platform implementation. You can also do this with DirectoryInfo and FileInfo.

    https://github.com/sami1971/SimplyMobile/blob/master/Core/SimplyMobile.Text/IStreamLocator.cs

    The implementation is really simple as well, only needs one single compiler flag for WP8:

    https://github.com/sami1971/SimplyMobile/blob/master/WP8/SimplyMobile.Text.Platform/StreamLocator.cs

    Recursively search for *.XML files:

        private static void PrintDirectory(IStreamLocator locator, string dir)
        {
            foreach (var file in locator.GetFileNames(dir, "*.XML"))
            {
                System.Diagnostics.Debug.WriteLine(file);
            }
    
            foreach (var di in locator.GetFolderNames(dir, "*"))
            {
                PrintDirectory(locator, di);
            }
        }
    
    0 讨论(0)
  • 2020-12-21 20:19

    Xamarin has a scanner which will give you a rough idea of the portability of your code: http://scan.xamarin.com/

    For some guidance on how to deal with non-portable APIs from PCLs, see my blog post: How to Make Portable Class Libraries Work for You

    For file IO in particular, you can try my PCL Storage library.

    0 讨论(0)
  • 2020-12-21 20:31

    Windows Phone applications do not use the file system of the operating system and are restricted to using isolated storage to persist and access files, so this namespace does not provide any additional functionality.

    http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.io%28v=vs.105%29.aspx

    0 讨论(0)
  • 2020-12-21 20:31

    Another option is to use Shim if all your platforms are supported by it.

    API coverage for file operations isn't exhaustive, but it gets you a long way. As a bonus, it also gives you access to a bunch of other stuff.

    0 讨论(0)
提交回复
热议问题