• C#相关 获取类中 变量名字 函数名字 属性名字 IsAssignableFrom


    参考 https://blog.csdn.net/xiaolei1982/article/details/2294364

    获取类外层的标签:

      [DataContract1("People")]
        public class Person
        {
            public String UserName { get; set; }
    
            public String UserAge { get; set; }
    
    
            static void Main(string[] args)
            {
                //反射自己这类
                Person aa = new Person();
                Type aaacc = typeof(Person);
                var attribute = aaacc.GetCustomAttribute(typeof(DataContract1Attribute));
                Console.WriteLine("");
            }
        }
        [AttributeUsage(AttributeTargets.All)]
        public class DataContract1Attribute : Attribute
        {
            public string Name;
    
            public DataContract1Attribute(string Name)
            {
                this.Name = Name;
            }
        }
            Type a = typeof(A);
    
            PropertyInfo[] piArr = a.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
    
            foreach (PropertyInfo pi in piArr)
            {
                Console.Write(pi.Name);  //显示所有的属性
            }
            Console.WriteLine("");
            MethodInfo[] info = a.GetMethods();
            foreach (MethodInfo pi in info)
            {
                Console.Write(pi.Name+"   ");  
            }
            Console.WriteLine("");
            FieldInfo[] inMemberInfofo = a.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            A aaaa = new A();
            foreach (FieldInfo pi in inMemberInfofo)
            {
                Console.Write(pi.Name+"  ");
              
    
                Console.Write("  值:" + pi.GetValue(aaaa));
    
                Console.Write("  类型:" + pi.FieldType.Equals(typeof(int)));
            }
    
    
            Console.WriteLine("");
            string aaa = "Ab";
            Console.WriteLine(aaa.IndexOf("A", StringComparison.OrdinalIgnoreCase));

    https://www.cnblogs.com/tomorrow0/p/14381500.html

    IsAssignableFrom

    bool res = {TypeA}.IsAssignableFrom({TypeB}) ;

    如果TypeA和TypeB类型一样则返回true;

    如果TypeA是TypeB的父类则返回true;

    如果TypeB实现了接口TypeA则返回true;

           Console.WriteLine("--");
            Type a = typeof(A);
            Console.WriteLine(a.AssemblyQualifiedName);
            Console.WriteLine("--");
    
    
            Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
         
            for (int i = 0; i != assemblies.Length; ++i)
            {
                Type type = typeof(Program).Assembly.GetType("Program+A");//查看 AssemblyQualifiedName的输出,每个C#版本可能不一致
                if (type != null)
                {
                    Console.WriteLine("不区分大小写");
                    break;
                }
            }
     Type type = typeof(Flux.FObject).Assembly.GetType("Flux." + className);
    private void ShowAddTrackMenu()
            {
                Event.current.Use();
    
                GenericMenu menu = new GenericMenu();
    
                System.Reflection.Assembly fluxAssembly = typeof(FEvent).Assembly;
    
                Type[] types = typeof(FEvent).Assembly.GetTypes();  //程序集合的所有类型信息
    
    if( fluxAssembly.GetName().Name != "Assembly-CSharp" )
                {
                    // if we are in the flux trial, basically allow to get the types in the project assembly
                    ArrayUtility.AddRange<Type>( ref types, System.Reflection.Assembly.Load("Assembly-CSharp").GetTypes() );
                }
    
                List<KeyValuePair<Type, FEventAttribute>> validTypeList = new List<KeyValuePair<Type, FEventAttribute>>();
                
                foreach( Type t in types )
                {
                    if( !typeof(FEvent).IsAssignableFrom( t ) ) //查看是否FEvent相关的类型 
                        continue;
                    
                    object[] attributes = t.GetCustomAttributes(typeof(FEventAttribute), false);
                    if( attributes.Length == 0 || ((FEventAttribute)attributes[0]).menu == null )
                        continue;
                    
                    validTypeList.Add( new KeyValuePair<Type, FEventAttribute>(t, (FEventAttribute)attributes[0]) );
                }
                
                validTypeList.Sort( delegate(KeyValuePair<Type, FEventAttribute> x, KeyValuePair<Type, FEventAttribute> y) 
                                   {
                    return x.Value.menu.CompareTo( y.Value.menu );
                });
                
                foreach( KeyValuePair<Type, FEventAttribute> kvp in validTypeList )
                {
                    menu.AddItem( new GUIContent(kvp.Value.menu), false, AddTrackMenu, kvp );
                }
                
                menu.ShowAsContext();
            }
    改变自己
  • 相关阅读:
    Visual Studio使用Git忽略不想上传到远程仓库的文件
    使用git处理github中提交有冲突的pull request
    C#基础访问修饰符概述
    从代码角度理解NNLM(A Neural Probabilistic Language Model)
    命名实体识别数据预处理
    基于bert命名实体识别(一)数据处理
    transformer多头注意力的不同框架实现(tensorflow+pytorch)
    基于tensorflow的bilstm_crf的命名实体识别(数据集是msra命名实体识别数据集)
    python实现命名实体识别指标(实体级别)
    基于tensorflow的文本分类总结(数据集是复旦中文语料)
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/14478623.html
Copyright © 2020-2023  润新知