Freigeben über


An implementation of a Generic Container for WCF

I am currently writing a service using WCF.  One of the things that I need to expose is a container that wraps my results to provide counts. I came up with the below implementations.  One of the things that becomes a problem is the resulting serialization of the container name. By default, the serialized object would be ContainerOf[T].  By defining a name with a String.Format type of syntax, [DataContract(Name="{0}sContainer")].  Would create  the following for the Apple object: ApplesContainer.

Enjoy

/// <summary>
/// Generic Container for holding results
/// </summary>
/// <typeparam name="T"></typeparam>
[DataContract(Name="{0}sContainer")]
public class Container<T>
{
    /// <summary>
    /// TotalResults that can be returned.
    /// </summary>
    [DataMember]
    public int TotalResults
    {
        get;
        set;
    }

    /// <summary>
    /// Container results.
    /// </summary>
    [DataMember]
    public IEnumerable<T> Results
    {
        get;
        set;
    }
}

 

References:

Comments