동일한 코드를 사용하여 Windows와 Mobile을 실행합니다.
모바일 기기 단어 PocketPC
프로젝트의 속성에서 정의를 따라서, 당신이 (당신이 C#으로 코딩되어 있기 때문에) 할 일은 다음과 같습니다
는
public static bool CreateDirectoryWithPermission(string path) {
bool ok = false;
DirectoryInfo dir = new DirectoryInfo(path);
#if !PocketPC
try {
DirectorySecurity ds;
if (dir.Exists) {
ds = dir.GetAccessControl();
} else {
ds = dir.Parent.GetAccessControl();
}
string user = Environment.UserDomainName + @"\" + Environment.UserName;
FileSystemAccessRule rule = new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow);
ds.AddAccessRule(rule);
dir.Create(ds);
ok = true;
} catch (Exception) { }
#endif
if (!ok) {
try {
dir.Create();
ok = true;
} catch (Exception) { }
}
return ok;
}
내가 제대로 기억한다면, System.Security.AccessControl
는 아래에 정의되어 있지 않습니다 Windows Mobile이므로 DirectorySecurity
은 정의되지 않았습니다.
UPDATE : 여기
이 관심있는 일을 할 수있는 또 다른 방법은 다음과 같습니다, 완전히 별도의 네임 스페이스에 직렬화 클래스를 만듭니다 두 프로젝트 모두에 해당 네임 스페이스를 사용하는 WebService에에서 직렬화 된 데이터를 전달 모바일 장치. 나는 또한 그렇게한다. 그러나 더 많은 코드가있다.
namespace LocksAnimal {
[Serializable()]
public class Animal {
private string name;
public Animal() {
name = "Lock";
}
public string GetName() {
#ifdef PocketPC
return name + " (Mobile Version)";
#else
return name + " (Webservice Version)";
#endif
}
}
}
WebService에 버전은 물론, 더 상세한 정보를 확인할 수 (GetAccessControl()
등은 첫 번째 코드 세그먼트에 도시).
이 아이디어가 도움이되기를 바랍니다.
2 개의 클래스를 생성하면 유지 보수에 심각한 영향을 미칩니다. XML 또는 JSON을 고려하십시오. –