static public int InspectCount(this IEnumerable item) { if (item != null) { ICollection collection; if (item.Convert <ICollection>(out collection)) { return(collection.Count); } MethodInfo method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("get_Count"), Filterer_MethodInfo.CanReturnInto <int>(), Filterer_MethodInfo.HasNoEffectiveParameters() ).GetFirst(); if (method != null) { return((int)method.Invoke(item)); } int count = 0; foreach (object sub_item in item) { count++; } return(count); } return(0); }
static public bool InspectSet(this IEnumerable item, int index, object value) { if (item != null) { IList list; if (item.Convert <IList>(out list)) { list[index] = value; return(true); } MethodInfo method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("set_Item"), Filterer_MethodInfo.CanNthEffectiveParameterHold(0, typeof(int)), Filterer_MethodInfo.HasTwoEffectiveParameters() ).GetFirst(); if (method != null) { method.Invoke(item, new object[] { index, value }); return(true); } } return(false); }
static public bool InspectAdd(this IEnumerable item, object value) { if (item != null) { MethodInfoEX method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("Add"), Filterer_MethodInfo.HasOneEffectiveParameter() ).GetFirst(); if (method != null) { if (value == null) { value = method.GetEffectiveParameterType(0).GetDefaultValue(); } method.Invoke(item, new object[] { value }); return(true); } return(item.InspectInsert( item.InspectCount(), value )); } return(false); }
static public object InspectGet(this IEnumerable item, int index) { if (item != null) { IList list; if (item.Convert <IList>(out list)) { return(list[index]); } MethodInfo method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("get_Item"), Filterer_MethodInfo.CanReturnInto <object>(), Filterer_MethodInfo.CanEffectiveParametersHold <int>() ).GetFirst(); if (method != null) { return(method.Invoke(item, new object[] { index })); } int count = 0; foreach (object sub_item in item) { if (count == index) { return(sub_item); } count++; } } return(null); }
static public bool InspectRemoveAt(this IEnumerable item, int index) { if (item != null) { MethodInfoEX method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("RemoveAt"), Filterer_MethodInfo.CanEffectiveParametersHold <int>() ).GetFirst(); if (method != null) { method.Invoke(item, new object[] { index }); return(true); } } return(false); }
static public bool InspectRemove(this IEnumerable item, object value) { if (item != null) { MethodInfoEX method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("Remove"), Filterer_MethodInfo.HasOneEffectiveParameter() ).GetFirst(); if (method != null) { method.Invoke(item, new object[] { value }); return(true); } } return(false); }
static public bool InspectInsert(this IEnumerable item, int index, object value) { if (item != null) { MethodInfoEX method = item.GetType().GetFilteredInstanceMethods( Filterer_MethodInfo.IsNamed("Insert"), Filterer_MethodInfo.CanNthEffectiveParameterHold(0, typeof(int)), Filterer_MethodInfo.HasTwoEffectiveParameters() ).GetFirst(); if (method != null) { if (value == null) { value = method.GetEffectiveParameterType(1).GetDefaultValue(); } method.Invoke(item, new object[] { index, value }); return(true); } } return(false); }