I'm using .Net framework 2.0 to try and do the following:  I've an external service which returns a list of int.  In turn I use each int to find a corresponding Type which has an Attribute with a property, key; the value of that property matches the search parameter.  Using the Type t I'd like to call a generic method, but I'm unable to do this.  As I will only know the Type at runtime, I suspect I may have to use reflection to invoke the generic method GetResultsForType - is this the correct way to go about this?  [MyAttribute(key1 = 1)] class A{     //some properties }  [MyAttribute(key1 = 2)] class B{     //some properties }  //and so on (for hundreds of classes).  The key is unique for every class.  public class Foo{     public void DoSomething(){          IList&lt;int&gt; keys = QuerySomeExternalService();           Assembly asm = LoadAssemblyFromSomewhere();          Type[] types = asm.GetTypes();          foreach(int key in keys){              Type t = SearchTypesForAttributeWithMatchingKey(types, key);  //I omitted caching of all the keys and Types into a Dictionary on first iteration for brevity.              IList&lt;t&gt; results = GetResultsForType&lt;t&gt;(); //won't work!              //do something with the results          }     }      Type SearchTypesForAttributeWithMatchingKey(Type[] types, int key){         foreach(Type t in types){             object[] attributes = t.GetCustomAttributes(typeof(MyAttribute),false);             MyAttribute myAtt = attributes[0] as MyAttribute;             if(myAtt.Key == key) return t;         }     }      IList&lt;T&gt; GetResultsForType&lt;T&gt;(){         IList&lt;T&gt; results = new List&lt;T&gt;();         bool querySuccess = true;         while(querySuccess){             T result;             querySuccess = QueryExternalService&lt;T&gt;(out result);             results.Add(result);         }         return results;     } }
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;()     {         //...     } }
The site description in the hero header is wrong for Meta sites The hero header contains the same description for the Main and Meta sites. Here's the one for MSO:           Meta Stack Overflow is a question and answer site for professional and enthusiast programmers. Join them; it only takes a minute:    This can easily confuse people who are new to the network, so I feel this should be changed to something Meta specific. Perhaps re-use the text from the sidebar, that has a good description:     This site is intended for bugs, features, and discussion of Stack Overflow and the software that powers it. You must have an account on Stack Overflow to participate. bash: start multiple chained commands in background I'm trying to run some commands in paralel, in background, using bash. Here's what I'm trying to do:  forloop {   //this part is actually written in perl   //call command sequence   print `touch .file1.lock; cp bigfile1 /destination; rm .file1.lock;`; }   The part between backticks (``) spawns a new shell and executes the commands in succession. The thing is, control to the original program returns only after the last command has been executed. I would like to execute the whole statement in background (I'm not expecting any output/return values) and I would like the loop to continue running.  The calling program (the one that has the loop) would not end until all the spawned shells finish.  I could use threads in perl to spawn different threads which call different shells, but it seems an overkill...  Can I start a shell, give it a set of commands and tell it to go to the background? In Star Trek TOS, we see the Defiant disappear to unknown parts  ('The Tholian Web'), and Star Trek: Enterprise revealed that the Defiant went back in time to the mirror universe ('In a Mirror Darkly', parts 1 &amp; 2).   Because of this, one might wonder why (in-universe) the mirror universe didn't obtain (and maintain) technological superiority over the main timeline. (Granted, the out of universe answer is that TOS depicted the two universes as having essentially the same level of tech)  So does any work (whether STO, or a pocket books work) address why the mirror universe didn't simply leap frog the main universe's technology?   (Or to put it another way, why did the mirror universe's technology appear to stagnate for a century after obtaining access to the Defiant's advanced technology?) Using wp_query is it possible to orderby taxonomy? My question is simple, I'm using WP_Query to retrieve some custom type posts filtering by a taxonomy using tax_query.  Now my problem is I would like to orderby the taxonomy, but from documentation and searching on the web I can't find a solution.  The orderby in WP_Query lets you order by a bunch of fields even custom meta fields but it doesn't seem to support taxonomy.  Any pointers in the right direction?  Thank you all. I know Wonder Woman has died in canon before, but in which issue did this happen? I'm interested if any of the following explanations have enough predictive capability to explain the observations we see today. The claim is that the Universe is not expanding, and that red-shift of light is caused by:    Though a couple of these are simply ridiculous, I'm still interested. Keep in mind that I am not a creationist, but am looking for reasons to see if any of these are valid or invalid. How to calculate $\lim \limits_{n \to \infty}(1 +\frac{a}{n})^n$? Logic Behind StackOverflow Question IDs Open existing file, append a single line I'd like to know whether, given a system, there's a way to obtain all the conserved quantities. For instance if the system consists of electric and magnetic fields, the fields must satisfy Maxwell's equations. These equations are invariant under many transformations (Lorentz transformation, rotations, spatial and temporal translations, etc. By the way is there a way, maybe from group theory, to find all the possible transformations that leaves the equation(s) invariant?) which imply as many conserved quantities thanks to Noether's theorem. In wikipedia I can see an equation that seems to give all the conserved quantities () but it involves the Lagrangian and I'm not sure whether the formula is valid for all systems whose Lagrangian is possible to obtain. What is the limit of series $\frac{1}{2 \cdot 3 \cdot 4} + \frac{1}{4 \cdot 5 \cdot 6} + \frac{1}{6 \cdot 7 \cdot 8} + \cdots $?  The $n$th summand is $\frac{1}{(2n)(2n + 1)(2n+2)} = \frac{1}{4} \frac{1}{n(2n+1)(n+1)}$.  I have tried expressing this as a telescoping sum, or as the limit of Riemann sums of a partition (the usual methods I normally try when doing this type of question- what are some other strategies?) Does 'rm .*' ever delete the parent directory? The expression .* is expanded by bash to include the current and parent directories:  $ ls -la total 2600 drwxrwxrwx   2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon  491520 Sep 10 15:34 .. -rw-r--r--   1 terdon terdon       0 Sep 10 16:22 foo $ echo .* . ..   If I run rm -rf .* on my Debian using GNU bash, version 4.2.36(1)-release and rm from rm (GNU coreutils) 8.13, I get this message:  $ rm -rf .* rm: cannot remove directory: `.' rm: cannot remove directory: `..'   Is this a GNU thing or is it POSIX? Are there any *nix systems where the command above will silently delete . and ..?  Also, is this a safety feature of the shell or of the rm command itself? Rendered image doesn't show what Rendered Viewport shows... (pictures below) Fortran IF statement with numbers/labels rather than another statement Sass Interpolation of Mixin, Function, and Variable names Max dimension of a subspace of singular $n\times n$ matrices I am sure the answer to this is (kind of) well known. I've searched the web and the site for a proof and found nothing, and if this is a duplicate, I'm sorry.  The following question was given in a contest I took part. I had an approach but it didn't solve the problem.     Consider $V$ a linear subspace of the real vector space $\mathcal{M}_n(\Bbb{R})$ ($n\times n$ real entries matrices) such that $V$ contains only singular matrices (i.e matrices with determinant equal to $0$). What is the maximal dimension of $V$?   A quick guess would be $n^2-n$ since if we consider $W$ the set of $n\times n$ real matrices with last line equal to $0$ then this space has dimension $n^2-n$ and it is a linear space of singular matrices.  Now the only thing there is to prove is that if $V$ is a subspace of $\mathcal{M}_n(\Bbb{R})$ of dimension $k &gt; n^2-n$ then $V$ contains a non-singular matrix. The official proof was unsatisfactory for me, because it was a combinatorial one, and seemed to have few things in common with linear algebra. I was hoping for a pure linear algebra proof.  My approach was to search for a permutation matrix in $V$, but I used some 'false theorem' in between, which I am ashamed to post here. How to prove that derivatives have the Intermediate Value Property I have the following title page in LaTeX: \documentclass{article}  \title{Appendix A: User Manual}  \author{ John Smith\\University XYZ\\Albert Square\\Walford\\NC1 8AE }  \begin{document} \maketitle \end{document}  What is the proper way to add a new page, say, for the contents page and start editing that new page? Problem from Herstein on group theory Green is the most common circuit-board color because it has become an industry standard.  What I'm interested in is How the traditional "PCB Green" become a standard in the first place?   Were there any interesting historical reasons for the initial choice, or was it just a product of what one particularly successful company was doing that became the de-facto standard?