本文整理汇总了C#中list.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# list.ToArray方法的具体用法?C# list.ToArray怎么用?C# list.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类list
的用法示例。
在下文中一共展示了list.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: code
/// <summary>
/// 生成代码
/// </summary>
/// <param name="fileName">模板文件名</param>
/// <returns>代码</returns>
private static list<string> code(string fileName)
{
string code = File.ReadAllText(fileName);
int index = code.IndexOf(@"*/
", StringComparison.Ordinal);
if (index != -1)
{
int startIndex = index += 4;
Dictionary<string, replace> keys = new Dictionary<string, replace>();
replace replace;
foreach (string keyValue in code.Substring(0, index).Split(new string[] { "/*" }, StringSplitOptions.None).sub(1))
{
if ((index = keyValue.IndexOf(':')) != -1 && keyValue.EndsWith(@"*/
", StringComparison.Ordinal))
{
keys[keyValue.Substring(0, index)] = replace = new replace
{
values = new subString(keyValue, ++index, keyValue.Length - index - 4).Split(';').getArray(value => value.Split(','))
};
replace.indexs = new list<int>[replace.values[0].Count];
for (index = 0; index != replace.indexs.Length; replace.indexs[index++] = new list<int>()) ;
}
else error.Add("自定义数据错误 : " + keyValue);
}
list<string> codeList = new list<string>();
for (code = code.Substring(startIndex), startIndex = 0, index = code.IndexOf("/*", StringComparison.Ordinal); index != -1; index = code.IndexOf("/*", startIndex))
{
codeList.Add(code.Substring(startIndex, index - startIndex));
if ((startIndex = code.IndexOf("*/", index, StringComparison.Ordinal) + 2) != 1 && startIndex != index + 4)
{
string name = code.Substring(index, startIndex - index);
if ((index = code.IndexOf(name, startIndex, StringComparison.Ordinal)) != -1)
{
startIndex = index + name.Length;
name = name.Substring(2, name.Length - 4);
if (name[name.Length - 1] == ']')
{
int arrayIndex = name.LastIndexOf('[') + 1;
if (arrayIndex == 0 || !int.TryParse(name.Substring(arrayIndex, name.Length - arrayIndex - 1), out index))
{
error.Add("自定义名称索引错误 : " + name);
index = 0;
}
else name = name.Substring(0, arrayIndex - 1);
}
else index = 0;
if (keys.TryGetValue(name, out replace))
{
replace.indexs[index].Add(codeList.Count);
codeList.Add(string.Empty);
}
else error.Add("自定义名称不匹配 : " + name);
}
else error.Add("自定义名称不匹配 : " + name);
}
else
{
error.Add("自定义名称错误 : " + code.Substring(index));
startIndex = code.Length;
}
}
codeList.Add(code.Substring(startIndex));
string[] codes = codeList.ToArray();
list<string> values = new list<string>();
replace[] replaces = keys.Values.getArray();
do
{
index = replaces.Length;
while (--index >= 0 && ++replaces[index].index == replaces[index].values.Length) ;
if (index == -1) break;
while (++index != replaces.Length) replaces[index].index = 0;
for (index = replaces.Length; --index >= 0; )
{
replace = replaces[index];
list<subString> replaceCode = replace.values[replace.index];
for (startIndex = replace.indexs.Length; --startIndex >= 0; )
{
foreach (int codeIndex in replace.indexs[startIndex]) codes[codeIndex] = replaceCode[startIndex];
}
}
values.Add(string.Concat(codes));
}
while (true);
return values;
}
else error.Add("自定义文件错误 : " + fileName);
return null;
}