Skip to content

WeavingWithoutAddingAReference

Simon Cropp edited this page Jan 6, 2015 · 5 revisions

There are two types of avoiding a reference to PropertyChanged.dll

1. Allow the weaving task to remove the reference

Assuming you added a reference to PropertyChanged.dll to get access to the notify attributes. The weaving task will remove all references to PropertyChanged.dll after your build. The resultant assembly will not need PropertyChanged.dll.

2. Have no reference in your project file

If you would prefer not to have any reference to PropertyChanged.dll, and you want to user the attribute approach to weaving you will need to implement your own attributes.

Note: Namespace, name and case is important. Not all attributes are required. See Attributes to work out what attributes you require.

NotifyPropertyAttribute

namespace PropertyChanged
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
    public class AlsoNotifyForAttribute : Attribute
    {
        public AlsoNotifyForAttribute(string property){}
        public AlsoNotifyForAttribute(string property, params string[] otherProperties){}
    }
}

DoNotNotifyAttribute

namespace PropertyChanged
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
    public class DoNotNotifyAttribute : Attribute
    {
    }
}

DependsOnAttribute

namespace PropertyChanged
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
    public class DependsOnAttribute : Attribute
    {
        public DependsOnAttribute(string dependency){}
        public DependsOnAttribute(string dependency, params string[] otherDependencies){}
    }
}

DoNotCheckEqualityAttribute

namespace PropertyChanged
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class DoNotCheckEqualityAttribute : Attribute
    {
    }
}