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 8006851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:38:48+00:00 2026-06-04T17:38:48+00:00

I have an object that’s being automatically serialized by the WebAPI, but I wanted

  • 0

I have an object that’s being automatically serialized by the WebAPI, but I wanted to wrap it to provide context to my data. An example would be:

public class SecureModel<T>
{
  public string Info { get; set; }
  public T Data { get; set; }
}

This serializes/deserializes no problem with my JSON requests and all is well. However, I want to verify some of that Info before I allow the request to finish executing, so I’ve added an ActionFilter where I’m retrieving parameters of my POST.

public class MyAuth : System.Web.Http.Filters.ActionFilterAttribute
{
  public override void OnActionExecuting(HttpActionContext actionContext)
  {
    var arg = actionContext.ActionArguments.FirstOrDefault().Value;
    // arg: get the Info?
    // if the info isn't correct, return a specific Response.
  }
}

When I examine the argument, it’s exactly what I need, however I can’t figure out how to weakly type it to SecureModel without specifying the actual generic type. I feel like I should be able to case this to SecureModel<object> and properly access the root, however it does not allow that. So far, I can only get the data I need using:

var notStrongEnough = arg.GetType().GetProperty("Info");

However, I’d prefer not to use Reflection for this and I am having a hard time moving forward without an answer. My alternative in this situation would be to change Data to a string and serialize/deserialize the JSON object manually, but that defeats some of the purpose of using Web API over MVC3.

Note: Changing the design to have SecureModel as the base class adds challenges to some of the hashing I am performing on the data, so I’d prefer to not go down that path either.

Thanks!

Edit: Misphrased title.

  • 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-04T17:38:50+00:00Added an answer on June 4, 2026 at 5:38 pm

    The typical solution to this sort of problem in C# is to create non-generic interfaces that your generic types implement. For example, with your class:

    public class SecureModel<T>
    {
        public string Info { get; set; }
        public T Data { get; set; }
    }
    

    You could define an interface, ISecureModel:

    public interface ISecureModel 
    {
        string Info { get; }
        object Data { get; }
    }
    

    And now you can implement it in your data class:

    public class SecureModel<T> : ISecureModel
    {
        public string Info { get; set; }
        public T Data { get; set; }
    
        object ISecureModel.Data {
            get { return Data; }
        }
    }
    

    We use explicit interface implementation here since the non-generic (object) and generic (T) versions of property Data would otherwise collide.

    Now, to get the info, you can simply cast to ISecureModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that is curently being serialized to: { label : label,
I have an object that contains a collection of items, each item being another
I have an object that has a generic IList in it that is being
I have object that is serialized into db. The question is where to keep
I have an object that is mapped to a cookie as a serialized base-64
I have an object that needs a test if the object data is valid.
I have an object that reads data from an Excel file using, which takes
We have a .Net object that has a static delegate (a data access strategy)
I have an object that has properties, but when I try to access them,
I have two tables: object that has object_id column and avalues that have object_id

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.