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

  • SEARCH
  • Home
  • 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 8889365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:14:41+00:00 2026-06-14T22:14:41+00:00

Possible Duplicate: How to determine if the MethodInfo is an override of the base

  • 0

Possible Duplicate:
How to determine if the MethodInfo is an override of the base method

Normally, when we execute “ToString” method of any complex type it will return current type name like the following string except there is “ToString” overrided method.

System.Data.Entity.DynamicProxies.UserRole_D77A004638495805D68478322DF47F48540438D82DC9A5A0E1B0B2A181E4A100

I want some logic to detect current type about this because I try to export data to excel format. But some property of model is complex type that doesn’t define “ToString” method. Output of this property is useless for normal user.

enter image description here

Thanks,

  • 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-14T22:14:42+00:00Added an answer on June 14, 2026 at 10:14 pm

    I think this approach to check whether particular type overrides ToString or not is a little bit brittle. We can solve this in several other ways.

    First of all if string representation is required you can add additional mixin interface like IObjectDescriptor with one method: string GetDescription. And you can require this implentation from every type (and if class is not implements it throw an exception).

    Second approach (if we don’t want to change existing code base) is use separate helper class that will have one method: ConvertToString:

    static class ToStringHelper
    {
      // We can use Generic method to prevent boxing
      public string ConvertToString(object o)
      {
        var sb = new StringBuilder();
        // using reflection to access all public properties, for example
    
        return sb.ToString();
      }
    }
    

    In both cases your intention and “contract” between you and your clients would be much more clear. In first case you’ll throw an exception if type is not implements particular interface, with second approach you’ll get at least consistent behavior.

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

Sidebar

Related Questions

Possible Duplicate: .NET: Determine the type of this class in its static method How
Possible Duplicate: Python - Determine the type of an object? I want 'complex' to
Possible Duplicate: .NET: Determine the type of this class in its static method Hello
Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?
Possible Duplicate: How to determine the class of a generic type? How to obtain
Possible Duplicate: Determine Browser’s Version I want to determine the browser type in the
Possible Duplicate: How to determine the class of a generic type? I have a
Possible Duplicate: How to determine the attached type from within a custom attribute? I
Possible Duplicate: How do I determine an HTML input element type upon an event
Possible Duplicate: Determine if Equals() is an override? I need to run specific pieces

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.