public static object GetResult(this IRestrictedCommand command) { var resultType = command.GetType().GetInterfaces().Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IHaveResult <>)).FirstOrDefault().GetGenericArguments()[0]; var resultPropertyName = typeof(IHaveResult <>).MakeGenericType(resultType).GetProperties().Where(x => x.PropertyType == resultType).FirstOrDefault().Name; var commandResult = command.GetType().GetProperty(resultPropertyName).GetValue(command); return(commandResult); }
public static bool HaveResult(this IRestrictedCommand command) { bool haveResult = command.GetType().GetInterfaces() .Where(i => i.IsGenericType) .Any(i => i.GetGenericTypeDefinition() == typeof(IHaveResult <>)); return(haveResult); }
public string GenerateKeyForCache(IRestrictedCommand command) { var attr = command.GetType().GetCustomAttributes(typeof(CacheOutputAttribute), true) .FirstOrDefault() as CacheOutputAttribute; if (attr == null) { return(null); } var key = command.GetType().FullName; foreach (var info in command.GetType().GetProperties()) { var cparam = info.GetCustomAttributes(typeof(CacheParameterAttribute), true) .FirstOrDefault() as CacheParameterAttribute; if (cparam != null) { key += "," + info.GetValue(command, new object[0]); } } return(key); }