Found **[this code](https://github.com/SimonCropp/Experiments/tree/master/CaliburnMicroNoBaseClass)**

Here's the gyst:

**ViewModel:**

```
[ExtendWith(typeof(ValidationTemplate))]
public class PersonViewModel :INotifyPropertyChanged
{
    public string GivenNames { get; set; }
    public string FamilyName { get; set; }

    public string FullName
    {
        get
        {

            return string.Format("{0} {1}", GivenNames, FamilyName);
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

```

**ExtendWithAttribute**

```
public class ExtendWithAttribute : Attribute
{
    public ExtendWithAttribute(Type type)
    {
    }
}

```

**ValidationTemplate**

```
public class ValidationTemplate : IDataErrorInfo
{
    private INotifyPropertyChanged target;

    public object Target
    {
        get
        {
            return target;
        }
        set
        {
            target = (INotifyPropertyChanged)value;
            validator = ValidationFactory.GetValidator(target.GetType());
            validationResult = validator.Validate(Target);
            target.PropertyChanged += Validate;
        }
    }

    private void Validate(object sender, PropertyChangedEventArgs e)
    {
        if (validator != null)
        {
            validationResult = validator.Validate(target);
        }
    }

    private IValidator validator;
    private ValidationResult validationResult;

    public string Error
    {
        get
        {
            return string.Join(Environment.NewLine, validationResult.Errors.Select(x => x.ErrorMessage).ToArray());
        }
    }

    public string this[string propertyName]
    {
        get
        {
            return string.Join(Environment.NewLine, validationResult.Errors.Where(x => x.PropertyName == propertyName).Select(x => x.ErrorMessage).ToArray());
        }
    }
}

```

If we make an instance of PersonViewModel, we get:

1. ValidationTemplate instantiated - I **assume** because we passed in the type into this ExtendWith attribute .NET automatically instantiates the type, but I can't find any info anywhere that confirms this behavior
2. ValidationTemplate Target property is being invoked "magically" and it receives reference to the PersonViewModel. Which .NET behavior piece calls into this? I can't find any documentation that describes this behavior - seems like it relies on naming convention? Is there are other properties that can get populated? What wizardry is this :)
3. If this object is bound in XAML the validation just works, but ViewModel doesn't directly implement *IDataErrorInfo*, which is what WPF hooks into to get it's validation working. Yet it works, somehow it's able to use this ValidationTemplate arbitrary object from somewhere.

**Update**: So after I examined the PersonViewModel in debugger the following yield interesting answers:

```
var viewModel = new PersonViewModel();
var isDataErrorInfo = viewModel is IDataErrorInfo; // true
var isDataErrorInfo = viewModel is ValidationTemplate; // false

```

The code is based on Caliburn.Micro, bootstrapper is vanilla with nothing in it. I instantiated PersonViewModel by hand to confirm that it's not WPF specific behavior that calls into the extender class, and I did get setters/getters on Target property firing. 

Can someone please explain all these strange behaviors. I have a feeling this is some internal/undocumented features/hacks of .NET framework.