public
Created

INPC Weaver example

  • Download Gist
AfterWeaving.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
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));
}
}
}
BeforeWeaving.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.