.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Xml Serialization: choose tag name for class instances in a generic ObservableCollection / List

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :WPF
 

Hi,

I've creating a class called Graphics, deriving from a generic ObservableCollection where T is a custom class called Graphic :

public class Graphics : ObservableCollection<Graphic>
{
public Graphics()
{
}
}

Another class has a Graphics field. When I serialize to XML this class, this works fine :

<MyOtherClassInstance>
 <Graphics>
  <Graphic id="1">
  <Graphic id="2">
  <Graphic id="3">
 </Graphics>
</MyOtherClassInstance>

But I would like to have the following:

<MyOtherClassInstance>
 <Gs>
  <Gr id="1">
  <Gr id="2">
  <Gr id="3">
 </Gs>
</MyOtherClassInstance>

How can I process, I can't find a solution.

Please help.

Thanks




View Complete Post


More Related Resource Links

Xml Serialization: change tag name of class instances in a generic ObservableCollection / List

  

Hi,

I've creating a class called Graphics, deriving from a generic ObservableCollection where T is a custom class called Graphic :

public class Graphics : ObservableCollection<Graphic>
{
public Graphics()
{
}
}

Another class has a Graphics field. When I serialize to XML this class, this works fine :

<MyOtherClassInstance>
 <Graphics>
  <Graphic id="1">
  <Graphic id="2">
  <Graphic id="3">
 </Graphics>
</MyOtherClassInstance>

But I would like to have the following:

<MyOtherClassInstance>
 <Gs>
  <Gr id="1">
  <Gr id="2">
  <Gr id="3">
 </Gs>
</MyOtherClassInstance>

How can I process, I can't find a solution.

Please help.

Thanks


Generic list of custom class returns data in WCF service layer, but loses them in Presentation Layer

  

I'm reading this excellent article by John Papa in MSDN Data Points - http://msdn.microsoft.com/en-us/magazine/cc700340.aspx

This single article alone sheds great deal of light on EF, WCF, WPF, MVP architecture, Layered Architecture with these technologies and so much more.

I'm trying to experiment with the code that comes with the article as is.

When executing the application, the service layer returns a Generic List with three Customer objects to the presentation layer. However, in presentation layer, the Generic list arrives with zero objects in the list. In the context of this application, I provide 'd' as a search criteria and hit the search button; while stepping through, I can see it returns 3 rows from the database.

With my limited experience in WCF, I am unable to figure out why it is so. This article was written  for 3.5 SP1 Beta 1. Could something changed in the general release that is causing this?


-Perennial Newbie-

Issue with x:TypeArguments, generic List class, and XAML

  

I created the following markup for a loose XAML file.

<StackPanel 
 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 
xmlns:sys="clr-namespace:System;assembly=mscorlib"
 
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib">
   
<scg:List x:TypeArguments="sys:String">
        HelloWorld
   
</scg:List>
</StackPanel>

But I get this error when I run the loose XAML in IE:

The tag 'List' does not exist in XML namespace 'clr-namespace:System.Collections.Generic;assembly=mscorlib'. Line '7' Position 2'.

As you would know, generics in XAML are a feature in XAML 2009 and can work for the most part only in loose XAML files. But the above code doesn't work.<

Format Generic List Bound to Gridview

  

I have a generic list of a custom type. The custom type has a string and double.

I'm binding the list to a gridview and it outputs everything fine.

I'm trying to format the double column into a currency format. It is in a template field as I'm calculating a running total. I pass the value to a function that returns a double and adds the current value to a running total which I will show in the footer.

The format is not changing to currency as expected when using String.Format("{0:c}", GetTotal(Convert.ToDouble(Eval("Amount"))))


Any ideas on what might be going on and how to fix this?

Thanks!


Advanced Basics: The ObservableCollection Class

  

Ken Getz shows how the CollectionChanged event lets you reflect changes to your underlying data source in your bound data controls.

Ken Getz

MSDN Magazine December 2008


Class To Contract: Enrich Your XML Serialization With Schema Providers In The .NET Framework

  

