3

I need to know what is difference between
"IsGenericType", "IsConstructedGenericType" and "IsNested" properties?

My goal was to get all those object properties which have their own many properties...
Maybe object property is simple number, maybe it is a string.
But what if object property is another object with a lot of properties?

I was working for: How to get first object properties which are objects with a lot of properties.

 var shellFile1 = ShellFile.FromParsingName(PathOfanyFile);
 PropertyInfo[] P1 = shellFile1.Properties.System.GetType().GetProperties();
 var t1 = shellFile1.Properties.System;
 for (int i = 0; i < P1.Count(); i++)
 {
     var t2 = t1.GetType().GetProperty(P1[i].Name).GetValue(t1, null);
     if (t2.GetType().IsGenericType)
     {
          textBox1.Text += i + 1 + "   " + P1[i].Name + "\r\n";
     }
     else
     {
          textBox2.Text += i + 1 + "   " + P1[i].Name + "\r\n";
     }
 }                

In my code if you replace one line :

     if (t2.GetType().IsGenericType)    

by another line

     if (t2.GetType().IsConstructedGenericType)    

or using another line

     if (!t2.GetType().IsNested) 

then you will get the exact same result!

As I mentioned: "IsGenericType" and "IsConstructedGenericType" property gives the same result as inverse of "IsNested" property!

Is it true?
Is it always like right now?
Which one should I use to get constructed object properties?

  • Just tell me which one should I use? – IremadzeArchil19910311 Oct 07 '15 at 14:57
  • So you're actually not interested in the difference? Can you explain what _exactly_ you're trying to do? "get first object properties which are objects with a lot of properties" isn't really clear. – CodeCaster Oct 07 '15 at 15:18
  • Yeas it is! I need to know which one really helps me to get get that kind of properties? I think it must be done using "IsNested".... – IremadzeArchil19910311 Oct 07 '15 at 15:20
  • No, it is not! What is "first object properties"? What are "objects with a lot of properties"? What is a lot? What makes one class viable and the other not? Explain _exactly_ what you are trying to do. Show some example data. – CodeCaster Oct 07 '15 at 15:21
  • shellFile1.Properties.System.Comment.Value is a simple string; on the other hand shellFile2.Properties.System.Volume as a property is not a string. it has a lot of properties.... – IremadzeArchil19910311 Oct 07 '15 at 15:44
  • So the generic stuff is actually irrelevant, you're looking for all properties that are of a reference type (excluding strings)? Then search for that. – CodeCaster Oct 07 '15 at 16:11
  • @CodeCaster: could you explain how the question _asked before_ answers this one? I don't see any connection. `IsConstructedGenericType` isn't even mentioned anywhere. – t3chb0t Oct 14 '15 at 11:46
  • @t3chb0t [that question](http://stackoverflow.com/questions/1735035/generics-open-and-closed-constructed-types) answers OP's question _"I need to know what is difference between [...]"_. That that is actually not the question they need the answer to, does not change that fact - as they haven't edited their question since. It seems OP's actual question is answered in [Detecting if class property is a reference type](http://stackoverflow.com/questions/4628395/detecting-if-class-property-is-a-reference-type), for example. – CodeCaster Oct 14 '15 at 11:49
  • @t3chb0t or we could have a few intermediate questions. To answer the question according to the mentioned terminology, _"What is the difference between Property1, Property2 and Property3"_, one could simply [point to MSDN](https://msdn.microsoft.com/en-us/library/system.type.isconstructedgenerictype(v=vs.110).aspx): _"Type.IsConstructedGenericType - Gets a value that indicates whether this object represents a constructed generic type."_, from which the question _"But what is a constructed generic type?"_ follows, which is answered in the duplicate. – CodeCaster Oct 14 '15 at 11:51
  • @CodeCaster ok, you're right... I now see the connection :) – t3chb0t Oct 14 '15 at 11:53
  • @t3chb0t no problem, good for you to call me out on my close vote. I'd be happy to reopen if I'm proven wrong. :) – CodeCaster Oct 14 '15 at 11:54

0 Answers0