Skip to content

WeavingWithoutAddingAReference

Simon Cropp edited this page Jul 30, 2012 · 2 revisions

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

1. Allow the weaving task to remove the reference ==

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

2. Have no reference in your project file ==

If you would prefer not to have any reference to PropertyChanging.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 PropertyChanging
{
    [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 PropertyChanging
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
    public class DoNotNotifyAttribute : Attribute
    {
    }
}

DependsOnAttribute

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

a