Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态计算依赖项_C#_Algorithm_Dynamic - Fatal编程技术网

C# 动态计算依赖项

C# 动态计算依赖项,c#,algorithm,dynamic,C#,Algorithm,Dynamic,我在为我的应用程序开发算法时遇到困难。应用程序需要非常灵活,以适应多种设备和多种样式 以下是其中一个设备的规则之一: 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

我在为我的应用程序开发算法时遇到困难。应用程序需要非常灵活,以适应多种设备和多种样式

以下是其中一个设备的规则之一:

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
现在我可以为这个特定的设备编写代码,但是有多个设备使用不同的语句集。目前,我正在从文件中读取这些值。这允许我在不更改代码的情况下更新程序支持的设备数量,从而减少维护


有什么建议吗?

您可以使用表格方式保存输入值和相应的配置设置,然后只需在字典中查找即可。 大概是这样的:

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)];
}
struct ConfigKey
{
公共只读int样式;
公共只读字符串斜率;
公共配置键(int样式,字符串斜率)
{
这个。风格=风格;
这个。斜率=斜率;
}
公共覆盖布尔等于(对象对象对象)
{
如果(!(obj是配置键))
{
返回false;
}
ConfigKey other=(ConfigKey)obj;
返回this.Style==other.Style&&this.Slope==other.Slope;
}
公共覆盖int GetHashCode()
{
返回样式。GetHashCode()^Slope.GetHashCode();
}
}
结构配置
{
字符串范围{get;set;}
双步骤{get;set;}
}
Dictionary conf=new Dictionary();
公共配置GetConfig(int样式,字符串斜率)
{
返回conf[新配置键(样式、坡度)];
}

你的帖子没有透露太多细节,但它确实说你已经有了解决方案。你目前的方法有什么问题?