C# 反射 Type.GetFields 方法


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;

public class Test01 : MonoBehaviour {

    void Start ()
    {
        FieldInfo[] array =  GetComponent<Test01>().GetType().GetFields();
        foreach (var item in array)
        {
            print("字段名称:" + item);
        }
    }

    [DataStoreSave]
    public string str = "abc";
    [DataStoreSave]
    public int i = 5;
    [DataStoreSave]
    public bool b = true;
    [DataStoreSave]
    public Vector3 V3 = new Vector3(4, 5, 6);
}

结果如下图:

 

Type.GetFields

返回当前 Type 的所有公共字段。

注意要引用命名空间:using System.Reflection;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM