コード例 #1
0
        /// <summary>
        /// Create a new field or property reference of specified name.
        /// </summary>

        static public FieldOrProperty Create(Type type, string name)
        {
            const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var field = type.GetField(name, flags);

            if (field != null)
            {
                var fp = new FieldOrProperty();
                fp.field = field;
                return(fp);
            }

            var property = type.GetProperty(name, flags);

            if (property != null)
            {
                var fp = new FieldOrProperty();
                fp.property = property;
                return(fp);
            }

#if UNITY_EDITOR
            Debug.LogError("Unable to find " + type + "." + name);
#endif
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Create a new field or property reference of specified name.
        /// </summary>

        static public FieldOrProperty Create(Type type, string name)
        {
            const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var field = type.GetField(name, flags);

            if (field != null)
            {
                var fp = new FieldOrProperty();
                fp.field = field;
                return(fp);
            }

            var property = type.GetProperty(name, flags);

            if (property != null)
            {
                var fp = new FieldOrProperty();
                fp.property = property;
                return(fp);
            }

#if UNITY_EDITOR
#if TNET_EXCEPTIONS
            throw new Exception("Unable to find " + type + "." + name);
#else
            Debug.LogWarning("Unable to find " + type + "." + name);
            return(null);
#endif
#else
            return(null);
#endif
        }
コード例 #3
0
        /// <summary>
        /// Create a new field or property reference of specified name.
        /// </summary>

        static public FieldOrProperty Create(Type type, PropertyInfo property)
        {
            if (property != null)
            {
                var fp = new FieldOrProperty();
                fp.property = property;
                return(fp);
            }
            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Create a new field or property reference of specified name.
        /// </summary>

        static public FieldOrProperty Create(Type type, FieldInfo field)
        {
            if (field != null)
            {
                var fp = new FieldOrProperty();
                fp.field = field;
                return(fp);
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Get the specified field or property. The result is cached in a lookup table.
        /// </summary>

        static public FieldOrProperty GetFieldOrProperty(this Type type, string name)
        {
            Dictionary <string, FieldOrProperty> dict;

            if (!mFoPs.TryGetValue(type, out dict))
            {
                dict        = new Dictionary <string, FieldOrProperty>();
                mFoPs[type] = dict;
            }

            FieldOrProperty fp = null;

            if (!dict.TryGetValue(name, out fp))
            {
                fp         = FieldOrProperty.Create(type, name);
                dict[name] = fp;
            }
            return(fp);
        }