Beispiel #1
0
        /// <summary>
        /// Gets the property value by name
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="m"></param>
        /// <param name="propertyName">Name of the property</param>
        /// <returns></returns>
        public static T GetProperty <T>(MacroDatabaseKeyAnnualReportData m, string propertyName)
        {
            var theProperty = m.GetType().GetProperty(propertyName);

            if (theProperty == null)
            {
                throw new ArgumentException("object does not have an " + propertyName + " property", "m");
            }
            if (theProperty.PropertyType.FullName != typeof(T).FullName)
            {
                throw new ArgumentException("object has an Id property, but it is not of type " + typeof(T).FullName, "m");
            }
            return((T)theProperty.GetValue(m, null));
        }