问题描述
本意:这里想对参数进行赋值,通一个类型的参数myBUOperatorInfo为本地的类,有20来个属性myWSBUOperatorInfo为WebService的类。本想动态的从myBUOperatorInfo读取值赋值到myWSBUOperatorInfo类若类是本地的,怎么调用都可以,但是类是WebService的,死活不行,哪位高人能解决这个问题,请加我JiRiGaLa_Bao@Hotmail.com比较急。wsFormLogin.BUOperatorInfomyWSBUOperatorInfo=newwsFormLogin.BUOperatorInfo();this.ConvertData(myBUOperatorInfo,myWSBUOperatorInfo);调用wsFormLogin这个WebServicewsFormLogin.wsFormLoginmywsFormLogin=newwsFormLogin.wsFormLogin();mywsFormLogin.Load(myWSBUOperatorInfo);#regionprivateintSetClassValue(refObjectmyTargetObject,StringparamName,ObjectparamValue)设置对象的属性///<summary>///设置对象的属性///</summary>///<paramname="myTargetObject">目标对象</param>///<paramname="paramName">属性名称</param>///<paramname="paramValue">目标值</param>///<returns>影响的属性个数</returns>privateintSetClassValue(ObjectmyTargetObject,StringparamName,ObjectparamValue){intreturnValue=0;TypemyType=myTargetObject.GetType();FieldInfo[]myFieldInfo=myType.GetFields(BindingFlags.FlattenHierarchy|BindingFlags.Public|BindingFlags.Static|BindingFlags.NonPublic|BindingFlags.Instance);FieldInfomyCurrentFieldInfo;for(inti=0;i<myFieldInfo.Length;i++){if(paramName.Equals(myFieldInfo[i].Name)){myCurrentFieldInfo=myType.GetField(paramName);myCurrentFieldInfo.SetValue(myTargetObject,paramValue);returnValue++;break;}}returnreturnValue;}#endregion#regionpublicObjectCopyObjectValue(ObjectmyObject,ObjectmyTargetObject)复制类对象的对应的值///<summary>///复制类对象的对应的值///</summary>///<paramname="myObject">当前对象</param>///<paramname="myTargetObject">目标对象</param>///<returns>对象</returns>publicObjectCopyObjectValue(ObjectmyObject,ObjectmyTargetObject){intreturnValue=0;StringparamName=String.Empty;TypemyType=myObject.GetType();FieldInfo[]myFieldInfo=myType.GetFields(BindingFlags.FlattenHierarchy|BindingFlags.Public|BindingFlags.Static|BindingFlags.NonPublic|BindingFlags.Instance);FieldInfomyCurrentFieldInfo;for(inti=0;i<myFieldInfo.Length;i++){paramName=myFieldInfo[i].Name;myCurrentFieldInfo=myFieldInfo[i];returnValue=this.SetClassValue(myTargetObject,paramName,myCurrentFieldInfo.GetValue(myObject));}returnmyTargetObject;}#endregion#regionprivatevoidConvertData(BUOperatorInfomyBUOperatorInfo,wsFormLogin.BUOperatorInfomyWSBUOperatorInfo)转换数据///<summary>///转换数据///</summary>///<paramname="myBUOperatorInfo">操作员信息</param>///<paramname="myWSBUOperatorInfo">远程传递信息</param>privatevoidConvertData(BUOperatorInfomyBUOperatorInfo,wsFormLogin.BUOperatorInfomyWSBUOperatorInfo){this.CopyObjectValue(myBUOperatorInfo,myWSBUOperatorInfo);}#endregion
解决方案
解决方案二:
关注,帮顶........
解决方案三:
privateintSetClassValue(ObjectmyTargetObject,StringparamName,ObjectparamValue)这句里面ref怎么不见了?其他还没有看完。
解决方案四:
我也遇到过类似的问题因为Webservice有个get方法获取了Webservice那定义的类才可以实用要么就作字符串传递过去再处理一下
解决方案五:
你把WS反射回来的类删掉,再使用你的本地类不就行了??为什么要搞这么复杂?