2013-02-26 61 views
-1

。应用程序需要非常灵活,以便考虑多个设备和多种样式。动态占我有困难开发我的应用程序的算法依赖

这里是为设备之一的规则之一:

Only for styles 1,2,3,8,9,10 
If slope = I2t 
    Range: 2-24 
    Step 0.5 
If slope = I4t 
    Range: 1-5 
    Step 0.5 
If slope = Mod Inv 
    Range: 0.1-5.0 
    Step 0.1 
If slope = Very Inv or Ext Inv 
    Range 0.2-5.0 
    Step 0.1 

Ony for Styles 4,5,6,7 
If slope = I2t 
    Range: 2-24 
    Step 0.5 
If slope = I4t 
    Range: 1-5 
    Step 0.5 
If slope = IEC-A 
    Range: 0.05 - 1.00 
    Step 0.05 
If slope = IEC-B 
    Range: 0.10 - 1.00 
    Step 0.05 
If slope = IEC-C 
    Range: 0.20-1.00 
    Step 0.05 

现在我能为这个特定的设备代码这件事,但也有一组不同的报表的多个设备。目前我正在从文件中读取这些值。这使我可以在不更改代码的情况下更新程序支持的设备数量,从而降低维护成本。

有什么建议吗?

+0

您的文章没有给出太多细节了,但它说,你有一个解决办法了。你目前的方法有什么问题? – 2013-02-26 13:28:38

回答

0

您可以使用表的方式保存输入值和相应的配置设置,然后就看在字典。 事情是这样的:

struct ConfigKey 
{ 
    public readonly int Style; 
    public readonly string Slope; 
    public ConfigKey(int style, string slope) 
    { 
     this.Style = style; 
     this.Slope= slope; 
    } 
    public override bool Equals(object obj) 
    { 
     if (!(obj is ConfigKey)) 
     { 
      return false; 
     } 
     ConfigKey other = (ConfigKey)obj; 
     return this.Style == other.Style && this.Slope == other.Slope; 
    } 

    public override int GetHashCode() 
    { 
     return Style.GetHashCode()^Slope.GetHashCode(); 
    } 
} 
struct Config 
{ 
    String Range {get; set;} 
    Double Step { get; set; } 
} 
Dictionary<ConfigKey, Config> conf = new Dictionary<ConfigKey, Config>(); 

public Config GetConfig(int style, string slope) 
{ 
    return conf[new ConfigKey(style, slope)]; 
} 
相关问题