Skip to content

Instantly share code, notes, and snippets.

@distantcam
Created September 30, 2012 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save distantcam/3805842 to your computer and use it in GitHub Desktop.
Save distantcam/3805842 to your computer and use it in GitHub Desktop.
INPC Weaver example
public class SomeViewModel : INotifyPropertyChanged
{
private string <URL>k__BackingField;
public event PropertyChangedEventHandler PropertyChanged;
public string URL
{
[CompilerGenerated]
get
{
return this.<URL>k__BackingField;
}
[CompilerGenerated]
set
{
if (string.Equals(this.<URL>k__BackingField, value, StringComparison.Ordinal))
{
return;
}
this.<URL>k__BackingField = value;
this.OnPropertyChanged("HostName");
this.OnPropertyChanged("URL");
}
}
public string HostName
{
get
{
string result;
try
{
Uri typedURL = new Uri(this.URL);
result = typedURL.Host;
}
catch (UriFormatException)
{
result = "";
}
return result;
}
}
public virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class SomeViewModel : INotifyPropertyChanged
{
public string URL { get; set; }
public string HostName
{
get
{
try
{
var typedURL = new Uri(URL);
return typedURL.Host;
}
catch (UriFormatException)
{
return "";
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment