惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
量子位
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
IT之家
IT之家
V
Visual Studio Blog
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
D
Docker
V
V2EX

博客园 - mahope

一个算法题解 在ASP.NET web 站点中使用log4net (1.2.9) 在.NET 中实现 AOP Q & A:Does ASP.NET support one-way Web Service operations? openwave:Malformed server response web 项目的 csproj 文件要有对应的.webinfo文件才能在vs里面打开 - mahope 软件需求规范(SRS)指南 写需求文档的一般原则 删除everyone对c:的 访问权限后,运行asp.net出现DirectoryNotFoundException未找到路径“C:\”的一部分 - mahope - 博客园 NHibernate Mapping文件中如何指定类的字节数组属性 NHibernate.ADOException : Unable to perform find 对于事件不能调用BeginInvoke,可改用另外一层包装 IBM面试题试解(关于50条狗、50个人、病狗) Einstein's Riddle 爱因斯坦出的智力题? Artificial intelligence: Solving problems for the real world 一些面向对象的设计法则 重构、分支语句、虚函数、抽象函数与多态--《重构:改善既有代码设计》之读书心得 NHibernate 执行内嵌类(Nested Class)查询 为内嵌类(Nested Class)配置NHibernate的O/R Mapping文件
解决Web Service中传递子类实例时,序列化的问题。
mahope · 2006-03-26 · via 博客园 - mahope

首先,无论如何传递一个子类的实例是无法解决问题的。
其次,好像没有什么现成的方法能直接从子类的实例中创造出父类的实例来。我曾经尝试返回base,但是失败了。
于是,迫不得已,我只有通过反射来将子类对象的数据传递到父类对象去。
代码如下:

public class DerivedType:WS.BaseType,System.ICloneable 
    
{
 
public WS.BaseType Clone()
        
{
            WS.BaseType result 
= new WSClient.WS.BaseType();
            PropertyInfo[] props 
= result.GetType().GetProperties();
            
foreach (PropertyInfo prop in props)
                prop.SetValue(result, prop.GetValue(
thisnull), null);

            
return result;
        }


        
object ICloneable.Clone()
        
{
            
return this.Clone();
        }

}