Archive for October 8th, 2009

Linq Distinct!

I have a List of books- each book has a category – i want to find out all the unique categories involved, given a list of books- i knew i could do this with linq, but not quite sure how!

It turned out to be easy..

List<Category> categories = _books.Select(i => i.Category).Distinct();

There was a minor complication however- Distinct obviously needs to be able to compare different instances of Category- you can supply a delegate to a custom EquityComparer class- otherwise it will simply check if this is the same instance of the object, which will (probably) always come back false rendering your distinct useless. So i created this;

    public class CategoryComparer : IEqualityComparer<Category>
    {
        public bool Equals(Category x, Category y)
        {
            return x.Id == y.Id;
        }

        public int GetHashCode(Category obj)
        {
            return obj.Id.GetHashCode();
        }
    }

then updated my linq to use it..

List<Category> categories = _books.Select(i => i.Category).Distinct(new CategoryComparer());

No Comments

A complete list of .NET Serializers in 3.5

Just saw this pop up in my Google Reader and though I would blog it as it is tres useful!

.NET Serializers – Development With A Dot.

As of version 3.5 SP1, .NET comes along with the following serializers:

  • System.Runtime.Serialization.Formatters.Binary.BinaryFormatter: binary serializer used in .NET Remoting, type information is included, understands System.Runtime.Serialization.ISerializable;
  • System.Runtime.Serialization.Formatters.Soap.SoapFormatter: SOAP (XML) serializer used in .NET Remoting, includes type information, understands System.Runtime.Serialization.ISerializable;
  • System.Runtime.Serialization.DataContractSerializer: XML serializer used in WCF, does not include type information;
  • System.Runtime.Serialization.Json.DataContractJsonSerializer: JSON serializer used in WCF, does not include type information;
  • System.Runtime.Serialization.NetDataContractSerializer: binary serializer used in WCF, includes type information;
  • System.Xml.Serialization.XmlSerializer: XML serializer used in ASP.NET Web Services (ASMX), type information is not included, understands System.Xml.Serialization.IXmlSerializable;
  • System.Web.UI.LosFormatter: uses ObjectStateFormatter internally, does not account by itself;
  • System.Web.UI.ObjectStateFormatter: binary serializer used in ASP.NET for storing items in view state, control state and session, type information is included, understands System.Runtime.Serialization.ISerializable.

There isn’t, however, a common interface for all of these serializers, and, in fact, they have quite different requirements.

The base interfaces are:

  • System.Runtime.Serialization.IFormatter: for BinaryFormatter, SoapFormatter, NetDataContractSerializer and ObjectStateFormatter;
  • System.Runtime.Serialization.XmlObjectSerializer: for DataContractSerializer, DataContractJsonSerializer and NetDataContractSerializer;
  • XmlSerializer doesn’t have any interface that specifies its behavior.

The interfaces that can be used to control the serialization process are:

  • System.Runtime.Serialization.ISerializable: for all the IFormatter serializers;
  • System.Xml.Serialization.IXmlSerializable: for XmlSerializer.

Also, there are a couple of attribute classes that can be used to control the serialization process:

  • System.Xml.Serialization.SoapAttributeAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapElementAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapEnumAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapIgnoreAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapIncludeAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapTypeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlAnyAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlAnyElementAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlArrayAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlArrayItemAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlAttributeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlChoiceIdentifierAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlElementAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlEnumAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlIgnoreAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlIncludeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlRootAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlTypeAttribute (XmlSerializer)
  • System.Runtime.Serialization.CollectionDataContractAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.DataContractAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.DataMemberAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.EnumMemberAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.IgnoreDataMemberAttribute (XmlObjectSerializer)

Note that the Soap* attributes are only considered if the SoapBindingStyle.Document is set for the Style property of the binding, in ASP.NET Web Services, otherwise, its the Xml* attributes.

No Comments

I absolutely love these. They came at the lace wigs are good quality, and very soft. Absolutely love these extensions. I just love this hair. Hair came on time, I waited until after hair extensions uk very full, no shedding and it is been installed for 3 weeks now and yes I jus ordered 3 more bundles. Lol. I definitely recommend this company for your bundles ladies. They are soft, hair bundles on the head for human hair wigs and I would continue to recommend them. I have thinner hair so they cover and blend nicely.