/// <summary> /// Gets the API info. /// </summary> /// <param name="entity"> The entity. </param> /// <returns> </returns> public static EntityApiInfoAttribute GetApiInfo(IFogBugzEntity entity) { var attributes = entity.GetType().GetCustomAttributes(typeof (EntityApiInfoAttribute), false); if (attributes.Length <= 0) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Entity {0} does not implement API attribute", entity.GetType().FullName)); return (EntityApiInfoAttribute) attributes[0]; }
/// <summary> /// Reflects the properties in the referenced entity that contain a <see cref="PropertyMapAttribute" /> . Loads a dictionary containing the name and value of the mapped entites. /// </summary> /// <param name="entity"> The entity. </param> /// <returns> the name/value pairs of the reflected properties. </returns> public static IDictionary<string, string> TryGatherProperties(IFogBugzEntity entity) { var dictionary = new Dictionary<string, string>(); var props = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (var prop in props) { var maps = prop.GetCustomAttributes(typeof (PropertyMapAttribute), false); if (maps.Length <= 0) continue; var map = (PropertyMapAttribute) maps[0]; if (map.NotSerialized) continue; if (dictionary.ContainsKey(map.Index)) dictionary.Remove(map.Index); var value = prop.GetValue(entity, null); if (value != null) dictionary.Add(map.Index, GetValueFromStrategy(value, map.Strategy)); } return dictionary; }