Question

I am c# silvelight5 beginner and under a situation that i have to create my own Converter() function which must be similar like Converter() function derived from IValueConverter Interface.

What data i have right now ? I have correctly deserialized xml and on deserializing i got this:

XmlSerializer deserializer = new XmlSerializer(typeof(Parameter));//this Parameter is class obtained from(Root node of xml) and "parameter" is object.
XmlReader reader = XmlReader.Create(new StringReader(xmlstring));
Parameter parameter = (Parameter)deserializer.Deserialize(reader);
foreach (var item in parameter.Component.Attributes.Items)
{
    Debug.WriteLine(item);//It works correctly i have debugged
}

As you can see that i have object parameter which now contains the xml elements and roots (I mean all the data). Using this object now i tried to create Converter equivalent like this(his code is also in the same class):

ICollection<Parameter> list = parameter as ICollection<Parameter>;// **Problem creating line**
List<UIElement> result = new List<UIElement>();   

You can see this "parameter" is obtained from deserialization and i was sure on debugging that it is deserialized properly. So here i have replaced "value" of converter() to "parameter".

The problem is when i debug and see then the parameter contains all deserialized xml but i don't know why "list" shows null always ? even i can see all the xml elements(i mean node values) on debugging but why "parameter" is not assigned to "list" ? (I guess it shows null because this parameter is of Parameter type. But how to make it use in current context ?)

Could some one please correct me and write me the way to equivalent of Converter() where we have already the object obtained from deserializing xml ? would be a big help.

Was it helpful?

Solution

I found the solution of this finally actually there was no need to do :

ICollection<Parameter> list = parameter as ICollection<Parameter>;// **Problem creating line**
List<UIElement> result = new List<UIElement>(); 

we can directly use parameter object obtained from :

Parameter parameter = (Parameter)deserializer.Deserialize(reader);

and put if() conditions to access the desired xml elements/Class value(or you can say node) there is no need of creating list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top