需要保存一些具有不同detial类型的选项,因此我们使用具有静态属性的staic类。
public class DynamicVariableSheet
{
public static class SendBackOptions
{
public static byte IsCancellingBrothersNode { get; set; }
}
public static class ForwardOptions
{
public static string SignForwardCompareType { get; set; }
public static float SignForwardCompleteOrder { get; set; }
}
}
然后,DynamicVariableSheet将是另一个类的属性:
public class Runner
{
public string RunnerName { get; set; }
public DynamicVariableSheet DynamicVariableSheet { get; set; }
}
我可以使用以下代码直接设置一些值:
DynamicVariableSheet.SendBackOptions.IsCancellingBrothersNode = 1;
但是如何像这些代码一样如何使属性变量为Runner类设置值。
var runner = new Runner();
runner.AppName = "Order";
runner.DynamicVariableSheet.SendBackOptions.IsCancellingBrothersNode = 1;
答案 0 :(得分:0)
您应将DynamicVariableSheet
设为Runner
类的静态成员
答案 1 :(得分:0)
好吧,因为它们是静态类,所以只能像这样访问它们: DynamicVariableSheet.SendBackOptions.IsCancellingBrothersNode =值;
如果要这样访问: Runner.DynamicVariableSheet.SendBackOptions.IsCancellingBrothersNode = 1;
将SendBackOptions和ForwardOptions转换为非静态类,并将其放置在DynamicVariableSheet之外。现在,您可以将它们声明为属性。
我在下面为您做到了
public class DynamicVariableSheet
{
public SendBackOptions SendBackOptions { get; set; }
public ForwardOptions ForwardOptions { get; set; }
}
public class SendBackOptions
{
public byte IsCancellingBrothersNode { get; set; }
}
public class ForwardOptions
{
public string SignForwardCompareType { get; set; }
public float SignForwardCompleteOrder { get; set; }
}