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 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 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 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); }
static public void InvokeFilteredMarkedStaticMethods <P1, P2, P3, P4, P5, P6, P7, P8, P9>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) { GetFilteredMarkedStaticMethods( Filterer_MethodInfo.CanEffectiveParametersHold <P1, P2, P3, P4, P5, P6, P7, P8, P9>() ).Process(m => m.Invoke(null, new object[] { p1, p2, p3, p4, p5, p6, p7, p8, p9 })); }
static public void InvokeFilteredMarkedStaticMethods <P1, P2, P3, P4, P5>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { GetFilteredMarkedStaticMethods( Filterer_MethodInfo.CanEffectiveParametersHold <P1, P2, P3, P4, P5>() ).Process(m => m.Invoke(null, new object[] { p1, p2, p3, p4, p5 })); }
static public void InvokeFilteredMarkedStaticMethods <P1, P2>(P1 p1, P2 p2) { GetFilteredMarkedStaticMethods( Filterer_MethodInfo.CanEffectiveParametersHold <P1, P2>() ).Process(m => m.Invoke(null, new object[] { p1, p2 })); }
static public void InvokeFilteredMarkedStaticMethods() { GetFilteredMarkedStaticMethods( Filterer_MethodInfo.CanEffectiveParametersHold() ).Process(m => m.Invoke(null, new object[] { })); }