TechTalk Genome Wire Object Protocol v4.2

<Extends> Element

Extends the view definition with the serialization information defined for another view.

<View name=" view " type=" type ">
<Extends view=" base-view " />
</View>
view
A name identifying the serialization view.
type
A type specifying a persistent class.
base-view
A view defined on type or one of its base types.

Remarks

<Extends> element can be used to extend the view with the serialization information defined in base-view. Multiple <Extends> elements can be specifed for each view. The serializer will always take the union of all fields declared on the view itself and on the views being extended.

When two extended views provide a declaration for the same reference or collection property the related persistent objects will be serialized with the union of the views defined in the extended views.

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

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 Cage Cage { get; set; }
}

public abstract class Cage : Persistent {
        public abstract Guid Id { get; set; }
        public abstract string Name { get; set; }
        public abstract int Size { get; set; }

        public abstract Set Inhabitants
        {
            [return: ElementType(typeof(Animal))]
            get;
        }
}
                
          
AnimalViews.xml    
                    
<WireObjectProtocol xmlns="urn:TechTalk:Genome.Wop.Definition">
    <Using namespace="Zoo"/>

    <View name="ListItem" type="Animal">
        <Member name="Name" />
        <Member name="Class" />
    </View>

    <View name="WithCage" type="Animal">
        <Member name="Name" />

        <Member name="Cage">
            <Member name="Name" />
            <Member name="Size" />
        </Member>
    </View>
    
    <View name="Full" type=Animal>
        <Extends view="ListItem" />
        <Extends view="WithCage" />
        
        <Member name="Age" />
    </View>
</WireObjectProtocol>
                
          
ServiceLayer.cs
                    
using Zoo;
using Zoo.Dto;                  
using Zoo.Dto.Serializers;
                    
[WebService]
public class AnimalSerivces {

    [WebMethod]
    public AnimalDto GetByName(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 "Full"
            return AnimalSerializer.SerializeFull(animal);
        }
    }
}
                
          
Transferred messages    
                    
<GetByNameResponse>
    <GetByNameResult xsi:type="AnimalDto">
        <Id>1</Id>
        <Name>Nemo</Name>
        <Class>Fish</Class>
        <Age>1</Age>
        <Cage>
            <Id>10</Id>
            <Name>Fishtank</Name>
            <Size>1</Size>
        </Cage>
    </GetByNameResult>
</GetByNameResponse>    

                

Requirements

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

Assembly: TechTalk.Genome.Wop.dll

Version: 4.2.11

Editions: Professional, Community, Evaluation

See Also

<View> Element