0

So, i'm not sure what i'm doing wrong here but for some reason the callback function in TypeScript that i have doesn't have anything but _proto in the response's .data property whenever i set private properties in C# and new up an object that is filled with constructed properties. However, if the properties are public and i don't use a constructor then i can see the response's .data property is filled like i would expect it to be. Here is an example of what works:

public class ThisWorks{
   public string MyProperty{get;set;}
}

Inside application layer:

ThisWorks example = new ThisWorks();
example.MyProperty = myReflectedProperty;
return example;

However, this does not work:

public class ThisDoesNotWork{
  private string MyPrivateProperty {get;set;}
    public ThisDoesNotWork(string myPrivateProperty){
        MyPrivateProperty = myPrivateProperty;
     }
 }

What's causing this to happen? My TypeScript service has not changed but for some reason the data isn't coming across from the service call...Any help would be greatly appreciated!

user1789573
  • 515
  • 2
  • 8
  • 23
  • What do you use to serialize your c# object? – Robert Moskal May 02 '16 at 15:13
  • Possible duplicate of [C# serialize private class member](http://stackoverflow.com/questions/4314982/c-sharp-serialize-private-class-member). Follow the thread in that question. It should get you where you need to go. – Robert Moskal May 02 '16 at 15:17
  • I didn't serialize in either case. Also, i forgot to mention i'm using TypeScript, actually. If you're going to say "add a serializer" then please don't as that is not helpful. – user1789573 May 02 '16 at 15:18
  • Then post the code that ships your c# object over to the client. – Robert Moskal May 02 '16 at 15:19
  • If you are returning your c# object from the application layer to the client, like in your snippet, you must be serializing it. – Robert Moskal May 03 '16 at 02:53
  • Hey, just try to make a public property and send it across like i did. I think you'll be VERY SURPRISED to know it WORKS! But, if you never try, then you'll never know...it's up to you if you want to figure it out or not, i can't make you do it... – user1789573 May 03 '16 at 13:47

0 Answers0