Esempio n. 1
0
        /// <summary>
        /// Gets the value of a primitive field.  This will throw an InvalidCastException if the type parameter
        /// does not match the field's type.
        /// </summary>
        /// <typeparam name="T">The type of the field itself.</typeparam>
        /// <param name="fieldName">The name of the field.</param>
        /// <returns>The value of this field.</returns>
        public T GetField <T>(string fieldName) where T : struct
        {
            ClrInstanceField field = _type.GetFieldByName(fieldName);

            if (field == null)
            {
                throw new ArgumentException(String.Format("Type '{0}' does not contain a field named '{1}'", _type.Name, fieldName));
            }

            object value = field.GetValue(_address, _interior);

            return((T)value);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the value of a primitive field.  This will throw an InvalidCastException if the type parameter
        /// does not match the field's type.
        /// </summary>
        /// <typeparam name="T">The type of the field itself.</typeparam>
        /// <param name="fieldName">The name of the field.</param>
        /// <returns>The value of this field.</returns>
        public T GetField <T>(string fieldName)
            where T : struct
        {
            ClrInstanceField field = Type.GetFieldByName(fieldName);

            if (field == null)
            {
                throw new ArgumentException($"Type '{Type.Name}' does not contain a field named '{fieldName}'");
            }

            object value = field.GetValue(Address);

            return((T)value);
        }