Today. Do a ranking display function. Need to deal with the situation in parallel. First, it's the rank function of SQL SERVER2005.
I later wondered if it would be possible to implement an extension method for list<t> to achieve a parallel ranking.
Think about it can be achieved. Have this idea to come true.
My idea is that when List<t> calls the Rank method, the T type has an extra attribute to get the rank.
But how to dynamically add properties to the T type ... I think of the dynamic creation of a type.
. NET can dynamically create a type ... .
There are 2 general ways (I only know 2 total ...). I also thought of a dynamic construct lambda using new{} I don't know if I can. I think it should be OK. Never tried (just think))
Mode 1: Use the class under the System.Reflection.Emit namespace. (both directly or indirectly manipulate the IL code)
Mode 2: Use Microsoft.csharp; System.CodeDom.Compiler; This 2-namespace class can be implemented relatively simple.
Let's start by looking at how to create a type dynamically.
Dynamic Create type first name is dynamic.
This method is very simple. is to get 26 uppercase and lowercase letters using ASCII code.
/// <summary>
/// 动态创建一个英文名称
/// </summary>
/// <param name="number">长度</param>
/// <returns></returns>
public static string CreateEnglish(int number)
{
Random random = new Random(DateTime.Now.Millisecond);
List<string> en = new List<string>();
Enumerable.Range(97, 26).ToList<int>().ForEach(t => en.Add(((char)t).ToString()));
Enumerable.Range(65, 26).ToList<int>().ForEach(t => en.Add(((char)t).ToString()));
string reuslt = string.Empty;
for (int i = 0; i < number; i++)
{
reuslt += en[random.Next(en.Count)];
}
return reuslt;
}