注解

注解
注解可以更好的分类class,再不用实例化类的情况下筛选需要的class

  1. 声明
[AttributeUsage( AttributeTargets.Class )]
public class NodeAttributes : Attribute
  public NodeAttributes( string name, string category, string description, 
  System.Type castType = null, KeyCode shortcutKey = KeyCode.None, 
  bool available = true, bool deprecated = false, string deprecatedAlternative = null, 
  System.Type deprecatedAlternativeType = null, string community = null, 
  string customCategoryColor = null, int sortOrderPriority = -1, int nodeAvailabilityFlags = int.MaxValue )
  1. 使用
[NodeAttributes( "Vector From Matrix", "Matrix Operators", "Retrieve vector data from a matrix" )]
  1. 筛选
Type[] availableTypes = GetTypesInNamespace( Assembly.GetExecutingAssembly(), "AmplifyShaderEditor" );
                foreach( System.Type type in availableTypes )
                {
                    foreach( NodeAttributes attribute in Attribute.GetCustomAttributes( type ).OfType<NodeAttributes>() )
                    {
                        if( attribute.Available && !attribute.Deprecated )
private Type[] GetTypesInNamespace( Assembly assembly, string nameSpace )
        {
            return assembly.GetTypes().Where( 
t => String.Equals( t.Namespace, nameSpace, StringComparison.Ordinal ) ).ToArray();
        }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容