Directive de compilation pour un ViewModel
Hello,
J'ai une Portable Class Library dans laquelle se trouve un Helper. Dans ce Helper je tente de mettre en place une fonction qui me retourne la version de l'application en fonction de la plateforme (WP ou Win8).
Le code de la fonction est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| public static string GetApplicationRelease()
{
#if NETFX_CORE
return Pakage.Current.Id.Version.ToString();
#elif WINDOWS_PHONE
System.Uri manifest = new System.Uri("WMAppManifest.xml",System.UriKind.Relative);
var si = App.GetResourceStream(manifest);
if(si != null)
{
using(System.IO.StreamReader sr = new System.IO.StreamReader(si.Stream))
{
bool haveApp = false;
while(!sr.EndOfStream)
{
string line = sr.ReadLine();
if(!haveApp)
{
int i = line.IndexOf("AppPlatformVersion=\"",System.StringComparison.InvariantCulture);
if(i >= 0)
{
haveApp = true;
line = line.Substring(i + 20);
int z = line.IndexOf("\"");
if(z >= 0)
{
// if you're interested in the app plat version at all
// AppPlatformVersion = line.Substring(0, z);
}
}
}
int y = line.IndexOf("Version=\"",System.StringComparison.InvariantCulture);
if(y >= 0)
{
int z = line.IndexOf("\"",y + 9,System.StringComparison.InvariantCulture);
if(z >= 0)
{
// We have the version, no need to read on.
return line.Substring(y + 9,z - y - 9);
}
}
}
}
}
return "Unknown";
#else
return "Unknown";
#endif
} |
En fait, il me retourne le Unknown du dernier #else
Je ne comprends pas comment ça fonctionne ça ...
Merci