public class NetworkCredentialHolder
{
public NetworkCredentialHolder()
{
_networkCred = new NetworkCredential();
}
public string UserName
{
get { return _networkCred.UserName; }
set { _networkCred.UserName = value; }
}
public string Domain
{
get { return _networkCred.Domain; }
set { _networkCred.Domain = value; }
}
}
public class SPS2003NetworkConfiguration
{
public SPS2003NetworkConfiguration()
{
_targetCredentials = new NetworkCredentialHolder();
}
private NetworkCredentialHolder _targetCredentials;
}
class Program
{
static void Main(string[] args)
{
var netConfiguration = new SPS2003NetworkConfiguration();
netConfiguration.SetGlobalCredentials("sanz", "pass@word1TestPassed");
var sb = new StringBuilder();
var writer = new StringWriter(sb);
XmlSerializer serializer = new XmlSerializer(typeof(SPS2003NetworkConfiguration));
serializer.Serialize(writer, netConfiguration);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
XmlSerializer serializer = new XmlSerializer(typeof(SPS2003NetworkConfiguration));
object obj = serializer.Deserialize(reader);
var netConfiguration = (SPS2003NetworkConfiguration)obj;
var encryptedPwd = netConfiguration.TargetCredentials.SecurePassword;
}
}
嗨,我在这里创建了
private NetworkCredentialHolder _targetCredentials;
当我创建_targetCredntials
为私有时,NetworkCrendtialHolder
likeUserName
下定义的属性Domain
不会序列化,除非_targetCredentials
定义为公共。有什么办法可以序列化UserName
,Domain
同时保持_targetCredential
私有?