不懂就问吧..我得到了一个System.Reflection.Assembly assembly对象

zhiang75 2005-05-23 05:58:43
想把它串行化...或者保存为一个文件什么的,各位大侠有高招吗?
MemoryStream memoryStream=new MemoryStream();
format.Serialize(memoryStream,assembly);

这个方法可行不通啊.
...全文
298 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhiang75 2005-06-06
  • 打赏
  • 举报
回复
问题还是没有解决,谢谢大家
foolnet 2005-06-01
  • 打赏
  • 举报
回复
得到数据并且保存
:
byte[] b=foolClientService.GetDllData(versionAndFiles[i].Trim());
FoolClient.TrasportFileHelper.Save(b,"filename.dll");


上面三个要一起看
foolnet 2005-06-01
  • 打赏
  • 举报
回复
服务器下载:
public byte[] GetDllData(string fileName)
{

string fullName=Server.MapPath(".")+@"\TeacherDll\"+fileName;
//throw new Exception(fullName);
//LogonImpersonate.ImpersonateValidUser("administrator","foolnet","uninet.foolnet.testdomain");
LogonImpersonate.ImpersonateValidUser("NetExamUser","foolnet","ERIC");

byte[] b= TrasportFileHelper.GetData(fullName);

LogonImpersonate.UndoImpersonation();
return b;
}
foolnet 2005-06-01
  • 打赏
  • 举报
回复
public class TrasportFileHelper
{
public TrasportFileHelper()
{
//
// TODO: 在此处添加构造函数逻辑
//

}

public static bool Save(byte[] b,string fullName)
{
if(b.Length==0)
{
return false;
}
using(FileStream fs=File.Create(fullName,b.Length))
{
fs.Write(b, 0, b.Length);
}
return true;
}

public static byte[] GetData(string fullName)
{
if(File.Exists(fullName))
{
try
{
///打开现有文件以进行读取。
FileStream s = File.OpenRead(fullName);
byte[] b=ConvertStreamToByteBuffer(s);
s.Close();
return b;
}
catch
{
return new byte[0];
}
}
else
{
return new byte[0];
}
}

static byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}
}
zhiang75 2005-06-01
  • 打赏
  • 举报
回复
感谢 mixiaobo(andy在努力ing......)

还是不行 UP
mixiaobo 2005-05-30
  • 打赏
  • 举报
回复
我有一个序列化对象的函数,将对象序列化到字节数组,很好用的,这样就可以将字节数组保存为文件
/// <summary>
/// 二进制方式将object对象序列化到字节数组中
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static byte[] SerializeByBinary ( Object obj )
{
byte[] buffer2;
try
{
MemoryStream stream1 = new MemoryStream();
BinaryFormatter formatter1 = new BinaryFormatter();
formatter1.Serialize(stream1, obj);
byte[] buffer1 = stream1.ToArray();
stream1.Close();
buffer2 = buffer1;
}
catch
{
buffer2 = null;
}
return buffer2;

}

/// <summary>
/// 二进制方式字节数组中数据还原为对象
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static object DeSerializeByBinary ( byte[] byt )
{
object obj2;
try
{
MemoryStream stream = new MemoryStream(byt);
BinaryFormatter formatter = new BinaryFormatter();
object obj1 = formatter.Deserialize(stream);
stream.Close();
obj2 = obj1;
}
catch
{
obj2 = null;
}
return obj2;

}
zhiang75 2005-05-26
  • 打赏
  • 举报
回复
up
zhiang75 2005-05-26
  • 打赏
  • 举报
回复
to:rachy(黑色雨) ( )
呵呵,
可以告诉我如何吧System.Reflection.Assembly assembly
对象转换为Byte[] blob = new Byte[] 吗?

UP
zhiang75 2005-05-26
  • 打赏
  • 举报
回复
up
zhongwanli 2005-05-25
  • 打赏
  • 举报
回复
:(
rachy 2005-05-25
  • 打赏
  • 举报
回复
Byte[] blob = new Byte[]
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
fs.Write(blob, 0, blob.Length);
fs.Close();
zhiang75 2005-05-25
  • 打赏
  • 举报
回复
up
zhiang75 2005-05-24
  • 打赏
  • 举报
回复
这样的事情主要用在动态构造程序中,我希望,用户可以使用源代码来写程序,然后系统编译后成为系统的一部分,有源代码,但是不希望每次使用时重新编译......
huaren801007 2005-05-24
  • 打赏
  • 举报
回复
能不能在il的级别处理一下
学习ing
zhiang75 2005-05-24
  • 打赏
  • 举报
回复
up
niunj 2005-05-24
  • 打赏
  • 举报
回复
不是太明白 帮你顶一下
bumm 2005-05-24
  • 打赏
  • 举报
回复
能说说这样做,有什么用途吗?
bumm 2005-05-24
  • 打赏
  • 举报
回复
帮你顶一下。
zhiang75 2005-05-24
  • 打赏
  • 举报
回复
up
zhiang75 2005-05-24
  • 打赏
  • 举报
回复
up
加载更多回复(1)

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