private static void InjectPermissions(Type pServerPlugin, PropertyFieldInfo pfi) { const string DefaultPermissionsMethodName = "GetDefaultPermissions"; if (!pfi.HasInjectAttribute()) { return; } MethodInfo mi = pServerPlugin.GetMethod(DefaultPermissionsMethodName); if (mi == null) { throw new Exception($"{pServerPlugin} does not implement a public method {DefaultPermissionsMethodName}()"); } if (!mi.IsStatic) { throw new Exception($"{pServerPlugin}.{DefaultPermissionsMethodName}' needs to be static"); } object permissionList = mi.Invoke(pServerPlugin, new object[] { }); DefaultPermission[] permissions = permissionList as DefaultPermission[]; if (permissions == null) { throw new Exception($"{pServerPlugin}.{DefaultPermissionsMethodName}() does not have the corrent return type {nameof(DefaultPermission)}[] "); } var storage = StorageFactory.GetStorageFactory(pServerPlugin, typeof(IPermissionService)).Invoke(pfi, permissions.ToDictionaryNonNullKeys(k => k.Key, k => (object)k.DefaultValue)); pfi.SetValue(null, storage); }
private static void Inject(Type pServerPlugin, Func <PropertyFieldInfo, Dictionary <string, object>, object> pFactory, PropertyFieldInfo pfi) { if (!pfi.HasInjectAttribute()) { return; } Dictionary <string, object> defaultValues = null; if (pfi.HasDefaultValuesAttribute()) { defaultValues = GetDefaultValues(pServerPlugin, pfi.GetDefaultValuesAttribute().MethodName); } if (!pfi.HasStorageLocationAttribute()) { throw new Exception($"No LocationAttribute defined for Storage {pfi.GetName()}"); } pfi.SetValue(null, pFactory.Invoke(pfi, defaultValues)); }