I am working with an interceptor (extended from RealProxy) which interacts with our caching service. I supply the key and am returned a JSON payload. The return type is reflected from the calling function (MethodInfo.ReturnType) and is used to cast the returned object as needed.  public object Get(string key, Type type) {     string value = cache[key];     return JsonConvert.DeserializeObject(value, type); }   Out of curiosity I wanted to make use of generics to accomplish this. I know you cannot specify a generic type from a Type variable. Is there any way to accomplish the following?  public T Get&lt;T&gt;(string key) {     string value = cache[key];     return JsonConvert.DeserializeObject&lt;T&gt;(value); }   The calling code is (simplified):  Type returnType = methodInfo.ReturnType; object cachedValue = cacheService.Get(key, returnType);  if (cachedValue != null) {     // return cached value } else {     // continue running }   The reason I am interested in doing this is I would like to use a different caching provider (redis, in particular StackExchange.Redis.Extensions.Newtonsoft) and our current method of caching/retrieving won't plug in quite so simply with calls like this:  User cachedUser = cacheClient.Get&lt;User&gt;("my cache key");
What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime?  Consider the following sample code - inside the Example() method, what's the most concise way to invoke GenericMethod&lt;T&gt;() using the Type stored in the myType variable?  public class Sample {     public void Example(string typeName)     {         Type myType = FindType(typeName);          // What goes here to call GenericMethod&lt;T&gt;()?         GenericMethod&lt;myType&gt;(); // This doesn't work          // What changes to call StaticMethod&lt;T&gt;()?         Sample.StaticMethod&lt;myType&gt;(); // This also doesn't work     }      public void GenericMethod&lt;T&gt;()     {         // ...     }      public static void StaticMethod&lt;T&gt;()     {         //...     } }
What is the speed of time? I tried to use my Virtual Box and this is the error I received - (I just updated to the new Ubuntu also) and I am VERY new at this Linux OS.     Kernel driver not installed (rc=-1908)      The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or   there is a permission problem with /dev/vboxdrv. Please reinstall the   kernel module by executing      '/etc/init.d/vboxdrv setup'      as root. Users of Ubuntu, Fedora or Mandriva should install the DKMS   package first. This package keeps track of Linux kernel changes and   recompiles the vboxdrv kernel module if necessary. Changing password? I would like to change my password.  I have followed the instructions in  but I cannot find the "my logins" hyperlink. Soving a Complex Integral along a circle Gel circular polarising filter I am contemplating buying a lens that only takes rear gel filters. Is it possible to buy a circular polarising filter in gel format? If so, who can supply them (preferably UK based)? Evolving Pokemon based on CP vs Moves Many people are evolving their pokemons based on the CP. However, there's a growing number of people evolving based on Moves instead of CP. In other words, choosing pokemons that have the highest Moves to keep, even if it isn't necessarily the highest CP. I am new to pokemon and don't quite understand the difference between the two. Thus, which strategy is better? Using global variables in a function I have a scene below where I am wanting to get an HDRI image to come in through the windows and light the scene in the window areas and have a god ray like effect.  I want to do this with a volumetric effect and have the HDRI lighting create throw patterns in the scene.  Is this possible?  To have volumetric lighting where the HDRI creates throw patterns?  Thanks for the help Is it possible to save frequently used expressions in QGIS? Is there any way to save frequently used expressions in the selection or field calculator dialogs? Obviously I can cut and paste them into a file where I might save them, but I mean within the context of QGIS like you can do in ArcMap. Why is the light reflected at the same angle from mirror? From the school physics I know that the material objects bounce from the plane surface at the same angle, losing some kinetic energy. In the same school I was taught that the light (and waves in general) obeys this principle too.  Obviously, in the case of light the plane surface should be a perfect mirror. But I can't understand how should this work from the quantum point of view. Let's assume that our mirror consists of a single silver atom.  Why should the electrons of this atom re-emit consumed photons at some specific angle? Probability of a 2 pair in poker What is wrong with my method of find the probability of a 2 pair?  For the first card we have 52 choices, one this is picked( call it A) we have 3 choices(different suite than A but this same value) for the second card, ( lets call this card B). Now we have AB, to we have to throw away 2 more cards so we don't have 3 of a kind or a four of a kind. Therefore one our third card we have 48 choices and on our fourth card we have 3 choices again similar to above.  On our last card we only have 44 choices left. So the probablity of getting a 2 pair should be (52*3*48*3*44)/(52 choose 5).  But this isn't correct.     Note: I edited this to "2 pair"; the original version was wrong. Binomial Distribution Problem - Airline Overbooking I am looking to identify a story that I read around 2001 (it is probably much older).  Someone showed me the story on pages printed from the internet, and it was attributed to Isaac Asimov (although I cannot state that is the true author).    The story is told in glimpses at different points of time in the future.  In each glimpse, humans are asking a more and more "intelligent" computer how to prevent the universe from collapsing into a singularity in the future, and the computer states it needs more computational power and resources to solve this problem.  At some point, man becomes one with the computer, and the computer exists in hyperspace (or subspace?).    In the final glimpse, it is the end of time and the universe is collapsing into a singularity.  At the instant the universe reaches the singularity, the computer figures out how to prevent it and says "Let there be light" and the universe begins to expand again.  Is anyone familiar with this story? Make a fake random distribution? Sometimes a "real" random event seems unfair and makes players frustrated. For instance a enemy has probability of 20% to cause double damage("critical hit"). Thus he could make 4 critical hits in a row with 1/725 probability. It's not as small as it sounds.  I hope the probability could be adjusted after each hit. If the player just got a critical hit, the probability decreases for the next hit. Otherwise it increases.  Is there a mathematical model for this behaviour? I often find  syntax very helpful, e.g. process substitution like in diff &lt;(sort file1) &lt;(sort file2).  Is it possible to use such Bash commands in a Makefile? I'm thinking of something like this:  file-differences:     diff &lt;(sort file1) &lt;(sort file2) &gt; $@   In my GNU Make 3.80 this will give an error since it uses the shell instead of bash to execute the commands. Do you need to submit an itinerary to get a Russian visa? And do you have to stick to it? Change the size/width of tabs in Notepad++ ubuntu terminal is not working properly in vi editor Sum of Cosine/Exponential I try to simplify to get rid of sum $$ \sum_{k=0}^{n-1}\cos(2 \pi fk)$$  I discover I shall use euler equation to form:  $$ \sum_{k=0}^{n-1}\frac{1}{2}(e^{2 \pi fki}+e^{-2 \pi fki})$$  but how to sum exponentials? Finding cartesian product with PHP associative arrays