/// <summary>Fügt einem Updatepaket eine beliebige Updateaction hinzu.</summary> /// <param name="action">Die updateAction die hinzugefügt werden soll.</param> /// <param name="package">Das Updatepaket in welche die updateAction hinzugefügt werden soll.</param> /// <returns>Gibt True zurück wenn die updateAction erfolgreich hinzugefügt wurde, andernfalls False.</returns> public bool addActionToPackage(actionBase action, updatePackage package) { foreach (PropertyInfo property in package.GetType().GetProperties()) { if (!property.Name.ToLower().Contains(action.GetType().Name.ToLower())) { continue; } object instance = property.GetValue(package, null); MethodInfo mInfo = instance.GetType().GetMethod("Add"); mInfo.Invoke(instance, new object[] { action }); return(true); } return(false); }
/// <summary>Ermittelt aus einer ID die dazugehörige updateAction aus einem bestimmten Updatepaket.</summary> public KeyValuePair <actionBase, administrationEditorAttribute> findActionById(string id, updatePackage package) { foreach (PropertyInfo property in package.GetType().GetProperties()) { if (!property.Name.ToLower().Contains("actions")) { continue; } Type propertyType = property.PropertyType; if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>)) { //Anzahl aktionen in der Liste auslesen object instance = property.GetValue(package, null); var count = (int)instance.GetType().GetProperty("Count").GetValue(instance, null); //Alle aktionen auslesen und ID vergleichen if (count > 0) { for (int i = 0; i < count; i++) { var action = (actionBase)instance.GetType().GetProperty("Item").GetValue(instance, new object[] { i }); if (action == null) { continue; } if (action.ID.Equals(id)) { return(new KeyValuePair <actionBase, administrationEditorAttribute>( action, action.GetType().GetCustomAttributes(typeof(administrationEditorAttribute), true)[0] as administrationEditorAttribute)); } } } } } throw new Exception(string.Format("Die Aktion mit der ID '{0}' konnte im Updatepaket nicht gefunden werden.", id)); }