C# 4.0 包含属性的类枚举对象
我试图找到一种方法,使一个类充满静态对象,每个对象都可以有各种静态属性 我希望能够传递这些属性,甚至将它们设置为其他对象的静态属性,还希望能够在对象之间切换 下面是一个例子来说明我的意思: 创建和发送消息 这不希望编译,因为它不允许我切换Order.SecurityType对象 市场秩序类 MessageProperties类C# 4.0 包含属性的类枚举对象,c#-4.0,enums,properties,switch-statement,C# 4.0,Enums,Properties,Switch Statement,我试图找到一种方法,使一个类充满静态对象,每个对象都可以有各种静态属性 我希望能够传递这些属性,甚至将它们设置为其他对象的静态属性,还希望能够在对象之间切换 下面是一个例子来说明我的意思: 创建和发送消息 这不希望编译,因为它不允许我切换Order.SecurityType对象 市场秩序类 MessageProperties类 枚举非常适合我正在尝试做的事情,只是很难拥有一个枚举值的多个属性。我曾考虑过使用枚举上的属性来设置属性,但获取这些属性与获取对象的静态属性相比要慢得多,而且我的应用程序对
枚举非常适合我正在尝试做的事情,只是很难拥有一个枚举值的多个属性。我曾考虑过使用枚举上的属性来设置属性,但获取这些属性与获取对象的静态属性相比要慢得多,而且我的应用程序对速度/延迟非常敏感 也许有更好的方法来完成我想做的事情吗 提前感谢您的帮助
William除了很难拥有一个枚举值的多个属性外,您能澄清一下您在这里的意思吗?很难理解您想要实现什么,不知道为什么,可能是因为night或question不清楚…基本上我希望message对象能够具有类似ExchangeDestination的属性,并且我希望该属性的值也具有属性,以便当不同的方法引用message对象时,他们可以调用消息对象的属性,然后引用该属性的属性。。。我知道这是相当混乱的-基本上我想有一个对象枚举。。。
class Program
{
static void Main(string[] args)
{
MarketOrder Order = new MarketOrder("DELL", MessageProperties.SecurityType.Equity, MessageProperties.ExchangeDestination.ARCA.PostOnly);
SendOrder(Order);
Console.ReadLine();
}
public static void SendOrder(MarketOrder Order)
{
switch (Order.SecurityType)
{
case MessageProperties.SecurityType.Equity:
// Equity sending logic here
break;
case MessageProperties.SecurityType.Option:
// Option sending logic here
break;
case MessageProperties.SecurityType.Future:
// Future sending logic here
break;
}
}
}
public class MarketOrder
{
public readonly string Symbol;
public readonly MessageProperties.SecurityType SecurityType;
public readonly MessageProperties.ExchangeDestination ExchangeDestination;
public MarketOrder(string Symbol, MessageProperties.SecurityType SecurityType, MessageProperties.ExchangeDestination ExchangeDestination)
{
this.Symbol = Symbol;
this.SecurityType = SecurityType;
this.ExchangeDestination = ExchangeDestination;
}
}
public abstract class MessageProperties
{
public class ExchangeDestination
{
public readonly string Value;
public readonly double ExchangeFee;
public ExchangeDestination(string Value, double ExchangeFeed)
{
this.Value = Value;
this.ExchangeFee = ExchangeFee;
}
public abstract class ARCA
{
public static ExchangeDestination Only = new ExchangeDestination("ARCA.ONLY", 0.01);
public static ExchangeDestination PostOnly = new ExchangeDestination("ARCA.ONLYP", 0.02);
}
public abstract class NYSE
{
public static ExchangeDestination Only = new ExchangeDestination("NYSE.ONLY", 0.01);
public static ExchangeDestination PostOnly = new ExchangeDestination("NYSE.ONLYP", 0.03);
}
}
public class SecurityType
{
public readonly string Value;
public SecurityType(string Value)
{
this.Value = Value;
}
public static SecurityType Equity = new SecurityType("EQ");
public static SecurityType Option = new SecurityType("OPT");
public static SecurityType Future = new SecurityType("FUT");
}
}