由于跨域访问 要求所有的输入输出参数 要么是继承MarshalByRefObject, 要么标记为可序列化
由于这些dll又是其他人开发的 我们没法修改它们继承与 MarshalByRefObject , 而且很多类型已经有了继承了...
那么只好在把类型变成可序列化上做功夫了
以前有写过一篇文件如何想办法把不可序列化的类 变为可序列化的
不可序列化的类 声明如下:
public
class
InputParameter
{
public string Name;
public int ? Type;
public decimal Money { get ; set ; }
}
{
public string Name;
public int ? Type;
public decimal Money { get ; set ; }
}
话说这个类写的真是够烂的..... - -#
只要实现一个它的子类 并实现ISerializable 接口 就可以在需要传递InputParameter的地方用它的子类代替它
代码如下:
public
class
SerializableParameter : InputParameter, ISerializable
{
public SerializableParameter(SerializationInfo info, StreamingContext context)
{
this .Name = info.GetString( " Name " );
if (info.GetValue( " Type " , typeof (Object)) != null )
this .Name = info.GetString( " Type " );
this .Money = info.GetDecimal( " Money " );
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue( " Name " , this .Name);
info.AddValue( " Type " , this .Type);
info.AddValue( " Money " , this .Money);
}
}
{
public SerializableParameter(SerializationInfo info, StreamingContext context)
{
this .Name = info.GetString( " Name " );
if (info.GetValue( " Type " , typeof (Object)) != null )
this .Name = info.GetString( " Type " );
this .Money = info.GetDecimal( " Money " );
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue( " Name " , this .Name);
info.AddValue( " Type " , this .Type);
info.AddValue( " Money " , this .Money);
}
}
C#里面 接口不能定义构造函数....真是悲剧啊 ,
PS:这个方法还是有一些限制的
1. 父类不能是密封的
2. 父类不能只有私有构造函数 (private 和 protected 构造函数的选择)
C#里面接口不能定义构造函数...所以这里没有定义对应的构造函数..会发生运行时错误....(BTW C#也不能定义静态接口.....CLR可以)
对于List<InputParameter>这样的集合 不能直接用 List<SerializableParameter> 来替代,不过可以构造一个List<InputParameter> 其内部项真实类型是 SerializableParameter