• 大小: 0.03M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-01
  • 语言: C#
  • 标签: 进程  信息  获取  任务  

资源简介


资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

namespace Lemony.SystemInfo
{

/// 
/// CustomMarshaler class implementation.
/// 

public abstract class CustomMarshaler
{
#region Fields
// The internal buffer
internal byte[] data;
private MemoryStream stream;
private BinaryReader binReader;
private BinaryWriter binWriter;

#endregion

#region constructors

public CustomMarshaler()
{

}

#endregion

#region public methods

public void Deserialize()
{
if (data != null)
{
if (binReader != null)
{
binReader.Close();
stream.Close();
}
// Create a steam from byte array
stream = new MemoryStream(data);
binReader = new BinaryReader(stream System.Text.Encoding.Unicode);
ReadFromStream(binReader);
binReader.Close();
}

}

public void Serialize()
{
if (data != null)
{
stream = new MemoryStream(data);
binWriter = new BinaryWriter(stream System.Text.Encoding.Unicode);
WriteToStream(binWriter);
binWriter.Close();
}
}

public int GetSize()
{
int size = 0;

FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);

foreach (FieldInfo field in fields )
{
if (field.FieldType.IsArray)
{
size += GetFieldSize(field);
}
else if (field.FieldType == typeof(string))
{
size += GetFieldSize(field)*2;

else if (field.FieldType.IsPrimitive)
{
size += Marshal.SizeOf(field.FieldType);
}
}

return size;
}

#endregion

#region properties

public byte[] ByteArray
{
get
{
return data;
}
}

#endregion

#region virtual and protected methods

public virtual void ReadFromStream(BinaryReader reader)
{
object[] param = null;

// Get all public fields
FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);

// Loop through the fields
foreach(FieldInfo field in fields)
{
// Retrieve the read method from ReadMethods hashtable
MethodInfo method = (MethodInfo)MarshallingMethods.ReadMethods[field.FieldType];

if (field.FieldType.IsArray)
{
Type element = field.FieldType.GetElementType();
if (element.IsValueType && element.IsPrimitive)
{
if ((element == typeof(char)) || element == typeof(byte))
{  
param = new object[1];
param[0] = GetFieldSize(field);
field.SetValue(this method.Invoke(reader param)); 
}
else // any other value type array
{
param = new object[2];
param[0] = reader;
param[1] = GetFieldSize(field);
field.SetValue(this method.Invoke(null param)); 
}
}
else // array

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1321  2007-03-29 09:04  SystemInfo\SystemInfo\Properties\AssemblyInfo.cs

     文件       2299  2007-03-29 09:09  SystemInfo\SystemInfo\SystemInfo.csproj

     文件      14926  2007-03-29 09:06  SystemInfo\SystemInfo\CustomtMarshaler.cs

     文件        908  2007-03-29 09:06  SystemInfo\SystemInfo\DiskInfo.cs

     文件        885  2007-03-29 09:06  SystemInfo\SystemInfo\IpInfo.cs

     文件       2000  2007-03-29 09:07  SystemInfo\SystemInfo\MIB_IFROW.cs

     文件        557  2007-03-29 09:07  SystemInfo\SystemInfo\MIB_IFTABLE.cs

     文件       3427  2007-03-29 09:07  SystemInfo\SystemInfo\NetInfo.cs

     文件       1519  2007-03-29 09:07  SystemInfo\SystemInfo\ProcessInfo.cs

     文件      17310  2007-03-29 16:34  SystemInfo\SystemInfo\SystemInfo.cs

     文件       1385  2007-03-29 09:09  SystemInfo\SystemInfo.sln

    ..A..H.     24064  2007-04-11 09:18  SystemInfo\SystemInfo.suo

     文件        249  2007-03-29 09:08  SystemInfo\Test\Properties\Settings.settings

     文件       1162  2007-03-29 09:08  SystemInfo\Test\Properties\AssemblyInfo.cs

     文件       5612  2007-03-29 09:08  SystemInfo\Test\Properties\Resources.resx

     文件       2862  2007-03-29 09:08  SystemInfo\Test\Properties\Resources.Designer.cs

     文件       1087  2007-03-29 09:08  SystemInfo\Test\Properties\Settings.Designer.cs

     文件       6774  2007-03-29 15:58  SystemInfo\Test\frmProcess.resx

     文件       8826  2007-03-29 15:58  SystemInfo\Test\frmProcess.cs

     文件       3816  2007-03-29 15:57  SystemInfo\Test\Test.csproj

     文件      26464  2007-03-29 15:58  SystemInfo\Test\frmProcess.designer.cs

     文件       5814  2007-01-08 17:21  SystemInfo\Test\LineChart.resx

     文件       4181  2007-03-29 09:11  SystemInfo\Test\LineChart.cs

     文件       1599  2007-03-29 09:12  SystemInfo\Test\LineChart.Designer.cs

     文件        468  2007-03-29 09:14  SystemInfo\Test\Program.cs

     目录          0  2007-04-06 15:59  SystemInfo\SystemInfo\Properties

     目录          0  2007-04-06 15:59  SystemInfo\Test\Properties

     目录          0  2007-04-06 15:59  SystemInfo\SystemInfo

     目录          0  2007-04-06 15:59  SystemInfo\bin

     目录          0  2007-04-06 15:59  SystemInfo\Test

............此处省略4个文件信息

评论

共有 条评论