繁体   English   中英

如果使用默认构造函数,DependencyAttribute实例将具有什么名称?

[英]What name will DependencyAttribute instance have if default constructor is used?

我有一个代码:

[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;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM