在X++中处理.NET返回的数组
列举出某个目录下所有的文件,C#代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CLRIntegration
{
class Program
{
static void Main(string[] args)
{
Program.DisplayFilesOfSomeDirectory(@"C:\");
}
/// <summary>
/// Display Files of Some Directory
/// </summary>
/// <param name="_path">Diectory</param>
static void DisplayFilesOfSomeDirectory(string _path)
{
System.IO.DirectoryInfo di = new DirectoryInfo(_path);
foreach(FileInfo fileInfo in di.GetFiles())
{
Console.WriteLine(fileInfo.Name);
}
Console.ReadLine();
}
}
}
X++可以与.NET的CLR互操作,但在X++中调用.NET的类System.IO.DirectoryInfo的方法GetFiles时返回值是FileInfo类型的数组,在X++中的数组不支持类类型,虽然有Array类型支持类类型,但貌似这个也不能指向FileInfo数组.using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CLRIntegration
{
class Program
{
static void Main(string[] args)
{
Program.DisplayFilesOfSomeDirectory(@"C:\");
}
/// <summary>
/// Display Files of Some Directory
/// </summary>
/// <param name="_path">Diectory</param>
static void DisplayFilesOfSomeDirectory(string _path)
{
System.IO.DirectoryInfo di = new DirectoryInfo(_path);
foreach(FileInfo fileInfo in di.GetFiles())
{
Console.WriteLine(fileInfo.Name);
}
Console.ReadLine();
}
}
}
可以用System.Collections.ArraryList接收,然后使用System.Collections.IEnumerator枚举其值.
代码如下:
static void DisplayFilesOfSomeDirectory(Args _args)
{
System.IO.FileInfo fInfo;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("C:\\");
System.Collections.ArrayList al;
System.Collections.IEnumerator ie;
Boolean OK;
;
al = di.GetFiles();
ie = al.GetEnumerator();
OK = ie.MoveNext();
while(OK)
{
fInfo = ie.get_Current();
OK = ie.MoveNext();
info(fInfo.get_FullName());
}
}
{
System.IO.FileInfo fInfo;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("C:\\");
System.Collections.ArrayList al;
System.Collections.IEnumerator ie;
Boolean OK;
;
al = di.GetFiles();
ie = al.GetEnumerator();
OK = ie.MoveNext();
while(OK)
{
fInfo = ie.get_Current();
OK = ie.MoveNext();
info(fInfo.get_FullName());
}
}
在X++中调用CLR的Assembly比较炫,可惜X++的代码编辑器的智能提示太弱了,另外有些语法习惯跟C#不太一样,不过吐着吐着应该就习惯了,呵呵.