0

I have an Interface [BindControls] which takes data from GUI and store it into a list „ieis”.

After that, Into another class, which sends this data through WebServices, I want to take this data from „ieis” and put it into required by WS Class fields (bottom is a snippet of code)

This is the interface:

void BindControls(ValidationFrameBindModel<A.B> model)
        {
            model.Bind(this.mtbxTax, (obj, value) =>
            {
                var taxa = TConvertor.Convert<double>((string)value, -1);

                if (taxa > 0)
                {
                    var ieis = new List<X>();

                    var iei = new X
                    {
                        service = new ServiceInfo
                        {
                            id = Constants.SERVICE_TAX
                        }, 
                        amount = tax,
                        currency = new CurrencyInfo
                        {
                            id = Constants.DEFAULT_CURRENCY_ID
                        }
                    };
                    ieis.Add(iei);
                }
            },"Tax");
        }

This is the intermediate property:

//**********

class A 
{
  public B BasicInfo
        {
            get;
            set;
        }

 class B
        {

            public X Tax
            {
                get;
                set;
            }
        }
}

//***********

This is the class which sends through WS:

void WebServiceExecute(SomeType someParam)
        {
//into ‚iai’ i store the data which comes from interface

            var iai = base.Params.FetchOrDefault<A>( INFO, null);

            var convertedObj = new IWEI();
            //...            
            var lx = new List<X>();

 //1st WAY: I tried to put all data from ‚Tax’into my local list ‚lx’
            //lx.Add(iai.BasicInfo.Tax); - this way is not working

    //2nd WAY: I tried to put data separately into ‚lx’ 
            var iei = new X
            {
                service = new ServiceInfo
                {
                    id = iai.BasicInfo.Tax.service.id
                },
                amount = iai.BasicInfo.Tax.amount,
                currency = new CurrencyInfo
                {
                   id = iai.BasicInfo.Tax.currency.id
                }
            };

            lx.Add(iei);

// but also is not working

Can you help me please to suggest how to implement a way that will fine do the work (take data from ‚ieis’ and put her into ‚lx’). Thank you so much

9
  • 1
    When you say "not working" are you getting compiler errors, runtime errors? What exactly is happening? Commented Sep 21, 2011 at 13:54
  • 1st WAY: didn't add any data to lx [see here: s2.ipicture.ru/uploads/20110921/Sl2ViVSX.png ]. 2nd WAY: gives System.NullPointerException. Commented Sep 21, 2011 at 14:06
  • 1
    It sounds to me like iai.BasicInfo.Tax is null, this would explain the null reference exception in #2, and why you don't have any data in #1 (has one null reference). Can you stop in a debugger and verify, or log/console whether == null? Commented Sep 21, 2011 at 14:37
  • @James Michael Hare, yes, iai.BasicInfo.Tax is null ... how do i implement to be possible to extract data from it ? Commented Sep 22, 2011 at 6:49
  • 1
    It's not clear why you've got a nested type B within class A... Commented Sep 22, 2011 at 9:01

1 Answer 1

1

As noted in my comment, it looks like iai.BasicInfo.Tax is null, once you find out why that is null your original Add() (#1) will work.

Sign up to request clarification or add additional context in comments.

1 Comment

I found that Tax was null. After i made the mechanism to put values into it all works fine. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.