Add support for DefaultValueAttribute
DefaultValueAttribute
Namespace System.ComponentModel has this little jewel called DefaultValueAttribute. According to documentation:
You can create a DefaultValueAttribute with any value. A member's default value is typically its initial value. A visual designer can use the default value to reset the member's value. Code generators can use the default values also to determine whether code should be generated for the member.
History
Back in 2010 I've written an extension for Unity 2.x.
Types of dependencies
Implicit
public void TestMethod(object @implicit) { }
Implicit dependencies are imported as required. Resolution fails if value can not be resolved.
Implicit with default value
public TestType(int @implicit = 33) { }
Any default value provided automatically makes dependency optional! Resolution will not fail if dependency could not be resolved. The default value will be used instead.
decorated with DefaultValueAttribute
public void TestMethod([DefaultValue("value")] string @implicit) { }
Default value attribute is the same as if default is provided in code.
with default and decorated with DefaultValueAttribute
public TestType([DefaultValue(44)] int @implicit = 33) { }
If both: DefaultValueAttribute and the default value are provided, the attribute takes precedence. In case attribute and default value are defined at different levels of inheritance hierarchy, child definition wins.
Annotated
[Dependency]
public int Field;
[OptionalDependency]
public string Property { get; set; }
Annotated and with default value
[Dependency]
public int Field = 111;
decorated with DefaultValueAttribute
[DefaultValue(55)]
[Dependency]
public int Field;
[DefaultValue("some_value")]
[OptionalDependency]
public string Property { get; set; }
with default and decorated with DefaultValueAttribute
[DefaultValue(55)]
[Dependency]
public int Field = 111;