为什么这个扩展方法不初始化返回的对象?

Why does this extension method not initialize the returned object?

我写了一个通用的扩展助手方法来初始化 SoapHeader 的一些参数,但是它没有更新返回的对象。

我错过了什么?

using System.Web.Services.Protocols;

    public class Header: SoapHeader {}

    public class WS {
      public Header securityHeader {
        get;
        set;
      }

    }
    public static class SecurityHeaderExtensions {

      public static T GetSecurityHeader < T > (this T header, string actor, string role) where T: SoapHeader, new() {

        T result = new T() {
          Actor = actor, Role = role
        };

        Console.WriteLine("Actor: " + actor); //prints actor
        Console.WriteLine("Actor: " + result.Actor); //prints blank
        return result;

      }
    }

    void Main() {
      var ws = new WS();
      ws.securityHeader = ws.securityHeader.GetSecurityHeader("actor", null);

    }

看来ActorRole在内部是同一个字段。

将其设置为 actor 然后将其设置为 null 意味着它是 null.

The recipient of that data, known as the SOAP Role in version 1.2 of the SOAP specification and the SOAP Actor in version 1.1