Ejemplo n.º 1
0
      /// <summary>
      /// Convert a given object into a PropertyListDataTable.
      /// </summary>
      /// <param name="obj">Object to convert</param>
      /// <returns>DataTable filled out for each property of the given item</returns>
      private static GridDataTables.PropertyListDataTable GetPropertyList(object obj)
      {
          if (obj == null)
          {
              throw new ApplicationException("Cannot load null object in PropertyList");
          }

          GridDataTables.PropertyListDataTable propList = new GridDataTables.PropertyListDataTable();

          ServiceObject so = obj as ServiceObject;

          if (so != null)
          {
              foreach (PropertyDefinitionBase baseProp in so.GetLoadedPropertyDefinitions())
              {
                  if (baseProp != ItemSchema.ExtendedProperties)
                  {
                      GridDataTables.PropertyListRow row = propList.NewPropertyListRow();

                      PropertyInterpretation propInter = new PropertyInterpretation(so, baseProp);

                      if (propInter.Name != null)
                      {
                          row.Name = propInter.Name;
                      }
                      else
                      {
                          row.Name = "";
                      }

                      row.Value          = propInter.Value;
                      row.SmartView      = propInter.SmartView;
                      row.Type           = propInter.TypeName;
                      row.KnownNames     = propInter.AlternateNames;
                      row.PropertyObject = baseProp;

                      // SortName is simply the property name with a prefix to ensure
                      // that first class properties and extended properties stay grouped
                      // together.
                      if (baseProp is PropertyDefinition)
                      {
                          row.Icon     = global::EWSEditor.Properties.Resources.FirstProp;
                          row.SortName = string.Concat("a", row.Name);
                      }
                      else if (baseProp is ExtendedPropertyDefinition)
                      {
                          row.Icon     = global::EWSEditor.Properties.Resources.ExtProp;
                          row.SortName = string.Concat("b", row.Name);
                      }

                      // Add the row to the table
                      propList.AddPropertyListRow(row);
                  }
              }
          }
          else
          {
              Type objType = obj.GetType();

              foreach (PropertyInfo propInfo in objType.GetProperties())
              {
                  GridDataTables.PropertyListRow row = propList.NewPropertyListRow();

                  PropertyInterpretation propInter = new PropertyInterpretation(obj, propInfo);

                  row.Name = propInter.Name;

                  row.Value = propInter.Value.Substring(
                      0,
                      propInter.Value.Length > MAX_VALUE_LENGTH ? MAX_VALUE_LENGTH : propInter.Value.Length);
                  row.Type           = propInter.TypeName;
                  row.PropertyObject = propInfo;
                  row.Icon           = global::EWSEditor.Properties.Resources.FirstProp;
                  row.SortName       = string.Concat("a", row.Name);

                  // Add the row to the table
                  propList.AddPropertyListRow(row);
              }
          }

          return(propList);
      }