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