How can I access only one specific method from the UWP class?

My application has a few pages with textboxes (I used xaml in PCL). I need to save the data that is typed in in an xml file. The problem is that there is no System.IO.FileStream (which I need in order to be able to save the data) method in PCL so I somehow need to get it from the native UWP class (the application should be running on a windows mobile 10). How do I do that? I've been suggested to use DependencyServices but how would I use it to get access to System.IO.Filestream in this case?

I know that it's somehow possible to get access to native stuff like camera access via DependencyServices. But is this also possible with native methods like System.IO.FileStream?

Let's say it's not possible and I have to use PCLStorage, can I achieve the same (=create an xml file) with it?

I'm sorry for using wrong terms, I'm a big noob who's watched multiple hours of xamarin tutorials but still struggels to get something done correctly.

Best Answer

  • ClintStLaurentClintStLaurent US ✭✭✭✭✭
    Accepted Answer

    I mean that an interface doesn't have exectuable methods. It has signatures for properties and methods.

    Then when you create classes that inherit from those interfaces, that's where you put your executable code.

    You mentioned having read about DependencyServices for camera... So I thought you were familiar with interfaces and structure of doing this. My mistake. Sorry.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    But is this also possible with native methods like System.IO.FileStream?

    Yes. That is the approach you want to take.

    I do this by making an IFileHelper interface at PCL level, then making DependencyService implementations on each platform. You've seen the tutorials for camera etc. Its exactly the same. Define a MakeFileStream(string path) or some such in your interface, then put the actual code in the platform code. Have it return the System.IO.FileStream

  • rolfMrolfM ATMember ✭✭

    Thanks @ClintStLaurent ! What do you mean by "put the actual code in the platform code"? You mean the whole code from PCL?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    Accepted Answer

    I mean that an interface doesn't have exectuable methods. It has signatures for properties and methods.

    Then when you create classes that inherit from those interfaces, that's where you put your executable code.

    You mentioned having read about DependencyServices for camera... So I thought you were familiar with interfaces and structure of doing this. My mistake. Sorry.

  • rolfMrolfM ATMember ✭✭

    Ok got it, thank you a lot!

Sign In or Register to comment.