The Microsoft .NET Framework 1.x provided minimal options for mapping classes to schemas and serializing objects to XML documents, making this sort of mapping quite a challenge. The .NET Framework 2.0 changes all this with Schema providers and the IXmlSerializable interface.

Keith Pijanowski

MSDN Magazine June 2006


How to Cache System.Collection.Generic.List object

  

I need to cache System.Collection.Generic.List object with expiration time

var Root = from feed in feedhotel.Descendants(ota + "HotelContent")
                           where (feed.Attribute("HotelCode") != null)
                           select new xmlhotel()
                           {

....

....

    };

return Root.ToList();

Is it possible to cache Root.ToList() for some time....





XML Serialization & List

  

 Hi all,

 

I'm working on the following code :

 

[System.Runtime.Serialization.DataContractAttribute(Name = "SalesOrder")]
    public partial class SalesOrder
    {

        ...
        private List<OrderLine> orderLineField;

...

public SalesOrder()
        {
            this.orderLineField = new List<OrderLine>();
            this.orderHeaderField = new OrderHeader();
        }

[System.Runtime.Serialization.DataMemberAttribute()]
        public List<OrderLine> OrderLine
        {
            get
            {
                return this.orderLineFi

Navigate through a generic list using a webservice

  
Hi I have a problem where I would have a dataset coming to me and I would break into 5 new generic LIST<>. Now the user needs to see one record at a time and navigate through the list Fields like               From date : Text box with calendar                To Date : Text box with calendar               Manager Reporting To : Drop down list                Buttons on Move Back  and move Forward Now I would have 4 such similar lists which I have to pick up from the audit table. When the user clicks on move back and move forward buttons he should be able to navigate through records in my list that I have fetched in the beginning . I can store it in a session or viewstate till it gets updated again. How do I achieve this. Can I also a gridview instead of textboxes. What should be the simplest way to achieve this. Thanks!      

text box binding with Generic list

  
Hi, I am working in asp.net 3.5 page, where I want to bind a textbox with generic list data. And I have Previous & next button. Which will show the record in textbox. I don't want to go in db again and again.  Is it possible.??? 

Can serialize but not deserialize class containing an xs:list attribute using XmlSerializer

  
I have a simple serializable class along the lines of: [Serializable] [XmlType] public class MyClass { [XmlAttribute("values")] public int[] Values { get; set; } } If I create an instance of this class with Values set to an empty collection the XmlSerializer class produces this output as expected: <?xml version="1.0" encoding="utf-16" ?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" values="" /> However, deserializing this exact output throws a System.FormatException: Input string was not in a correct format. Shouldn't the XmlSerializer be able to deserialize this, since it produced the xml string in the first place?

Choose Item from dropdown list and display in a separate URL ASP.NET

  
Hi, I've a dropdown list for departments (engineering, bio, chemistry,physics etc.) when somebody choose the departments from the dropdown list, it displays the opening closing time(hours) in a detailsview controls. I have separate homepage for these departments ( these are the static html pages and no way to send querystring value) and I want to link the hours for each department from the departmental homepage. When I choose the department from the DDL, everytime it's the same URL. How can I solve the problem  So that I can point the respective hours from the respective departments ?   Thanks in advance.    

Customizing class serialization for dissimilar clients

  
In my class (with DataContract attribute) some properties,  [DataMember( Name = "Name",Order = 1)] are used by existing WCF clients. Now, I need to modify/supplement it to have only _some_ of these properties  to be serialized/deserialized on behalf a new non-WCF client, while not disrupting the existing WCF clients' functionality. What would be your choice: to use OnSerializing/ISerializable (how  to avoid serializing some properties?), to go SurrogateSelector way or to use something else for non-WCF client, like XmlSerializer, LINQ to XML, or something else.  One complication is that I would need for my non-WCF client to modify XML output into a a customer XML format (KLM),  while preserving serialization order and hierarchy. Which way would require less effort and/or provide more flexibility? I am using .NET 3.5 SP1 -Nick
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend