Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetMethodsWithAttribute

Retrieves an unordered collection of methods marked with the T attribute.
Read time 4 minutesLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

GetMethodsWithAttribute<T>()

Retrieves an unordered collection of methods marked with the T attribute.
public static TypeCache.MethodCollection GetMethodsWithAttribute<T>() where T : Attribute

Returns

Type

Description

MethodCollectionReturns an unordered FrameDataView.MethodInfo 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 does not support pseudo-attributes. For more information, refer to Microsoft's documentation on attributes and pseudo-attributes. Pseudo-attributes are handled specially rather than as custom attributes, and
TypeCache
does not provide explicit support for caching them.
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 is read-only and thread-safe. The order of FrameDataView.MethodInfo in the collection is undefined.

GetMethodsWithAttribute(Type)

Retrieves an unordered collection of methods marked with the T attribute.
public static TypeCache.MethodCollection GetMethodsWithAttribute(Type attrType)

Parameters

attrType

Attribute type.

Returns

Type

Description

MethodCollectionReturns an unordered FrameDataView.MethodInfo 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 does not support pseudo-attributes. For more information, refer to Microsoft's documentation on attributes and pseudo-attributes. Pseudo-attributes are handled specially rather than as custom attributes, and
TypeCache
does not provide explicit support for caching them.
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 is read-only and thread-safe. The order of FrameDataView.MethodInfo in the collection is undefined.

GetMethodsWithAttribute<T>(string)

Retrieves an unordered collection of methods marked with the T attribute.
public static TypeCache.MethodCollection GetMethodsWithAttribute<T>(string assemblyName) where T : Attribute

Parameters

assemblyName

Optional assembly name.

Returns

Type

Description

MethodCollectionReturns an unordered FrameDataView.MethodInfo 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 does not support pseudo-attributes. For more information, refer to Microsoft's documentation on attributes and pseudo-attributes. Pseudo-attributes are handled specially rather than as custom attributes, and
TypeCache
does not provide explicit support for caching them.
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 is read-only and thread-safe. The order of FrameDataView.MethodInfo in the collection is undefined.

GetMethodsWithAttribute(Type, string)

Retrieves an unordered collection of methods marked with the T attribute.
public static TypeCache.MethodCollection GetMethodsWithAttribute(Type attrType, string assemblyName)

Parameters

attrType

Attribute type.

assemblyName

Optional assembly name.

Returns

Type

Description

MethodCollectionReturns an unordered FrameDataView.MethodInfo 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 does not support pseudo-attributes. For more information, refer to Microsoft's documentation on attributes and pseudo-attributes. Pseudo-attributes are handled specially rather than as custom attributes, and
TypeCache
does not provide explicit support for caching them.
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 is read-only and thread-safe. The order of FrameDataView.MethodInfo in the collection is undefined.