home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / samples / classbrowser / ClassInfo.cs < prev    next >
Encoding:
Text File  |  2000-05-10  |  19.8 KB  |  513 lines

  1. using System ;
  2. using System.Web;
  3. using System.Web.UI; 
  4. using System.Collections;
  5. using System.Reflection;
  6.  
  7. namespace ClassInfo
  8. {
  9.  
  10. public class SortTable : Hashtable, IComparable
  11.    {
  12.        public String sortField;
  13.     
  14.        public SortTable(String sField)
  15.        {
  16.            sortField= sField;
  17.        }
  18.  
  19.        public int CompareTo(Object b)
  20.        {
  21.             return ((String)this[sortField]).CompareTo((String)((SortTable)b)[sortField]);
  22.        }
  23.    }
  24.  
  25.  
  26.  
  27.  
  28. public class DisplayFields : ArrayList
  29.     public  DisplayFields(Type classType) 
  30.     {
  31.         System.Reflection.FieldInfo[] fieldInfos = classType.GetFields();
  32.  
  33.         if (fieldInfos == null)
  34.             return;
  35.                
  36.         ArrayList fieldTable = new ArrayList();
  37.  
  38.         for (int x=0; x<fieldInfos.Length; x++)
  39.         {
  40.             SortTable fieldDetails = new SortTable("Name");
  41.  
  42.             fieldDetails["Name"] = fieldInfos[x].Name;
  43.             fieldDetails["Type"] = fieldInfos[x].FieldType.Name;
  44.             if(( fieldInfos[x].FieldType.IsArray && fieldInfos[x].FieldType.Name != "Array") ||  fieldInfos[x].FieldType.IsPointer)
  45.             {
  46.                 fieldDetails["GetType"]   = fieldInfos[x].FieldType.GetElementType().Name;
  47.                 fieldDetails["Namespace"] = fieldInfos[x].FieldType.GetElementType().Namespace;
  48.             }
  49.             else
  50.             {
  51.                 fieldDetails["GetType"]   = fieldInfos[x].FieldType.Name;
  52.                 fieldDetails["Namespace"] = fieldInfos[x].FieldType.Namespace;
  53.             }
  54.             if (fieldInfos[x].IsPublic == true) 
  55.             {
  56.                 fieldDetails["Access"] = "public ";
  57.             }
  58.             else if (fieldInfos[x].IsPrivate == true) 
  59.             {
  60.                 fieldDetails["Access"] = "private ";
  61.             }     
  62.             else if (fieldInfos[x].IsFamily == true) 
  63.             {
  64.                 fieldDetails["Access"] = "protected ";
  65.             }                  
  66.  
  67.             if (fieldInfos[x].IsStatic == true) 
  68.             {
  69.                 fieldDetails["Access"] = ((String) fieldDetails["Access"]) + "static ";
  70.             }
  71.  
  72.             if (fieldInfos[x].IsLiteral == true) 
  73.             {
  74.                 fieldDetails["Access"] = ((String) fieldDetails["Access"]) + "const ";
  75.             }
  76.  
  77.             this.Add(fieldDetails);
  78.        }
  79.          this.Sort();
  80.     }
  81. }
  82.  
  83. public class DisplayConstructors : ArrayList
  84. {
  85.     public DisplayConstructors(Type classType)
  86.     {
  87.         System.Reflection.ConstructorInfo[] constructorInfos = classType.GetConstructors();
  88.         
  89.         if (constructorInfos == null)
  90.             return;
  91.                
  92.         for (int x=0; x<constructorInfos.Length; x++) 
  93.         {
  94.             Hashtable constructorDetails = new Hashtable();
  95.  
  96.             constructorDetails["Name"] = classType.Name;
  97.  
  98.             if (constructorInfos[x].IsPublic == true) 
  99.             {
  100.                 constructorDetails["Access"] = "public ";
  101.             }
  102.             else if (constructorInfos[x].IsPrivate == true) 
  103.             {
  104.                 constructorDetails["Access"] = "private ";
  105.             }     
  106.             else if (constructorInfos[x].IsFamily == true) 
  107.             {
  108.                 constructorDetails["Access"] = "protected ";
  109.             }    
  110.  
  111.             System.Reflection.ParameterInfo[] paramInfos = constructorInfos[x].GetParameters();
  112.  
  113.             if (paramInfos != null)
  114.             {
  115.                 ArrayList paramTable = new ArrayList();
  116.                 for (int y=0; y<paramInfos.Length; y++)
  117.                 {     
  118.                     Hashtable paramDetails = new Hashtable();
  119.                     paramDetails["ParamName"] = paramInfos[y].Name;
  120.                     paramDetails["ParamType"] = paramInfos[y].ParameterType.Name;    
  121.                     if ( ( paramInfos[y].ParameterType.IsArray && paramInfos[y].ParameterType.Name !="Array" ) || paramInfos[y].ParameterType.IsPointer )  
  122.                     {
  123.                         paramDetails["GetType"]   = paramInfos[y].ParameterType.GetElementType().Name ;
  124.                         paramDetails["Namespace"] = paramInfos[y].ParameterType.GetElementType().Namespace ;
  125.                     }
  126.   
  127.                     else  
  128.                     {
  129.                     paramDetails["GetType"]   = paramInfos[y].ParameterType.Name;
  130.                         paramDetails["Namespace"] = paramInfos[y].ParameterType.Namespace ;
  131.                     }
  132.                     paramTable.Add(paramDetails); 
  133.                 }
  134.                  
  135.                 constructorDetails["Params"] = paramTable;
  136.             }    
  137.  
  138.             this.Add(constructorDetails);
  139.         }  
  140.     }
  141. }
  142.  
  143.  
  144. public class DisplayProperties : ArrayList
  145. {
  146.     public  DisplayProperties(Type classType) 
  147.     {
  148.         System.Reflection.PropertyInfo[] propertyInfos = classType.GetProperties();
  149.  
  150.         if (propertyInfos == null)
  151.             return;
  152.                
  153.         ArrayList propertyTable = new ArrayList();
  154.          
  155.         for (int x=0; x<propertyInfos.Length; x++)
  156.         {
  157.                          
  158.             SortTable propertyDetails = new SortTable("Name");
  159.                 
  160.             if(propertyInfos[x].GetGetMethod() != null)
  161.             {
  162.                 if(( propertyInfos[x].GetGetMethod().ReturnType.IsArray && propertyInfos[x].GetGetMethod().ReturnType.Name !="Array" ) || propertyInfos[x].GetGetMethod().ReturnType.IsPointer )
  163.                 {   
  164.                     propertyDetails["GetType"] = propertyInfos[x].GetGetMethod().ReturnType.GetElementType().Name;
  165.                     propertyDetails["Namespace"]=propertyInfos[x].GetGetMethod().ReturnType.GetElementType().Namespace;
  166.              
  167.                 }
  168.                 else
  169.                 {
  170.                     propertyDetails["GetType"] = propertyInfos[x].GetGetMethod().ReturnType.Name; 
  171.                     propertyDetails["Namespace"] = propertyInfos[x].GetGetMethod().ReturnType.Namespace;
  172.                 }
  173.                 propertyDetails["Type"] = propertyInfos[x].GetGetMethod().ReturnType.Name; 
  174.                 propertyDetails["Name"] = propertyInfos[x].Name;
  175.                
  176.                 if (propertyInfos[x].GetGetMethod().IsPublic == true) 
  177.                 {
  178.                      propertyDetails["Visibility"] = "public";
  179.                 }
  180.                 else if (propertyInfos[x].GetGetMethod().IsPrivate == true) 
  181.                 {
  182.                      propertyDetails["Visibility"] = "private";
  183.                 }     
  184.                 else if (propertyInfos[x].GetGetMethod().IsFamily == true) 
  185.                 {
  186.                     propertyDetails["Visibility"] = "protected";
  187.                 }                  
  188.                
  189.                 if (propertyInfos[x].GetGetMethod().IsStatic == true) 
  190.                 {
  191.                     propertyDetails["Visibility"] = ((String) propertyDetails["Visibility"]) + " static";
  192.                 }
  193.                   
  194.                 if (propertyInfos[x].GetSetMethod() == null)
  195.                 { 
  196.                     propertyDetails["Access"] =  "[Get]" ; 
  197.                 }
  198.             else
  199.                 {
  200.                 propertyDetails["Access"] = "[Get , Set]" ;
  201.             }    
  202.                   
  203.                 System.Reflection.ParameterInfo[] paramInfos = propertyInfos[x].GetGetMethod().GetParameters();
  204.                 
  205.                 if (paramInfos != null)
  206.                 {
  207.                     ArrayList paramTable = new ArrayList();
  208.                  
  209.                     for (int y=0; y<paramInfos.Length; y++)
  210.                     {     
  211.                         Hashtable paramDetails = new Hashtable();
  212.                         paramDetails["ParamName"] = paramInfos[y].Name;
  213.                         paramDetails["ParamType"] = paramInfos[y].ParameterType.Name;    
  214.                         if (( paramInfos[y].ParameterType.IsArray && paramInfos[y].ParameterType.Name !="Array") ||paramInfos[y].ParameterType.IsPointer )  
  215.                         {
  216.                             paramDetails["GetType"]   = paramInfos[y].ParameterType.GetElementType().Name ;
  217.                             paramDetails["Namespace"] = paramInfos[y].ParameterType.GetElementType().Namespace ;
  218.                         }
  219.                         else  
  220.                         {
  221.                         paramDetails["GetType"]   = paramInfos[y].ParameterType.Name;
  222.                             paramDetails["Namespace"] = paramInfos[y].ParameterType.Namespace ;
  223.                         }
  224.                         paramTable.Add(paramDetails); 
  225.                     }
  226.                  
  227.                     propertyDetails["Params"] = paramTable;
  228.                }
  229.             }
  230.             else if(propertyInfos[x].GetSetMethod() != null)
  231.             {
  232.                 
  233.                 propertyDetails["GetType"] = propertyInfos[x].GetSetMethod().ReturnType.Name; 
  234.                 propertyDetails["Namespace"] = propertyInfos[x].GetSetMethod().ReturnType.Namespace;
  235.               
  236.                 propertyDetails["Type"] = propertyInfos[x].GetSetMethod().ReturnType.Name; 
  237.                 propertyDetails["Name"] = propertyInfos[x].Name;
  238.             
  239.                 if (propertyInfos[x].GetSetMethod().IsPublic == true) 
  240.                 {
  241.                      propertyDetails["Visibility"] = "public";
  242.                 }
  243.                 else if (propertyInfos[x].GetSetMethod().IsPrivate == true) 
  244.                 {
  245.                      propertyDetails["Visibility"] = "private";
  246.                 }     
  247.                 else if (propertyInfos[x].GetSetMethod().IsFamily == true) 
  248.                 {
  249.                     propertyDetails["Visibility"] = "protected";
  250.                 }                  
  251.               
  252.                 if (propertyInfos[x].GetSetMethod().IsStatic == true) 
  253.                 {
  254.                     propertyDetails["Visibility"] = ((String) propertyDetails["Visibility"]) + " static";
  255.                 }
  256.                         
  257.             propertyDetails["Access"] = "[ Set ]" ;
  258.                       
  259.                 System.Reflection.ParameterInfo[] paramInfos = propertyInfos[x].GetSetMethod().GetParameters();
  260.                 
  261.                 if (paramInfos != null)
  262.                 {
  263.                     ArrayList paramTable = new ArrayList();
  264.                  
  265.                     for (int y=0; y<paramInfos.Length; y++)
  266.                     {     
  267.                         Hashtable paramDetails = new Hashtable();
  268.                         paramDetails["ParamName"] = paramInfos[y].Name;
  269.                         paramDetails["ParamType"] = paramInfos[y].ParameterType.Name;    
  270.                         if(( paramInfos[y].ParameterType.IsArray && paramInfos[y].ParameterType.Name !="Array") || paramInfos[y].ParameterType.IsPointer) 
  271.                         {
  272.                             paramDetails["GetType"]   = paramInfos[y].ParameterType.GetElementType().Name ;
  273.                             paramDetails["Namespace"] = paramInfos[y].ParameterType.GetElementType().Namespace ;
  274.                         }
  275.                         else  
  276.                         {
  277.                         paramDetails["GetType"]   = paramInfos[y].ParameterType.Name;
  278.                             paramDetails["Namespace"] = paramInfos[y].ParameterType.Namespace ;
  279.                         }
  280.                         paramTable.Add(paramDetails); 
  281.                     }
  282.                  
  283.                     propertyDetails["Params"] = paramTable;
  284.                }
  285.             }
  286.           
  287.            this.Add(propertyDetails);
  288.            
  289.         }
  290.         this.Sort();
  291.     }
  292. }        
  293.  
  294.  
  295. public class DisplayMethods : ArrayList
  296. {    
  297.      public DisplayMethods(Type classType, String myclassname)
  298.      { 
  299.          System.Reflection.MethodInfo[] methodInfos = classType.GetMethods(BindingFlags.Default) ;
  300.           
  301.          if (methodInfos == null)
  302.              return;
  303.                
  304.          for (int x=0; x<methodInfos.Length; x++) 
  305.          {
  306.              if((String.Compare(myclassname,methodInfos[x].DeclaringType.Name )==0)&&(methodInfos[x].IsPublic || methodInfos[x].IsFamily) && (!(methodInfos[x].IsSpecialName)) ) 
  307.              { 
  308.                  SortTable MethodDetails = new SortTable("Name");
  309.  
  310.                  MethodDetails["Name"] = methodInfos[x].Name;
  311.                  MethodDetails["Type"] = methodInfos[x].ReturnType.Name;
  312.                  if(( methodInfos[x].ReturnType.IsArray && methodInfos[x].ReturnType.Name !="Array") ||  methodInfos[x].ReturnType.IsPointer)  
  313.                  {
  314.                      // For Supporting Multi-Dimension Arrays as Return Type 
  315.                      Type ReturnElementType =  methodInfos[x].ReturnType.GetElementType();
  316.                      while(ReturnElementType.IsArray)
  317.                      {
  318.                         ReturnElementType =  ReturnElementType.GetElementType();    
  319.                      }
  320.  
  321.                      MethodDetails["GetType"]   = ReturnElementType.Name ;
  322.                      MethodDetails["Namespace"] = ReturnElementType.Namespace ;
  323.                       
  324.                  }
  325.                  else  
  326.                  {
  327.                  
  328.                   MethodDetails["GetType"] = methodInfos[x].ReturnType.Name;
  329.                       MethodDetails["Namespace"] = methodInfos[x].ReturnType.Namespace ;
  330.                  }             
  331.                 
  332.                  if (methodInfos[x].IsPublic == true) 
  333.                  {
  334.                      MethodDetails["Access"] = "public ";
  335.                  }
  336.                  else if (methodInfos[x].IsPrivate == true) 
  337.                  {
  338.                      MethodDetails["Access"] = "private ";
  339.                  }     
  340.                  else if (methodInfos[x].IsFamily == true) 
  341.                  {
  342.                      MethodDetails["Access"] = "protected ";
  343.                  }    
  344.                  
  345.                  if (methodInfos[x].IsStatic == true) 
  346.                  {
  347.                      MethodDetails["Access"] = ((String) MethodDetails["Access"]) + "static ";
  348.                  }
  349.  
  350.                  System.Reflection.ParameterInfo[] paramInfos = methodInfos[x].GetParameters();
  351.  
  352.                  if (paramInfos != null)
  353.                  {
  354.                   
  355.                      ArrayList paramTable = new ArrayList();
  356.                  
  357.                      for (int y=0; y<paramInfos.Length; y++)
  358.                      {     
  359.                          Hashtable paramDetails = new Hashtable();
  360.                          paramDetails["ParamName"] = paramInfos[y].Name;
  361.                          paramDetails["ParamType"] = paramInfos[y].ParameterType.Name;
  362.                          if(( paramInfos[y].ParameterType.IsArray && paramInfos[y].ParameterType.Name != "Array" )  || paramInfos[y].ParameterType.IsPointer)
  363.                          {
  364.                              paramDetails["GetType"]   = paramInfos[y].ParameterType.GetElementType().Name ;
  365.                              paramDetails["Namespace"] = paramInfos[y].ParameterType.GetElementType().Namespace ;
  366.                          }
  367.                          else  
  368.                          {
  369.                          paramDetails["GetType"]   = paramInfos[y].ParameterType.Name;
  370.                              paramDetails["Namespace"] = paramInfos[y].ParameterType.Namespace ;
  371.                          }
  372.                          paramTable.Add(paramDetails);
  373.                      }
  374.                      
  375.                      MethodDetails["Params"] = paramTable;
  376.                  }
  377.  
  378.                 this.Add(MethodDetails);
  379.              }
  380.         }
  381.          this.Sort();
  382.     }
  383.  
  384. public class DisplayInterfaces : ArrayList
  385. {
  386.     public DisplayInterfaces(Type classType)
  387.     {
  388.          Type[] classInterfaces = classType.GetInterfaces();
  389.          for(int x = 0 ; x < classInterfaces.Length ; x++)
  390.          {
  391.             
  392.             Hashtable interfaceDetails = new Hashtable();
  393.  
  394.             interfaceDetails["FullName"]     = classInterfaces[x].FullName;
  395.             interfaceDetails["GetType"]      = classInterfaces[x].Name;
  396.             interfaceDetails["Namespace"]    = classInterfaces[x].Namespace;
  397.             this.Add(interfaceDetails);
  398.          }
  399.          
  400.      }
  401. }
  402.  
  403.  
  404. public class DisplaySuperclasses : ArrayList
  405. {
  406.     public DisplaySuperclasses(Type classType)
  407.     {
  408.        Type SuperClass ;
  409.  
  410.        Hashtable classDetails = new Hashtable();
  411.  
  412.        classDetails["FullName"]     = classType.FullName;
  413.        classDetails["GetType"]      = classType.Name;
  414.        classDetails["Namespace"]    = classType.Namespace;
  415.  
  416.        this.Add(classDetails);
  417.  
  418.        while (classType.BaseType != null)
  419.        {
  420.            Hashtable superclassDetails = new Hashtable();
  421.            SuperClass =  classType.BaseType ;
  422.            classType   =  SuperClass        ;
  423.  
  424.            superclassDetails["FullName"]     = SuperClass.FullName;
  425.            superclassDetails["GetType"]      = SuperClass.Name;
  426.            superclassDetails["Namespace"]    = SuperClass.Namespace;
  427.  
  428.            this.Add(superclassDetails)    ;
  429.        }
  430.        this.Reverse() ;
  431.     }
  432.    
  433. }
  434.  
  435. public class DisplaySubClasses : ArrayList 
  436. {
  437.      private Type        classType ;
  438.      private Module[]      CorRuntime ;
  439.      private Type[]      CorClasses;
  440.      private String      myclassname ;
  441.      private Type[]      classInterfaces; 
  442.  
  443.  
  444.     
  445.     public DisplaySubClasses(Type classtype,ArrayList ModuleName)
  446.     {
  447.         this.classType =classtype ;
  448.         myclassname = classType.FullName ;
  449.         if (classType.IsInterface ) 
  450.         {
  451.             for(int y = 0 ; y <  ModuleName.Count ;y++)
  452.             {
  453.                 
  454.                 CorRuntime = Assembly.Load(ModuleName[y].ToString()).GetModules(); //System.Assembly.Load(ModuleName[y].ToString()).GetModules();
  455.             CorClasses   = CorRuntime[0].GetTypes() ;
  456.                                    
  457.                 for(int x= 0 ; x < CorClasses.Length; x++)
  458.                 {
  459.                     classType       =  CorClasses[x];
  460.                     classInterfaces =  classType.GetInterfaces() ;
  461.                 
  462.                     for(int  i = 0 ; i < classInterfaces.Length ; i++)
  463.             {
  464.                         if(String.Compare(myclassname , classInterfaces[i].FullName )==0)
  465.                         {
  466.  
  467.                              SortTable subclassDetails     = new SortTable("FullName");
  468.                              subclassDetails["FullName"]     = classType.FullName;
  469.                              subclassDetails["GetType"]      = classType.Name;
  470.                              subclassDetails["Namespace"]    = classType.Namespace;
  471.                   this.Add(subclassDetails) ;      
  472.                 }
  473.                     }
  474.                 }
  475.             }
  476.         }                  
  477.          
  478.         else 
  479.         {
  480.             for(int y = 0; y < ModuleName.Count ; y++)  
  481.             {
  482.                 CorRuntime = Assembly.Load(ModuleName[y].ToString()).GetModules() ;
  483.              CorClasses  = CorRuntime[0].GetTypes() ;
  484.  
  485.                 for( int x= 0 ; x< CorClasses.Length ;x++)
  486.                 {
  487.                     classType = CorClasses[x].BaseType ;
  488.  
  489.                     if ( null != classType  )  
  490.                     {
  491.                         if( String.Compare(classType.FullName, myclassname)==0)
  492.                         {
  493.                             SortTable subclassDetails     = new SortTable("FullName");
  494.                             subclassDetails["FullName"]     = CorClasses[x].FullName;
  495.                             subclassDetails["GetType"]      = CorClasses[x].Name;
  496.                             subclassDetails["Namespace"]    = CorClasses[x].Namespace;
  497.                  this.Add(subclassDetails) ;      
  498.                         }      
  499.                     }
  500.                 }
  501.             }
  502.         }
  503.         this.Sort();
  504.     }
  505. }
  506.  
  507.  
  508. }
  509.  
  510.  
  511.