Esempio n. 1
0
 /// <summary>
 /// Creates a new instance of <see cref="ObjectPropertyDict{TKey, TVal}"/>
 /// </summary>
 /// <param name="name">the property name</param>
 /// <param name="token">the token information</param>
 /// <param name="property">The PropertyInfo object for this instance</param>
 /// <param name="owner">the ConFileObject that owns this property instance</param>
 public ObjectPropertyDict(string name, Token token, PropertyInfo property, ConFileObject owner)
 {
     Name     = name;
     Token    = token;
     Property = property;
     Owner    = owner;
     Items    = new Dictionary <TKey, ObjectProperty <TKey, TVal> >();
 }
Esempio n. 2
0
        /// <summary>
        /// Using reflection, this method creates a new instance of the <typeparamref name="T"/>
        /// type, and returns it.
        /// </summary>
        /// <typeparam name="T">A type of <see cref="ObjectProperty"/></typeparam>
        /// <param name="property">The <see cref="ConFileObject"/> property info</param>
        /// <param name="owner">The <see cref="ConFileObject"/> that owns this property</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static T Create <T>(PropertyInfo property, ConFileObject owner, Token token) where T : ObjectProperty
        {
            // If the Custom attribute exists, we add it to the Mapping
            Attribute attribute = Attribute.GetCustomAttribute(property, typeof(PropertyName));

            if (attribute == null)
            {
                throw new Exception($"Internal property \"{property.Name}\" does not contain a PropertyName attribute!");
            }

            // Get our constructor
            PropertyName fieldAttr = attribute as PropertyName;

            return((T)Activator.CreateInstance(
                       typeof(T),
                       new object[] { fieldAttr.Names[0], token, property, owner }
                       ));
        }