private PolicyResult TryAuthorizeUserOnlyPolicy(IPolicy <TUser> policy) { Type objectType = policy.GetType(); Type currentType = objectType; Type baseType; Dictionary <Type, Type> handlers = options.Handlers; Type handlerType = null; while (true) { if (handlers.TryGetValue(currentType, out handlerType)) { break; } baseType = currentType.BaseType; if (IPolicyBaseType.IsAssignableFrom(baseType)) { currentType = baseType; } else { break; } } if (handlerType == null) { foreach (Type interfaceType in objectType.GetInterfaces()) { if (IPolicyBaseType.IsAssignableFrom(interfaceType) && handlers.TryGetValue(interfaceType, out handlerType)) { break; } } } if (handlerType == null) { return(PolicyResult.NotHandled); } object handler = ActivatorUtilities.CreateInstance(services, handlerType); TUser user = options.UserAccessor(services); MethodInfo authorizeMethod = handlerType.GetMethod("OnAuthorization"); return((PolicyResult)authorizeMethod.Invoke(handler, new object[] { user, policy })); }