1

Not even sure I knew how to give the correct title for this question...

I have a class:

~ in 1st DLL

namespace ServerEnd
{
    class A
    {
         string field1 {get; set;}
         List<B> Nested {get;set;}
    }

    class B
    {
         string field1 { get; set;}
    }
}

~in 2nd DLL

namespace ClientEnd
{
    class A
    {
         string field1 {get; set;}
         List<B> Nested {get;set;}
    }

    class B
    {
         string field1 { get; set;}
    }
}

Now if I want to populate the client objects with the server objects I would use this:

var test = new ServerEnd.A();
test.field1 = "a test";
test.Nested = new ServerEnd.A.B();
test.Nested.Add(new (){field1 = "hi1" } ;

var clientModel = from x in test 
    select new ClientEnd.A
        {
            field1 = x.field1,
            * what do i put here to transpose data from list object *                
         };

But how do I populate the List from Server to Client?

Hope this is clear?

thanks

1
  • This looks much like a serialize and deserialize Commented Jul 14, 2016 at 18:58

2 Answers 2

4

Can use linq to build the ClientEnd.B objects

   var clientModel = from x in test 
        select new ClientEnd.A
            {
                field1 = x.field1,
                Nested = x.Nested
                          .Select(a=>new ClientEnd.B{ field1=a.field1 }).ToList()                
             };
Sign up to request clarification or add additional context in comments.

Comments

1

I assume that you could work with it the same as with a property.

Nested = x.Nested;

If you want to create a separate list you can just use ToList() so it will create another one:

Nested = x.Nested.ToList();

2 Comments

HI, I actually phrased my question wrong but your answer gave me a clue to fix it. As you answered the question i asked I accept - thanks
the types ServerSide.B and ClientSide.B are not the same, they just have the same properties so don't think this would work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.