Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

How to return default class object in this situation

$
0
0

I am under a situation where i am not able to develop programming logic for the current situation.

Actually i have xml and i deserialied it into class objects suppose object of parent xml is "params".

Now what i have to achieve ? Some part of my code will get "ccypair" (it could be XAUUSD,EURUSD,USDEUR etc. ani will get this ccypair dynamically).

Once if i got this ccypair then i have to check in all Attributes of each parameter that **do the dynamically obtained ccypair equals to ccypair present in Attributes ? If yes then return that Attribute ** if do not exist then function will return the Attribute which do not contain ccypair(as you can see in my xml sample the first attribute class has no ccypair, so in the case if match do not found it will return this attribute class).

My xml is:

<parameters><parameter><component><attributes><item>1 000 000</item></attributes><attributes><ccypair>XAUUSD</ccypair><item>2000</item></attributes><attributes><ccypair>EURUSD</ccypair><item>50</item></attributes><attributes><ccypair>USDEUR</ccypair><item>1000</item></attributes></component></parameter><parameter><component><attributes><item>2065 000 000</item></attributes><attributes><ccypair>USDEUR</ccypair><item>8000</item></attributes></component></parameter><parameter><component><attributes><item>25555</item></attributes><attributes><ccypair>GBUSD</ccypair><item>18000</item></attributes></component></parameter></parameters>

And my code to do so is:

foreach(Parameter param in Parameters)
{
 attribute=  GetAttributeByCcyPair(Ccypair_Obtained_Dyamically, param);
}

public Attributes GetAttributeByCcyPair(string ccypair, Parameter param)
        {
            foreach (Attributes atrb in param.Component.Attributes)
            {
                if (atrb.Ccypair == ccypair)
                {
                      return atrb ;
                }
                else //
                {
                    if (atrb.Ccypair != ccypair && atrb.Ccypair==null)
                    {
                        return atrb;
                    }                   
                }
            }
            return null;
        }

My code works fine when there is match (i mean when atrb.Ccypair == ccypair)but when "ccypair" is null in that case it has to return the Attribute class in which ccypair is not present(i mean the first one in my xml but it could be anywhere), And problem with current code written is it just enters the else condition and returns the very first Attibute encounteres it even do not check other Attibutes ccypair.

Example. Supppose if dynamically obtained Ccypair_Obtained_Dyamically is "GBUSD" in this case all the returns of function must be:

(1) 1 000 000 (from first parameter because it do not match ccypair with dynamically obtained ccypair so it return attibute not containing "ccypair").

(2) 2065 000 000 (from second parameter, same reason).

(3) 18000 (because there is a match)

What change should i do to make my code work ?



Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>