社区
C#
帖子详情
不懂就问吧..我得到了一个System.Reflection.Assembly assembly对象
zhiang75
2005-05-23 05:58:43
想把它串行化...或者保存为一个文件什么的,各位大侠有高招吗?
MemoryStream memoryStream=new MemoryStream();
format.Serialize(memoryStream,assembly);
这个方法可行不通啊.
...全文
323
21
打赏
收藏
不懂就问吧..我得到了一个System.Reflection.Assembly assembly对象
想把它串行化...或者保存为一个文件什么的,各位大侠有高招吗? MemoryStream memoryStream=new MemoryStream(); format.Serialize(memoryStream,assembly); 这个方法可行不通啊.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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)
vb.net 获取应用程序路径
获取应用程序路径,c# vb.net 源程序
c# 反射实例
//c# 反射实例 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.
Reflection
; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { // 类型名,方法名,参数 string className = "ConsoleApplication1.A"; string methodName = "Fun"; string param = "param"; // 获取程序集
Assembly
assembly
=
Assembly
.GetExecuting
Assembly
(); // 取得类型,方法;定义参数 Type type =
assembly
.GetType(className); MethodInfo method = type.GetMethod(methodName); object[] parameters = new object[] { param }; // 创建实例;调用方法(传递参数,获取返回值) object instance =
assembly
.CreateInstance(type.ToString()); string rt = (string)method.Invoke(instance, parameters); // 打印输出 Console.WriteLine(rt); Console.ReadKey(); } } class A { public string Fun(string param) { return "A.Fun:" + param; } } }
C#
Assembly
类访
问
程序集信息
C#中通过
Assembly
类可以访
问
程序集信息. 1.允许访
问
给定程序集的元元素,包含可以加载和执行程序集的方法; 2.加载程序集:使用静态方法
Assembly
.Load(程序集名称)或
Assembly
.LoadFrom(程序集完整路径名); 3.属性: FullName:程序集显示名称; 3.方法: GetTypes():获取程序集中定义的类型。 Test
Assembly
.cs: view plaincopy to clipboardprint? using System; using System.
Reflection
; namespace Magci.Test.
Reflection
{
( System.
Reflection
.
Assembly
.GetEntry
Assembly
() ).Location 路径解析
( System.
Reflection
.
Assembly
.GetEntry
Assembly
() ).Location
得到
的是可执行文件(.exe文件)的相对路径(如:"/…….Service/bin/Debug/…….Service.exe"),如果在Website下使用是错误的,是在Windows Service环境下使用的 获取应用程序的当前工作目录System.IO.Dire
System.
Reflection
名称空间下的程序集类
Assembly
应用.
利用反射中的程序集类(
Assembly
--抽象类)动态加载类库(.dll)或者可执行程序(.exe). 优点:①.可以消除if条件的逻辑判断.②.减少内存资源.③.有利于程序扩展. 缺点... 使用静态方法LoadFrom()加载外部.dll实例. //
Assembly
程序集中有三个加载程序集的方法(Load()、LoadFrom()和LoadFile()). ...
C#
111,120
社区成员
642,537
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章