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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:29:55+00:00 2026-06-18T20:29:55+00:00

I have this class public class MyViewModel { public MyClass Thing { get; set;

  • 0

I have this class

public class MyViewModel {
  public MyClass Thing { get; set; }
  public int Id { get { return Thing.Id; } }
  public string Name { get { return Thing.Name; } }
}

I noticed when I bind it to an ASP.NET GridView, it automatically omits Thing, and for a good reason (ie. because otherwise it will only show the meaningless “MyNamespace.MyClass” in all rows)

I am trying to do a similar thing in this method.

public static string ConvertToCsv<T>(IEnumerable<T> items)
{
  foreach (T item in items)
  {
    if(item is not a native/.NET class) // <-- How do you do this?
      continue;
    else // If it is a string/int/bool/DateTime or something meaningful
    {
      ...
    }
  }
}
  • 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-18T20:29:57+00:00Added an answer on June 18, 2026 at 8:29 pm

    Not sure about performance, but you could use somthing along the lines of

    if(item.GetType().Namespace.StartsWith("System")) 
    {
       // do stuff
    }
    

    Or filter before looping

    public static string ConvertToCsv<T>(IEnumerable<T> items)
    {
        foreach (T item in items.Where(i => i.GetType().Namespace.StartsWith("System")))
        {
    
        }
    }
    

    Edit: after a quick test the method above has some flaws, If your object is nullable (MyViewModel?) it will be picked up in this check (System.Nullable<MyViewModel>).

    So perhaps you could use:

    public static string ConvertToCsv<T>(IEnumerable<T> items)
    {
        foreach (T item in items.Where(i => i.GetType().Module.ScopeName.Equals("CommonLanguageRuntimeLibrary")))
        {
    
        }
    }
    

    Another edit:
    There seems to be some issue with the last method also, But this one below is by far the fastest and most reliable, We just create a list of the System.Objects from the Assembly, and check if your item object is in that list.

    private List<Type> _systemTypes;
    public List<Type> SystemTypes
    {
        get
        {
            if (_systemTypes == null)
            {
                _systemTypes = Assembly.GetExecutingAssembly().GetType().Module.Assembly.GetExportedTypes().ToList();
            }
            return _systemTypes;
        }
    }
    
    public static string ConvertToCsv<T>(IEnumerable<T> items)
    {
        foreach (T item in items.Where(i => SystemTypes.Contains(i.GetType())))
        {
             // is system type
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this class public class Image { public string url { get; set;
I have this Class: public class User { public string id{ get; set; }
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
I have this class public class wordObject implements java.io.Serializable { String wordName; int occCount;
Say I have this class: public class Account { public int AccountID { get;
I have a ViewModel like this: public class MyViewModel { [Display(Name = One_Name, ResourceType
Suppose I have ViewModel like public class AnotherViewModel { public string Name { get;
I have this class : public class TempFileRef { public readonly string FilePath; public
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
In the world of MVC I have this view model... public class MyViewModel{ [Required]

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.