如果使用默认构造函数,依赖项属性实例将具有什么名称

本文关键字:实例 什么 属性 默认 构造函数 依赖 如果 | 更新日期: 2023-09-27 18:34:50

我有一个代码:

[Dependency] public string MyProperty { get; set; }

虽然DependencyAttribute类具有属性Name

在这种情况下,它将包含什么价值?

null还是nameof(MyProperty)

不幸的是,我还没有看到DependencyAttribute类的源代码。也许有人可以提供链接。

提前感谢!

如果使用默认构造函数,依赖项属性实例将具有什么名称

该值将为空。 在没有显式名称的情况下,null 是 Unity 使用的默认名称(例如,在调用 RegisterType() 时(。 具体就DependencyAttribute而言:

    public DependencyAttribute()
        : this(null) { }
    /// <summary>
    /// Create an instance of <see cref="DependencyAttribute"/> with the given name.
    /// </summary>
    /// <param name="name">Name to use when resolving this dependency.</param>
    public DependencyAttribute(string name)
    {
        this.name = name;
    }