IsReference property in data contract

后端 未结 2 1745
一向
一向 2020-12-05 17:11

What is the purpose of IsReference property in DataContract? How does the request and response vary with this property applied?

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 17:47

    It determines how objects are serialized, by default, IsReference=false.

    Setting IsReference = true allows the serialization of trees of objects that can reference each other. So with a list of Employees that each have a property for Manager (who is also an Employee), a reference to the Manager for each Employee can be held rather than embedding the Manager within each Employee node:

    IsReference=false would produce:

     
           
          Kenny 
     
     
           
                 
                Kenny 
            
          Bob 
     
     
           
                 
                Kenny 
            
          Alice 
     
    

    Where as IsReference=true would produce:

     
            
          Kenny 
     
     
            
          Bob 
     
     
            
          Alice 
     
    

    Snippets taken from this weblog that has a full explanation along with examples of the generated XML with the property applied.

    MSDN - IsReference Property provides details as well as Interoperable Object References.

提交回复
热议问题