社区
C#
帖子详情
不懂就问吧..我得到了一个System.Reflection.Assembly assembly对象
zhiang75
2005-05-23 05:58:43
想把它串行化...或者保存为一个文件什么的,各位大侠有高招吗?
MemoryStream memoryStream=new MemoryStream();
format.Serialize(memoryStream,assembly);
这个方法可行不通啊.
...全文
298
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)
C#反射机制.doc
反射的定义:审查元数据并收集关于它的类型信息的能力。元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建
一个
类定义表,
一个
字段定义表,和
一个
方法定义表等。 System.
reflection
命名空间包含的几个类,允许你反射(解析)这些元数据表的代码 System.
Reflection
.
Assembly
System.
Reflection
.MemberInfo System.
Reflection
.EventInfo System.
Reflection
.FieldInfo System.
Reflection
.MethodBase System.
Reflection
.ConstructorInfo System.
Reflection
.MethodInfo System.
Reflection
.PropertyInfo System.Type
将DLL嵌入到EXE大众
将dll动态库嵌入到exe当中,无需嵌入互操作类型 1、双击Resources.resx 2、添加现有文件 3、添加代码 public Form1() { //添加程序解析失败事件 AppDomain.CurrentDomain.
Assembly
Resolve += new ResolveEventHandler(CurrentDomain_
Assembly
Resolve);//添加代码 InitializeComponent(); JObject obj = new JObject(); } //添加代码 System.
Reflection
.
Assembly
CurrentDomain_
Assembly
Resolve(object sender, ResolveEventArgs args) { string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", ""); dllName = dllName.Replace(".", "_"); if (dllName.EndsWith("_resources")) return null; System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.
Reflection
.
Assembly
.GetExecuting
Assembly
()); byte[] bytes = (byte[])rm.GetObject(dllName); return System.
Reflection
.
Assembly
.Load(bytes); }
.NET5跨平台System.IO解析
本内容包含内容是作为
一个
C#/.NET开发者必须的技术储备;包含了IO操作的各种Api;多种序列化器的使用和封装.
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
{
C#
110,545
社区成员
642,580
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章