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

发布于 2024-10-06 11:42:42 字数 674 浏览 4 评论 0原文

在 app.config 中,我提供了一个cycle字符串值:“Monday”、“Tuesday”、...、“Daily”。我想根据该值分配一个 枚举。仅使用 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,我正在寻找更好的方法。

In app.config, I supply a cycle string value: "Monday", "Tuesday", ..., "Daily". From that value I wanted to assign a <Flags()> enum. Simply using DayOfWeek does not give me the ability to flag a process as a daily routine. Is there an available .Net class that does provide the day of week as a flag?

In the meantime, I devised the following:

<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

It feels somewhat hackish and I am looking for a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情旳空白 2024-10-13 11:42:42

以下是 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
}

Here is a link to a DaysOfWeek enum (used for setting recurrences) for PocketOutlook on Windows Mobile:
http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.daysofweek.aspx

It defines an enum like this:

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

I would define a similar enum with an additional one for Daily (and maybe for every weekday and every weekend day:

[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
}
苍风燃霜 2024-10-13 11:42:42

这会起作用,对吧?

<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(星期六)开始

this will work, right?

<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

or this

<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

since DayOfWeek start from 0 (Sunday) to 6 (Saturday)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文