开发者

Can I change the T4 for a Silverlight WCF Data Service ServiceReference?

开发者 https://www.devze.com 2023-04-05 06:55 出处:网络
I have a WCF Data Service in my web app. I added a service reference using the \"Add New Service Reference\" command in my Silverlight application. I was looking at the Reference.cs file VS generates

I have a WCF Data Service in my web app. I added a service reference using the "Add New Service Reference" command in my Silverlight application. I was looking at the Reference.cs file VS generates for me and noticed the setters don't check for a change before calling OnPropertyChanged. I'd like to change this behavior. Can I overrride the T4 template without having to override all the code generation? If it's possible how would I go about doing it?

original generated code

 /// <summary>
 /// There are no comments for Property Title in the schema.
 /// </summary>
 [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Services.Design", "1.0.0")]
 public开发者_如何转开发 string Title
 {
    get
    {
         return this._Title;
    }
    set
    {
        this.OnTitleChanging(value);
        this._Title = value;
        this.OnTitleChanged();
        this.OnPropertyChanged("Title");
    }
 }

Desired change:

  /// <summary>
  /// There are no comments for Property Title in the schema.
  /// </summary>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Services.Design", "1.0.0")]
  public string Title
  {
     get
     {
         return this._Title;
     }
     set
     {
        // change to 
        if(this._Title != value) {
            this.OnTitleChanging(value);
            this._Title = value;
            this.OnTitleChanged();
            this.OnPropertyChanged("Title");
        }
      }
   }


Unfortunately the Add Service Reference for WCF Data Services doesn't use T4 yet. So there's no easy way to do this. Feel free to vote for the feature here: http://blogs.msdn.com/b/astoriateam/archive/2010/09/10/what-do-you-want-to-see-added-changed-in-wcf-data-services.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号