xml - C# Calling list from Class -
this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
i pulling httpwebrequest warranty information. have tested each section information , worked. once put class failed.
my question is, how can call device class ?
dell computerrequest = new dell(apikey); xdocument xltest = new xdocument(); xltest = computerrequest.xmlresponse(txttag.text.trim()); xnamespace getassetwarrantya = "http://schemas.datacontract.org/2004/07/dell.awr.domain.asset"; xnamespace getassetwarrantyi = "http://www.w3.org/2001/xmlschema-instance"; list<device> xlasset = (from asset in xltest.descendants(getassetwarrantya + "response") select new device() { deviceinfo = (from defaultinfo in asset.descendants(getassetwarrantya + "dellasset") select new devicebase() { product = (string)asset.descendants(getassetwarrantya + "machinedescription").firstordefault(), ordernumber = (string)asset.descendants(getassetwarrantya + "ordernumber").firstordefault(), servicetag = (string)asset.descendants(getassetwarrantya + "servicetag").firstordefault(), shipdate = (string)asset.descendants(getassetwarrantya + "shipdate").firstordefault() }).tolist(), warrantyinfo = (from warranty in asset.descendants(getassetwarrantya + "warranty") select new warranty() { service = (string)warranty.descendants(getassetwarrantya + "serviceleveldescription").firstordefault(), provider = (string)warranty.descendants(getassetwarrantya + "serviceprovider").firstordefault(), startdate = (string)warranty.descendants(getassetwarrantya + "startdate").firstordefault(), enddate = (string)warranty.descendants(getassetwarrantya + "enddate").firstordefault(), typeofwarranty = (string)warranty.descendants(getassetwarrantya + "entitlementtype").firstordefault() }).tolist(), }).tolist(); **//fails -- no object set reference** device testdevice = new device(); messagebox.show(testdevice.warrantyinfo.count.tostring()); dtgrdwar.datasource = xlasset.toarray(); } public class device { public list<devicebase> deviceinfo{ get; set; } public list<warranty> warrantyinfo { get; set; } } public class devicebase { public string product { get; set; } public string ordernumber { get; set; } public string servicetag { get; set; } public string shipdate { get; set; } } public class warranty { public string service { get; set; } public string provider { get; set; } public string startdate { get; set; } public string enddate { get; set; } public string typeofwarranty { get; set; } }
xml:
<getassetwarrantyresponse xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <getassetwarrantyresult xmlns:i="http://www.w3.org/2001/xmlschema-instance" xmlns:a="http://schemas.datacontract.org/2004/07/dell.awr.domain.asset"> <a:faults/> <a:response> <a:dellasset> <a:assetparts i:nil="true"/> <a:countrylookupcode>11</a:countrylookupcode> <a:customernumber>117731304</a:customernumber> <a:isduplicate>false</a:isduplicate> <a:itemclasscode>oc002</a:itemclasscode> <a:localchannel>66</a:localchannel> <a:machinedescription>compellent sc8000,1st,2nd,upg</a:machinedescription> <a:ordernumber>nanananan</a:ordernumber> <a:parentservicetag i:nil="true"/> <a:servicetag>xxxxxxx</a:servicetag> <a:shipdate>2014-02-07t00:00:00</a:shipdate> <a:warranties> <a:warranty> <a:enddate>2016-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>933-5366</a:itemnumber> <a:servicelevelcode>s9</a:servicelevelcode> <a:serviceleveldescription>4 hour on-site service</a:serviceleveldescription> <a:servicelevelgroup>5</a:servicelevelgroup> <a:serviceprovider>uny</a:serviceprovider> <a:startdate>2015-07-31t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2016-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>974-9929</a:itemnumber> <a:servicelevelcode>zl</a:servicelevelcode> <a:serviceleveldescription>cml - storage center core base</a:serviceleveldescription> <a:servicelevelgroup>11</a:servicelevelgroup> <a:serviceprovider>dell</a:serviceprovider> <a:startdate>2015-07-31t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2016-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>933-5406</a:itemnumber> <a:servicelevelcode>sv</a:servicelevelcode> <a:serviceleveldescription>silver premium support</a:serviceleveldescription> <a:servicelevelgroup>8</a:servicelevelgroup> <a:serviceprovider>dell</a:serviceprovider> <a:startdate>2015-07-31t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2015-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>933-5416</a:itemnumber> <a:servicelevelcode>sv</a:servicelevelcode> <a:serviceleveldescription>silver premium support</a:serviceleveldescription> <a:servicelevelgroup>8</a:servicelevelgroup> <a:serviceprovider>dell</a:serviceprovider> <a:startdate>2014-08-01t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2015-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>933-5376</a:itemnumber> <a:servicelevelcode>s9</a:servicelevelcode> <a:serviceleveldescription>4 hour on-site service</a:serviceleveldescription> <a:servicelevelgroup>5</a:servicelevelgroup> <a:serviceprovider>uny</a:serviceprovider> <a:startdate>2014-08-01t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2015-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>975-0042</a:itemnumber> <a:servicelevelcode>zl</a:servicelevelcode> <a:serviceleveldescription>cml - storage center core base</a:serviceleveldescription> <a:servicelevelgroup>11</a:servicelevelgroup> <a:serviceprovider>dell</a:serviceprovider> <a:startdate>2014-08-01t00:00:00</a:startdate></a:warranty> <a:warranty> <a:enddate>2014-07-31t23:59:59</a:enddate> <a:entitlementtype>extended</a:entitlementtype> <a:itemnumber>933-5376</a:itemnumber> <a:servicelevelcode>s9</a:servicelevelcode> <a:serviceleveldescription>4 hour on-site service</a:serviceleveldescription> <a:servicelevelgroup>5</a:servicelevelgroup> <a:serviceprovider>uny</a:serviceprovider> <a:startdate>2014-02-07t00:00:00</a:startdate></a:warranty></a:warranties></a:dellasset></a:response></getassetwarrantyresult></getassetwarrantyresponse>
the issue class being created correctly. here correction curious:
public class device { private list<devicebase> _deviceinfo = new list<devicebase>(); private list<warranty> _warrantyinfo = new list<warranty>(); public list<devicebase> deviceinfo { { return _deviceinfo; } set { _deviceinfo = value; } } public list<warranty> warrantyinfo { { return _warrantyinfo; } set { _warrantyinfo = value; } } } public class devicebase { public string product { get; set; } public string ordernumber { get; set; } public string servicetag { get; set; } public string shipdate { get; set; } } public class warranty { public string service { get; set; } public string provider { get; set; } public string startdate { get; set; } public string enddate { get; set; } public string typeofwarranty { get; set; } }
Comments
Post a Comment