Skip to content

Instantly share code, notes, and snippets.

@renestein
Created April 11, 2013 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/5362877 to your computer and use it in GitHub Desktop.
Save renestein/5362877 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace Mormegill_test
{
internal class Program
{
private static void Main(string[] args)
{
var program = new Program();
Object[] devilArray1 =
{
new object[0]
};
Console.WriteLine(program.Test(devilArray1));
Array[] arrays = new [] {new int[10]};
Array[] arrays2 = new [] {arrays};
Console.WriteLine(program.Test(arrays2));
Console.ReadLine();
}
private bool Test<T>(T[] arr)
{
Console.WriteLine(typeof(T));
return arr.Any(x =>
{
return (x is T[]);
});
}
}
}
@mormegil-cz
Copy link

Výtečně, tohle už bych uznal. :-) Ale dodávám, že ani tohle ještě není úplné řešení: Za ten object nebo Array lze ještě přidat libovolný počet []:

    Console.WriteLine(program.Test<object>(new object[]{new object[0]}));
    Console.WriteLine(program.Test<Array>(new Array[]{new Array[0]}));
    Console.WriteLine(program.Test<object[]>(new object[][]{new object[0][]}));
    Console.WriteLine(program.Test<Array[]>(new Array[][]{new Array[0][]}));
    Console.WriteLine(program.Test<object[][]>(new object[][][]{new object[0][][]}));
    Console.WriteLine(program.Test<Array[][]>(new Array[][][]{new Array[0][][]}));
    // ...ad infinitum

O dalších řešeních nevím, ale mohu se samozřejmě mýlit. :-)

@renestein
Copy link
Author

Jasně, to už jsme nerozepisoval, mohli bychom na to napsat i nějaký generátor přes reflection.
Mě ještě napadal dynamic, ale tam je problém s operátorem is.
A pak si myslím, že by ještě šlo kouzlit s COM wrapperem. Ale stejně - pěkný test:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment