I suggest you ...

ExcludePropertyReferences for Data Contracts

Currently ExcludePropertyReferences is expecting DeclaringTypeName.DataContractName. Its more helpful if the type is fully qualified.

for example ; from below Json if we want to exclude :{"Officeaddress.houseaddress.city"}; .

Json:
//----------------------------------------------------------------------------
{"id":"eb26f100-3758-4a19-806b-cd5af44f88a4","data":{"lname":"Talluri","firstname":"RamaNaresh","city":"Atlanta"},"collections":{"houseaddress":[{"id":"126e057d-e91b-42ec-b40d-bdba9c831d64","data":{"city":"CA_Toronto"}}],"officeaddress":[{"id":"5ff48bd4-bfe2-4721-adf1-3f5cd3b5c736","data":{"city":"US_Alpharetta"},"collections":{"houseaddress":[{"id":"aad21efc-2768-4518-a505-71dc8b82ad40","data":{"city":"CA_Downtown"}}]}}]}}
//----------------------------------------------------------------------------
Model :
//----------------------------------------------------------------------------
[DataContract]
public class AddressModel : BaseModel
{
[DataMember(Name = "id")]
public System.Guid Id
{
get;
set;
}

[DataMember(Name = "data")]
public virtual BaseAddress Data
{
get;
set;
}

[DataMember(Name = "collections")]
public virtual AddressCollection Collections
{
get;
set;
}
}

[DataContract]
public class BaseAddress
{

[DataMember(Name = "lname")]
public string LastName
{
get;
set;
}
[DataMember(Name = "firstname")]
public string FirstName
{
get;
set;
}
[DataMember(Name = "city")]
public string City
{
get;
set;
}
}

[DataContract()]
public class AddressCollection
{

[DataMember(Name = "houseaddress")]
public virtual List<HAdddress> HAdddress{get; set;}

[DataMember(Name = "officeaddress")]
public virtual List<OAdddress> OAdddress { get; set; }

}


[DataContract]
public class HAdddress
{
[DataMember(Name = "id")]
public System.Guid Id
{
get;
set;
}

[DataMember(Name = "data")]
public virtual HAddressData Data
{
get;
set;
}
}

[DataContract]
public class OAdddress
{
[DataMember(Name = "id")]
public System.Guid Id
{
get;
set;
}

[DataMember(Name = "data")]
public virtual OAddressData Data
{
get;
set;
}

[DataMember(Name = "collections")]
public virtual SeAdddress Collection { get; set; }
}

[DataContract]
public class HAddressData
{
[DataMember(Name = "city")]
public string City { get; set; }
}

[DataContract]
public class OAddressData
{

[DataMember(Name = "city")]
public string City { get; set; }
}

[DataContract]
public class SeAdddress
{
[DataMember(Name = "houseaddress")]
public virtual List<HAdddress> SECAdddress { get; set; }
}

[DataContract]
public class SeAdddress2
{
[DataMember(Name = "id")]
public System.Guid Id
{
get;
set;
}

[DataMember(Name = "data")]
public virtual BaseAddress Data
{
get;
set;
}
}
[DataContract]
public class BaseModel
{
}

//-------------------------------------------------------------------------
object to serialize
//-------------------------------------------------------------------------
var aModel = new AddressModel
{
Id = Guid.NewGuid(),
Data = new BaseAddress() {FirstName = "RamaNaresh", LastName = "Talluri", City = "Atlanta"},
Collections = new AddressCollection()
{
HAdddress = new List<HAdddress>()
{
new HAdddress() {Id = Guid.NewGuid(), Data = new HAddressData() {City = "CA_Toronto"}}
},
OAdddress = new List<OAdddress>()
{
new OAdddress()
{
Id = Guid.NewGuid(),
Data = new OAddressData() {City = "US_Alpharetta"},
Collection = new SeAdddress()
{
SECAdddress =
new List<HAdddress>()
{
new HAdddress()
{
Id = Guid.NewGuid(),
Data = new HAddressData() {City = "CA_Downtown"}
}
}
}
}
}
}
};

jsScope.ExcludePropertyReferences= new []{"Officeaddress.houseaddress.city"};

Thanks

27 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Rama Naresh shared this idea  ·   ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base