如何使用DayOfWeek枚举来标记流程周期?

时间:2010-12-07 20:23:13

标签: vb.net enums dayofweek

在app.config中,我提供循环字符串值:“星期一”,“星期二”,......,“每日”。从那个值我想分配一个<Flags()>枚举。简单地使用DayOfWeek并不能让我将进程标记为日常例程。是否有一个可用的.Net类确实提供星期几作为标志?

与此同时,我设计了以下内容:

<Flags()> _
Public Enum enumExportCycle As Integer
    Monday = DayOfWeek.Monday
    Tuesday = DayOfWeek.Tuesday
    Wednesday = DayOfWeek.Wednesday + 1
    Thursday = DayOfWeek.Thursday + 4
    Friday = DayOfWeek.Friday + 11
    Saturday = DayOfWeek.Saturday + 26
    Sunday = DayOfWeek.Sunday + 64
    Daily = Monday Or Tuesday Or Wednesday Or Thursday Or Friday Or Saturday Or Sunday
End Enum

感觉有点hackish,我正在寻找更好的方式。

2 个答案:

答案 0 :(得分:5)

以下是Windows Mobile上PocketOutlook的DaysOfWeek枚举(用于设置重复)的链接: http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.daysofweek.aspx

它定义了一个这样的枚举:

[Flags] 
public enum DaysOfWeek
{
  Sunday = 1,
  Monday = 2,
  Tuesday = 4,
  Wednesday = 8,
  Thursday = 16,
  Friday = 32,
  Saturday = 64
}

我会为Daily定义一个类似的枚举,另外一个(也许是每个工作日和每个周末:

[Flags] 
public enum DaysOfWeek
{
  Sunday = 1,
  Monday = 2,
  Tuesday = 4,
  Wednesday = 8,
  Thursday = 16,
  Friday = 32,
  Saturday = 64,
  Daily = Sunday + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday,
  Weekdays = Monday + Tuesday + Wednesday + Thursday + Friday,
  Weekends = Sunday + Saturday
}

答案 1 :(得分:4)

这会起作用,对吧?

<Flags()> _
Public Enum enumExportCycle As Integer
    Monday = 1
    Tuesday = 2
    Wednesday = 4
    Thursday = 8
    Friday = 16
    Saturday = 32
    Sunday = 64
    Daily = Monday Or Tuesday Or Wednesday Or Thursday Or Friday Or Saturday Or Sunday
End Enum

或者

<Flags()> _
Public Enum enumExportCycle As Integer
    Monday = 2 ^ DayOfWeek.Monday
    Tuesday = 2 ^ DayOfWeek.Tuesday
    Wednesday = 2 ^ DayOfWeek.Wednesday
    Thursday = 2 ^ DayOfWeek.Thursday
    Friday = 2 ^ DayOfWeek.Friday
    Saturday = 2 ^ DayOfWeek.Saturday
    Sunday = 2 ^ DayOfWeek.Sunday
    Daily = Monday Or Tuesday Or Wednesday Or Thursday Or Friday Or Saturday Or Sunday
End Enum

因为DayOfWeek从0(星期日)到6(星期六)开始