TechTalk Genome Wire Object Protocol v4.2

<Type> Element

Overrides a view definition on a derived class to further specialize what additional properties of the subclass are to be serialized in the message.

<View name=" view " type=" type ">
<Type name=" subtype " >
<Member name=" property1 " />
<Member name=" property2 " />
...
</Type>
</View>

or

<View name=" view " type=" type ">
<Type name="*" >
<Member name="*" />
</Type>
</View>
view
A name identifying the serialization view.
type
A type specifying a persistent class.
subtype
Type specifying a persistent subclass of type
property1, property2, ...
Public scalar, reference or Set properties defined on subtype.

Remarks

<Type> element overrides view on subtype to further specialize what additional properties of the subtype are to be serialized in the message.

Within each view definition it is possible to provide exactly one <Type> element per (direct or indirect) subclass of type. Overriding the view definition is optional. When not overridden no additional fields defined on the subclass will be included in the resulting message.

When an instance of a polymorphic class is serialized the serializer will choose the exact view definition based on the runtime type of the actual instance. Instances of the base class will ignore any view overrides while instances of a particular derived class will serialize both base class properties and properties declared in the overriden view. The same logic would apply when serializing a collection of persistent instances whereas each instance of the collection would be serialized based on its runtime type.

On every <Member> element of the subtype, the same filter and order clause have to be defined as for the corresponding <Member> element on the type (or none, if none was defined on the <Member> element of the type).

All scalar properties of each subclass can also be included using the asterisk (*) as type name. In this case the <Member> element inside the type specification can be used only with *.

Examples

          
Animal.cs
                    
public abstract class Animal : Persistent {

    public abstract Guid Id { get; set; }
    public abstract string Name { get; set; }
    public abstract TaxonomyClass Class { get; set; }
    public abstract int Age { get; set; }
}

public abstract class Bird : Animal {
    public abstract int FeatherCount { get; set; }
}

public abstract class Fish : Animal{
    public abstract string Length { get; set; }
}
                
          
AnimalViews.xml    
                    
<WireObjectProtocol xmlns="urn:TechTalk:Genome.Wop.Definition">
    <Using namespace="Zoo"/>
    
    <View name="Details" type="Animal">
        <Member name="Name" />
        <Member name="Class" />
        <Member name="Age" />
    </View>

    <View name="DetailsWithSubTypes" type="Animal">
        <Member name="Name" />
        <Member name="Class" />
        <Member name="Age" />
        
        <Type name="Bird">
            <Member name="FeatherCount" />
        </Type>

        <Type name="Fish">
            <Member name="Length" />
        </Type>
    </View>
</WireObjectProtocol>
                
          
ServiceLayer.cs
                    
using Zoo;
using Zoo.Dto;                  
using Zoo.Dto.Serializers;
                    
[WebService]
public class AnimalSerivces {

    [WebMethod]
    public AnimalDto GetByName1(string name) {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Animal animal = (Animal)DB.Extent(typeof(Animal))["Name = {0}", name].ToObject();
            
            // serializing the result to a DTO object with view "Details"
            return AnimalSerializer.SerializeDetails(animal);
        }
    }

    [WebMethod]
    public AnimalDto GetByName2(string name) {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Animal animal = (Animal)DB.Extent(typeof(Animal))["Name = {0}", name].ToObject();
            
            // serializing the result to a DTO object with view "DetailsWithSubTypes"
            return AnimalSerializer.SerializeDetailsWithSubTypes(animal);
        }
    }

    [WebMethod]
    public AnimalDtoCollection GetAll() {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Set animals = DB.Extent(typeof(Animal));
            
            // serializing the result to a 
            // DTO object collection with view "DetailsWithSubTypes"
            return AnimalSerializer.SerializeDetailsWithSubTypes(animals);
        }
    }
}
                
          
Transferred messages    
                    
<GetByName1Response>
    <GetByName1Result xsi:type="FishDto">
        <Id>1</Id>
        <Name>Nemo</Name>
        <Class>Fish</Class>
        <Age>1</Age>
    </GetByName1Result>
</GetByName1Response>   

<GetByName2Response>
    <GetByName2Result xsi:type="FishDto">
        <Id>1</Id>
        <Name>Nemo</Name>
        <Class>Fish</Class>
        <Age>1</Age>
        <Length>12</Length>
    </GetByName2Result>
</GetByName2Response>   

<GetAllResponse>
    <GetAllResult>
        <AnimalDto xsi:type="FishDto">
            <Id>1</Id>
            <Name>Nemo</Name>
            <Class>Fish</Class>
            <Age>1</Age>
            <Length>12</Length>
        </AnimalDto>
        <AnimalDto xsi:type="BirdDto">
            <Id>2</Id>
            <Name>Tweety</Name>
            <Class>Bird</Class>
            <Age>12</Age>
            <FeatherCount>500</FeatherCount>
        </AnimalDto>
        <AnimalDto xsi:type="BirdDto">
            <Id>2</Id>
            <Name>Oriole</Name>
            <Class>Bird</Class>
            <Age>2</Age>
            <FeatherCount>2000</FeatherCount>
        </AnimalDto>
    </GetAllResult>
</GetByClassResponse>   


                

Requirements

Type: TechTalk.Genome.Wop.Definition.Builder.Xml.TypeXmlData

Assembly: TechTalk.Genome.Wop.dll

Version: 4.2.11

Editions: Professional, Community, Evaluation