如何在方法中访问属性值

时间:2014-02-04 21:41:27

标签: c# properties httpwebrequest

我在GetData()方法中设置属性,我想在同一个类中的所有其他方法中获取属性的更新值。它适用于没有httpWebRequest,httpWebResponse参数的方法,但在httpWebRequest,httpWebResponseparameter的方法中不起作用。请指导我如何使用httpWebRequest,httpWebResponse Parameters。

获取方法中的属性值
  class ContentFetcher
  {
    Download download;
    private bool _IsEverything = false;

    public void GetData(Download download)
    {
      this.download = download;
      _IsEverything = download.IsEverything ;

      MessageBox.Show(_isEverything.ToString());    //output is "True"
    }

    public void ProcessHtmlContent(HttpWebRequest request, HttpWebResponse response)
    {
      MessageBox.Show(_IsEverything.ToString());   // Output is false while it should be true.
    }


    public void ProcessCssContent(HttpWebRequest request, HttpWebResponse response)
    {
      MessageBox.Show(_IsEverything.ToString());   // Output is false while it should be true.
    }

    public void FetchData(){
        ..........
        ..........
        ..........
     switch (getContentType(content_type_primary))
        {
            case "html":
                ProcessHtmlContent(request, response);
                break;
            case "javascript":
                ProcessJavascriptContent(request, response);
                break;
            case "image":
                ProcessImageContent(request, response);
                break;
            case "css":
                ProcessCssContent(request, response);
                break;
         }
      }
  }

我在MainWindow.xaml.cs中调用GetData():

public void StartDownloading()
{
        ..........
        ..........
        ..........
  Download download = new Download();
  download.IsEverything = true;

  ContentFetcher cf = new ContentFetcher();
  cf.GetData(download);
  cf.FetchData();
}

并在Download.cs中

 private bool _IsEverything ;
        public bool IsEverything
        {
            get { return _IsEverything; }
            set
            {
                if (_IsEverything == value)
                    return;

                _IsEverything = value;
                this.OnPropertyChanged("IsEverything");
            }
        }

0 个答案:

没有答案