110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
classA ca = new classA();
ca.f1 = 1;
ca.f2 = 2;
A a1 = (A)ca;
MemoryStream ms = new MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(ms, a1);
ms.Position = 0;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf2 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf2.Binder = new ubind(typeof(classb).FullName);
B b1 = (B)bf2.Deserialize(ms);
}
}
public class ubind : SerializationBinder
{
private string strTypeName = "";
public ubind(string typeName)
{
strTypeName = typeName;
}
public override System.Type BindToType(string assemblyName, string typeName)
{
System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
typeName = strTypeName;
return ass.GetType(typeName);
}
}
public interface A
{
int f1 { get; set; }
int f2 { get; set; }
}
[Serializable()]
public class classA : A
{
private int _f1;
public int f1
{
get { return _f1; }
set { _f1 = value; }
}
private int _f2;
public int f2
{
get { return _f2; }
set { _f2 = value; }
}
}
public interface B
{
int f1 { get; set; }
int f2 { get; set; }
}
[Serializable()]
public class classb : B
{
private int _f1;
public int f1
{
get { return _f1; }
set { _f1 = value; }
}
private int _f2;
public int f2
{
get { return _f2; }
set { _f2 = value; }
}
}
}
using System;
using System.Web.UI;
using System.Configuration;
public class ClassA {
public String Text = "";
public ClassA() {
}
public ClassA(String dText) {
this.Text = dText;
}
public static explicit operator ClassB(ClassA dValue) {
return new ClassB(dValue.Text);
}
}
public class ClassB {
public String Text = "";
public ClassB() {
}
public ClassB(String dText) {
this.Text = dText;
}
public static explicit operator ClassA(ClassB dValue) {
return new ClassA(dValue.Text);
}
}
public partial class oMenu : UserControl {
protected void Page_Load(object sender, EventArgs e) {
ClassA a = new ClassA();
ClassB b = (ClassB)a;
}
}