# GetMethodsWithAttribute

> Retrieves an unordered collection of methods marked with the T attribute.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## GetMethodsWithAttribute\<T>()

Retrieves an unordered collection of methods marked with the **T** attribute.

```csharp
public static TypeCache.MethodCollection GetMethodsWithAttribute<T>() where T : Attribute
```

### Returns

| Type                                                                                          | Description                                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) | Returns an unordered [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) collection of methods marked with the **T** attribute. If assemblyName is specified, returns only methods defined in this assembly. |

### Remarks

This method provides fast access to all methods loaded from a given assembly or all Unity domain assemblies and marked with a specific attribute. Methods marked with ancestors of the specified attribute are also included in the result. The order of results is undefined.

**Note**: [TypeCache.GetMethodsWithAttribute](/engine/6000.6/script-reference/unityeditor/typecache/getmethodswithattribute.md) does not support pseudo-attributes. For more information, refer to Microsoft's documentation on [attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes) and [pseudo-attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/pseudo-attributes). Pseudo-attributes are handled specially rather than as custom attributes, and `TypeCache` does not provide explicit support for caching them.

```csharp
using UnityEditor;
using System.Collections.Generic;

public class Example
{
    static void ScanInitializeOnLoadMethods()
    {
        var extractedMethods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>();
        foreach (var m in extractedMethods)
        {
            if (m.IsPrivate)
                continue;
            //...
        }

        for (int i = 0; i < extractedMethods.Count; ++i)
        {
            if (extractedMethods[i].IsPublic)
                continue;
            //...
        }
    }
}
```

The returned [TypeCache.MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) is read-only and thread-safe. The order of [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) in the collection is undefined.

## GetMethodsWithAttribute(Type)

Retrieves an unordered collection of methods marked with the **T** attribute.

```csharp
public static TypeCache.MethodCollection GetMethodsWithAttribute(Type attrType)
```

### Parameters

**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): Attribute type.

### Returns

| Type                                                                                          | Description                                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) | Returns an unordered [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) collection of methods marked with the **T** attribute. If assemblyName is specified, returns only methods defined in this assembly. |

### Remarks

This method provides fast access to all methods loaded from a given assembly or all Unity domain assemblies and marked with a specific attribute. Methods marked with ancestors of the specified attribute are also included in the result. The order of results is undefined.

**Note**: [TypeCache.GetMethodsWithAttribute](/engine/6000.6/script-reference/unityeditor/typecache/getmethodswithattribute.md) does not support pseudo-attributes. For more information, refer to Microsoft's documentation on [attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes) and [pseudo-attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/pseudo-attributes). Pseudo-attributes are handled specially rather than as custom attributes, and `TypeCache` does not provide explicit support for caching them.

```csharp
using UnityEditor;
using System.Collections.Generic;

public class Example
{
    static void ScanInitializeOnLoadMethods()
    {
        var extractedMethods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>();
        foreach (var m in extractedMethods)
        {
            if (m.IsPrivate)
                continue;
            //...
        }

        for (int i = 0; i < extractedMethods.Count; ++i)
        {
            if (extractedMethods[i].IsPublic)
                continue;
            //...
        }
    }
}
```

The returned [TypeCache.MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) is read-only and thread-safe. The order of [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) in the collection is undefined.

## GetMethodsWithAttribute\<T>(string)

Retrieves an unordered collection of methods marked with the **T** attribute.

```csharp
public static TypeCache.MethodCollection GetMethodsWithAttribute<T>(string assemblyName) where T : Attribute
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional assembly name.

### Returns

| Type                                                                                          | Description                                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) | Returns an unordered [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) collection of methods marked with the **T** attribute. If assemblyName is specified, returns only methods defined in this assembly. |

### Remarks

This method provides fast access to all methods loaded from a given assembly or all Unity domain assemblies and marked with a specific attribute. Methods marked with ancestors of the specified attribute are also included in the result. The order of results is undefined.

**Note**: [TypeCache.GetMethodsWithAttribute](/engine/6000.6/script-reference/unityeditor/typecache/getmethodswithattribute.md) does not support pseudo-attributes. For more information, refer to Microsoft's documentation on [attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes) and [pseudo-attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/pseudo-attributes). Pseudo-attributes are handled specially rather than as custom attributes, and `TypeCache` does not provide explicit support for caching them.

```csharp
using UnityEditor;
using System.Collections.Generic;

public class Example
{
    static void ScanInitializeOnLoadMethods()
    {
        var extractedMethods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>();
        foreach (var m in extractedMethods)
        {
            if (m.IsPrivate)
                continue;
            //...
        }

        for (int i = 0; i < extractedMethods.Count; ++i)
        {
            if (extractedMethods[i].IsPublic)
                continue;
            //...
        }
    }
}
```

The returned [TypeCache.MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) is read-only and thread-safe. The order of [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) in the collection is undefined.

## GetMethodsWithAttribute(Type, string)

Retrieves an unordered collection of methods marked with the **T** attribute.

```csharp
public static TypeCache.MethodCollection GetMethodsWithAttribute(Type attrType, string assemblyName)
```

### Parameters

**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): Attribute type.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional assembly name.

### Returns

| Type                                                                                          | Description                                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) | Returns an unordered [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) collection of methods marked with the **T** attribute. If assemblyName is specified, returns only methods defined in this assembly. |

### Remarks

This method provides fast access to all methods loaded from a given assembly or all Unity domain assemblies and marked with a specific attribute. Methods marked with ancestors of the specified attribute are also included in the result. The order of results is undefined.

**Note**: [TypeCache.GetMethodsWithAttribute](/engine/6000.6/script-reference/unityeditor/typecache/getmethodswithattribute.md) does not support pseudo-attributes. For more information, refer to Microsoft's documentation on [attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/attributes) and [pseudo-attributes](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/pseudo-attributes). Pseudo-attributes are handled specially rather than as custom attributes, and `TypeCache` does not provide explicit support for caching them.

```csharp
using UnityEditor;
using System.Collections.Generic;

public class Example
{
    static void ScanInitializeOnLoadMethods()
    {
        var extractedMethods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>();
        foreach (var m in extractedMethods)
        {
            if (m.IsPrivate)
                continue;
            //...
        }

        for (int i = 0; i < extractedMethods.Count; ++i)
        {
            if (extractedMethods[i].IsPublic)
                continue;
            //...
        }
    }
}
```

The returned [TypeCache.MethodCollection](/engine/6000.6/script-reference/unityeditor/typecache/methodcollection.md) is read-only and thread-safe. The order of [FrameDataView.MethodInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/methodinfo.md) in the collection is undefined.
