-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Portability.DoNotHardcodePathsRule(git)
Sebastien Pouliot edited this page Mar 2, 2011
·
1 revision
Assembly: Gendarme.Rules.Portability
Version: git
This rule checks for strings that contain valid paths, either under Unix or Windows file systems. Path literals are often not portable across operating systems (e.g. different path separators). To ensure correct cross-platform functionality they should be replaced by calls to Path.Combine and/or Environment.GetFolderPath.
Bad example:
void ReadConfig ()
{
using (FileStream fs = File.Open ("~/.local/share/myapp/user.config")) {
// read configuration
}
}
Good example:
void ReadConfig ()
{
string config_file = Environment.GetFolderPath (SpecialFolder.LocalApplicationData);
config_file = Path.Combine (Path.Combine (config_file, "myapp"), "user.config");
using (FileStream fs = File.Open (config_file)) {
// read configuration
}
}
- This rule is available since Gendarme 2.0
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!