public static bool HandlesMatch(object item, string handle)
        {
            if (item == null)
            {
                return(false);
            }
            if (handle.NullOrEmpty())
            {
                return(false);
            }
            handle = TranslationHandleUtility.NormalizedHandle(handle);
            if (handle.NullOrEmpty())
            {
                return(false);
            }
            Type type = item as Type;

            if (type != null)
            {
                return(TranslationHandleUtility.NormalizedHandle(type.Name) == handle || TranslationHandleUtility.NormalizedHandle(type.FullName) == handle || TranslationHandleUtility.NormalizedHandle(type.ToString()) == handle);
            }
            string text;

            try
            {
                text = item.ToString();
            }
            catch (Exception arg)
            {
                throw new InvalidOperationException("Could not get element by handle because one of the elements threw an exception in its ToString(): " + arg);
            }
            return(!text.NullOrEmpty() && TranslationHandleUtility.NormalizedHandle(text) == handle);
        }
        public static string GetBestHandleWithIndexForListElement(object list, object element)
        {
            if (list == null || element == null)
            {
                return(null);
            }
            PropertyInfo property = list.GetType().GetProperty("Count");

            if (property == null)
            {
                return(null);
            }
            PropertyInfo property2 = list.GetType().GetProperty("Item");

            if (property2 == null)
            {
                return(null);
            }
            FieldInfo fieldInfo = null;
            string    handle    = null;
            int       num       = 0;

            FieldInfo[] fields = element.GetType().GetFields(BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            FieldInfo[] array  = fields;
            for (int i = 0; i < array.Length; i++)
            {
                FieldInfo fieldInfo2 = array[i];
                TranslationHandleAttribute translationHandleAttribute = fieldInfo2.TryGetAttribute <TranslationHandleAttribute>();
                if (translationHandleAttribute != null)
                {
                    object value = fieldInfo2.GetValue(element);
                    if (value != null)
                    {
                        Type   type = value as Type;
                        string text;
                        if (type != null)
                        {
                            text = type.Name;
                        }
                        else
                        {
                            try
                            {
                                text = value.ToString();
                            }
                            catch
                            {
                                return(null);
                            }
                        }
                        if (!text.NullOrEmpty())
                        {
                            int priority = translationHandleAttribute.Priority;
                            if (fieldInfo == null || priority > num)
                            {
                                fieldInfo = fieldInfo2;
                                handle    = text;
                                num       = priority;
                            }
                        }
                    }
                }
            }
            if (fieldInfo == null)
            {
                return(null);
            }
            int num2 = 0;
            int num3 = -1;
            int num4 = (int)property.GetValue(list, null);

            for (int j = 0; j < num4; j++)
            {
                object value2 = property2.GetValue(list, new object[]
                {
                    j
                });
                if (value2 != null)
                {
                    if (value2 == element)
                    {
                        num3 = num2;
                        num2++;
                    }
                    else
                    {
                        FieldInfo[] fields2 = value2.GetType().GetFields(BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                        FieldInfo[] array2  = fields2;
                        for (int k = 0; k < array2.Length; k++)
                        {
                            FieldInfo fieldInfo3 = array2[k];
                            if (TranslationHandleUtility.FieldInfosEqual(fieldInfo3, fieldInfo))
                            {
                                object value3 = fieldInfo3.GetValue(value2);
                                if (value3 != null)
                                {
                                    if (TranslationHandleUtility.HandlesMatch(value3, handle))
                                    {
                                        num2++;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (num3 < 0)
            {
                return(null);
            }
            string text2 = TranslationHandleUtility.NormalizedHandle(handle);

            if (num2 <= 1)
            {
                return(text2);
            }
            return(text2 + '-' + num3);
        }