Export (0) Print
Expand All

Module.GetCustomAttributes Method (Boolean)

Returns all custom attributes.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual Object[] GetCustomAttributes(
	bool inherit
)

Parameters

inherit
Type: System.Boolean
This argument is ignored for objects of this type.

Return Value

Type: System.Object[]
An array that contains all the custom attributes.

Implements

ICustomAttributeProvider.GetCustomAttributes(Boolean)

The following example defines an attribute and applies it to the example's module. When the example runs, it retrieves the attributes that were applied to the module and displays them.


using System;
using System.Reflection;

//Define a module-level attribute.
[module: MySimpleAttribute("module-level")]

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Module[] moduleArray = Assembly.GetExecutingAssembly().GetModules();
        Module myModule = moduleArray[0];
        object[] attributes = myModule.GetCustomAttributes(true);
        foreach (Object o in attributes)
        {
            outputBlock.Text += 
               String.Format("Found this attribute on myModule: {0}.\n", o.ToString());
        }
    }
}

//A very simple custom attribute.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Module)]
public class MySimpleAttribute : Attribute
{
    private string name;

    public MySimpleAttribute(string newName)
    {
        name = newName;
    }
}

/* This example produces output similar to the following:

Found this attribute on myModule: MySimpleAttribute.
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft