Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:31:45+00:00 2026-06-15T09:31:45+00:00

I have problem with architectural problem for my C# application. I need to have

  • 0

I have problem with architectural problem for my C# application. I need to have the following JSON:

{data:{lat:22,lng:33}, error:{code:0,description:""}}

I’m trying to implement this JSON structure with these classes:

public class Response
{
    public object Data { get; set; }
    public object Error { get; set; }

    public Response()
    {
        Error = new ErrorsManager();
    }
}

public class Coordinates : Response
{
    public double Lat { get; set; }
    public double Lng { get; set; }
}

I can set values for Error without any problems. But how to set values for Data I can’t understand. Can anybody suggest proper solution for this situation? I know that this problem can be solved with extends in Java. Can I use something similar in C#?

Update: I’d like to have common root objects in JSON – data and error. But data object can have different context like: coordinates, user data, etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:31:46+00:00Added an answer on June 15, 2026 at 9:31 am

    You would set Data to an instance of coordinates. That is something like this:

    public class Response
    {
        public object Data { get; set; }
        public object Error { get; set; }
    
        public Response()
        {
            Error = new ErrorsManager();
            Data = new Coordinates();
        }
    }
    
    public class Coordinates {
        public double Lat { get; set; }
        public double Lng { get; set; }
    }
    

    You might think about creating strongly typed versions of Response meaning something like this:

    public class Response
    {
        public Coordinates Data { get; set; }
        public ErrorsManager Error { get; set; }
    
        public Response()
        {
            Error = new ErrorsManager();
            Data = new Coordinates();
        }
    }
    

    If you have different response types, you might want to have a base class defining only Error and the subclasses adding a new property. I assume you’re using something like JSON.NET to serialize / deserialize.

    You could be generic:

    public class Response<T> where T : new() {
        public T Data { get; set; }
        public ErrorsManager Error { get; set; }
    
        public Response() {
            Error = new ErrorsManager();
            Data = new T();
        }
    }
    
    public class Coordinates {
        /* left away */
    }
    

    Usage:

    var response = new Response<Coordinates>();
    response.Data.Lat = 0.01;
    // whatever you like
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a classical 3-tier-architecture application. Now we face a little problem and we
I have problem with show or hide form in Window Form Application. I start
I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I'd like to implement ASP.Net MVC application which could have controllers, views and content
I have a legacy dot net application (now migrated to .net 2.0). We need
I have a bit of an architecture problem here. Say I have two tables,
it's a kind of client-server architecture problem. I have 2 projects in my solution:
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.