相关疑难解决方法(0)

如何在我的属性中设置动态值

我想将动态变量作为参数传递给我的属性.在这里,我想使用Environment.MachineName,请参阅下面的代码:

public interface IMonitoringViewModelConfiguration : IConfigurationContainer
{
    [ConfigurationKey("MonitoringService", Environment.MachineName)]
    string ConnectionString { get; }
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:错误1属性参数必须是属性参数类型Abc.ServiceBus.Monitoring.ViewModel的常量表达式,typeof表达式或数组创建表达式

为了传递我的Environment.MachineName,是否有尽可能干净的解决方法?

谢谢.

约翰

PS:我发现了一些谈论这个案子的文章,但它已经写成2 - 3年前了.但今天,来自.NET 4.0的clr能提供一些不错的解决方案吗?

c# attributes

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

attributes ×1

c# ×1