I'm doing some reading of files in .Net that targets mobile platforms so I am using the PCL. I've noticed that if I add/change my targeted platforms my assembly options vary pretty dramatically. In general, what is the best way to get the max amount of assemblies in the PCL?
Here's something more specific: I'd like to use System.Reflection.Assembly.GetExecutingAssembly();
AND System.IO.Path
So far I've only been able to get one or the other. Has anyone found a way to get both?
This is the class I want to implement:
public class ContentProviderImplementation : IContentProvider
{
private static Assembly _CurrentAssembly;
private Assembly CurrentAssembly
{
get
{
if (_CurrentAssembly == null)
{
_CurrentAssembly = Assembly.GetExecutingAssembly();
}
return _CurrentAssembly;
}
}
public StreamReader LoadContent(string relativePath)
{
string localXMLUrl = Path.Combine(Path.GetDirectoryName(CurrentAssembly.GetName().CodeBase), relativePath);
return new StreamReader(File.OpenRead(new Uri(localXMLUrl).LocalPath));
}
}
What would be the best conceptual way (code specifics OK but I don't want straight up solutions unless it's just getting scope on the right PCL assemblies) of implementing this for multiple mobile platforms? Specifically: IOS, Android, Windows 8.1 and Windows phone.
This is the answer to the most related SO question:
Portable class libraries allow you to work with namespaces and classes that exist in all the platforms that you're targeting. .Net 4.5 (assuming you mean the full desktop-WinForms/WPF), Windows 8 and Windows Phone 8 all do file access very differently and have different files available to them. Where files can be accessed from also differs greatly: embedded content; embedded resources; isolated storage; shared folders; the full file system. These aren't all available on all the platforms you mention.
Short answer. You probably can't do what you're after. File system access varies dramatically across platforms and typically has to be done differently for each platform. What you can do is define an interface for file access (open, read, save, etc.) that your PCL can use and then create platform specific instances that you pass to the PCL as needed.
URL to related SO question: C# PCL Reading from File
Also, I like to mean what I say. Please tell me if I'm using any programming terminology incorrectly. I'm pretty new to the software scene! Thanks guys!