] or a similar line (but without ...">

C # square brackets and more / less than

In C #, you can see things like:

[<DllImport("myUnmanagedDLL.dll")>] 

or a similar line (but without more / less characters):

 [assembly: AssemblyTitle("MyProject")] 

I know that the first is called an attribute (it has the signs gt and lt) and can be used to add some kind of metadata to methods, types, etc., but what does the syntax of the second mean? I am trying to translate something with this syntax into F #, namely this line:

 [MonoMac.Foundation.Register("AppDelegate")] 
+4
source share
3 answers

but what does the syntax of the second mean?

This means that the attribute applies to the assembly, and not to the type (class or structure) or member.

In F #, the line you are trying to translate should be:

 [<MonoMac.Foundation.Register("AppDelegate")>] 

Seeing no more, it is impossible to determine where it should be applied (type, method, etc.). I suspect that this will go to the definition of type in F #, although given that this is commonly used in the C # class.

As a side note [<DllImport("myUnmanagedDLL.dll")>] invalid C # is the F # syntax. C # uses [Attribute] for attributes (and VB.Net uses <Attribute> ).

+7
source

In case this is useful - in F #, assembly level attributes are usually applied to an empty do block:

 [<assembly: AssemblyTitle("MyProject")>] do () 
+6
source

I think you are confusing C # with VB.NET syntax

In VB.NET it is <DllImport("myUnmanagedDLL.dll")> while in C # it [DllImport("myUnmanagedDLL.dll")] is unsigned more or less.

The second assembly attribute is used to apply the attribute to the entire assembly, not just a specific class, method, or property

+3
source

All Articles