/// <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];
 }
        public void PostInitializeEntity(IFogBugzEntity entity, IDictionary<string, string> rawValues)
        {
            if (HttpContext.Current != null && entity is Case && FbAccountContext.Current.Settings.AllowQaEstimates)
            {
                var fieldName = FbAccountContext.Current.Settings.QaEstimateCustomFieldName;
                //"plugin_kilnplugin_at_fogcreek_com_fkilnreview";

                var filteredValues = rawValues.Where(k => k.Key.ToLower().Contains(fieldName.ToLower()))
                                              .Select(v => v.Value)
                                              .ToList();

                if (fieldName != null && filteredValues.Any())
                {
                    var converter = new PropertyMapAttribute(string.Empty, ConversionStrategy.Integer);

                    var val = converter.Convert(filteredValues.First());
                    (entity as Case).TestEstimate = (int?)val;
                }
            }
        }
        /// <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;
        }