What you need is "Enum.combine", see below link for more details:

[link:research.microsoft.com]

By on 7/17/2006 3:50 AM ()

And how about such code:

1
2
3
4
enum RuleTarget {
   Class = 0x0001, Delegate = 0x0002, Enum = 0x0004, Struct = 0x0008, 
   <b>AllTypes = Class | Delegate | Enum | Struct</b>,
}

?

Nemerle provides such ability in that way:

1
2
3
4
enum RuleTarget {
   | Class = 0x0001 | Delegate = 0x0002 | Enum = 0x0004 | Struct = 0x0008
   | <b>AllTypes = Class %| Delegate %| Enum %| Struct</b>
}
By on 3/10/2008 12:13 PM ()

In F# enums can be create using the following syntax (note you must explicitly give the members a value to distinguish it from a union type):

1
2
3
4
5
6
[<System.Flags>]
type RuleTarget =
   | Class = 0x0001 
   | Delegate = 0x0002
   | Enum = 0x0004
   | Struct = 0x0008

It's seems for the moment you can't reference enum members from there definition so you can't create a value "AllTypes" as a member (unless you work out its value). As a work around you can create a sperate value for all types:

1
let AllTypes = RuleTarget.Class ||| RuleTarget.Delegate ||| RuleTarget.Enum ||| RuleTarget.Struct

If this is really important to you send a feature request to the F# team, they've generally been quite good about small feature requests like this.

By on 3/11/2008 9:07 AM ()

It's seems for the moment you can't reference enum members from there definition so you can't create a value "AllTypes" as a member (unless you work out its value). As a work around you can create a sperate value for all types:

1
let AllTypes = RuleTarget.Class ||| RuleTarget.Delegate ||| RuleTarget.Enum ||| RuleTarget.Struct

I think you'll agree that this is not the same. Actually, I don't see any value of AllTypes when it is not an enum's member.

If this is really important to you send a feature request to the F# team, they've generally been quite good about small feature requests like this.

Important - is a wrong word for this. But, it is hell of a useful. I'll follow your advice and send a request ;)

By on 3/11/2008 10:56 AM ()

It's seems for the moment you can't reference enum members from there definition so you can't create a value "AllTypes" as a member (unless you work out its value). As a work around you can create a sperate value for all types:

1
let AllTypes = RuleTarget.Class ||| RuleTarget.Delegate ||| RuleTarget.Enum ||| RuleTarget.Struct

I think you'll agree that this is not the same. Actually, I don't see any value of AllTypes when it is not an enum's member.

I don't think I said it was the samething, I said it was a work arround and okay not a very good one ;). A better one is maybe to use F# binary litterals which make it a doodle to work flags:

1
2
3
4
5
6
7
[<System.Flags>]
type RuleTarget =
   | Class =    0b00000001 
   | Delegate = 0b00000010
   | Enum =     0b00000100
   | Struct =   0b00001000
   | AllTypes = 0b00001111
By on 3/12/2008 1:20 AM ()

A better one is maybe to use F# binary litterals which make it a doodle to work flags:

Yep! That what I'm doing. Thank you Robert!

By on 3/12/2008 1:47 AM ()

Use Enum.combine, e.g. fom a different example exercising the .NET reflection library:

1
2
3
4
5
6
7
8
open System.Reflection
let callStaticMethod (ty:Type) name args =
  ty.InvokeMember(name, 
    Enum.combine 
     [ BindingFlags.InvokeMethod; 
       BindingFlags.Static; 
       BindingFlags.Public; 
       BindingFlags.NonPublic ], null, null, args)

Cheers!

Don

By on 7/17/2006 3:50 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper