0
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;

private として作成した場合、 likeで_targetCredntials定義されたプロパティは、 public として定義されていない限りシリアル化されません。プライベートに保ちながら、シリアル化できる方法はありますか??NetworkCrendtialHolderUserNameDomain_targetCredentialsUserNameDomain_targetCredential

4

0 に答える 0