示例#1
0
        private string GetCollectionXml(PropertyInfo prop, Infolight.EasilyReportTools.DataSourceItemCollection collection)
        {
            StringBuilder builder = new StringBuilder();
            if (prop != null && collection != null && prop.PropertyType == collection.GetType())
            {
                if (collection.Count > 0)
                {
                    builder.AppendLine(string.Format("\t<{0}>", prop.Name));
                    for (int i = 0; i < collection.Count; i++)
                    {
                        builder.Append(string.Format("\t\t<{0}:{1} ", "cc1", collection[i].GetType().Name));
                        PropertyInfo[] infos = collection[i].GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                        for (int j = 0; j < infos.Length; j++)
                        {
                            if (!IsVisibilityHidden(infos[j]))
                            {
                                if (infos[j].PropertyType == typeof(string) || infos[j].PropertyType == typeof(int) || infos[j].PropertyType == typeof(bool)
                                    || infos[j].PropertyType.BaseType == typeof(Enum))
                                {
                                    if (!infos[j].Name.Equals("Name"))
                                    {
                                        object value = infos[j].GetValue(collection[i], null);
                                        object defaultvalue = GetDefaultValue(infos[j]);
                                        if (infos[j].CanWrite && value != defaultvalue)
                                        {
                                            builder.Append(string.Format("{0}=\"{1}\" ", infos[j].Name, value));
                                        }
                                    }
                                }

                                if (infos[j].PropertyType == typeof(Infolight.EasilyReportTools.FieldItemCollection))
                                {
                                    builder.AppendLine(">");
                                    builder.AppendLine(string.Format("\t\t<{0}>", infos[j].Name));

                                    Infolight.EasilyReportTools.FieldItemCollection fieldItemCollection = (Infolight.EasilyReportTools.FieldItemCollection)infos[j].GetValue(collection[i], null);

                                    foreach (Infolight.EasilyReportTools.FieldItem item in fieldItemCollection)
                                    {
                                        builder.Append(string.Format("\t\t\t<{0}:{1} ", "cc1", item.GetType().Name));

                                        PropertyInfo[] itemProps = item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

                                        for (int k = 0; k < itemProps.Length; k++)
                                        {
                                            if (!IsVisibilityHidden(itemProps[k]))
                                            {
                                                if (itemProps[k].PropertyType == typeof(string) || itemProps[k].PropertyType == typeof(int) || itemProps[k].PropertyType == typeof(bool)
                                                || itemProps[k].PropertyType.BaseType == typeof(Enum))
                                                {
                                                    if (!itemProps[k].Name.Equals("Name"))
                                                    {
                                                        object itemValue = itemProps[k].GetValue(item, null);
                                                        object itemDefaultvalue = GetDefaultValue(itemProps[k]);
                                                        if (itemProps[k].CanWrite && itemValue != itemDefaultvalue)
                                                        {
                                                            builder.Append(string.Format("{0}=\"{1}\" ", itemProps[k].Name, itemValue));
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        builder.AppendLine("/>");
                                    }

                                    builder.AppendLine(string.Format("\t\t</{0}>", infos[j].Name));
                                }
                            }
                        }
                        builder.Append(string.Format("\t\t</{0}:{1}>", "cc1", collection[i].GetType().Name));
                    }
                    builder.AppendLine(string.Format("\t</{0}>", prop.Name));
                }
            }
            return builder.ToString();
        }
示例#2
0
 private string GetCollectionXml(PropertyInfo prop, Infolight.EasilyReportTools.ReportItemCollection collection)
 {
     StringBuilder builder = new StringBuilder();
     if (prop != null && collection != null && prop.PropertyType == collection.GetType())
     {
         if (collection.Count > 0)
         {
             builder.AppendLine(string.Format("\t<{0}>", prop.Name));
             for (int i = 0; i < collection.Count; i++)
             {
                 builder.Append(string.Format("\t\t<{0}:{1} ", "cc1", collection[i].GetType().Name));
                 PropertyInfo[] infos = collection[i].GetType().GetProperties();
                 for (int j = 0; j < infos.Length; j++)
                 {
                     if (!IsVisibilityHidden(infos[j]))
                     {
                         if (infos[j].PropertyType == typeof(string) || infos[j].PropertyType == typeof(int) || infos[j].PropertyType == typeof(bool)
                             || infos[j].PropertyType.BaseType == typeof(Enum))
                         {
                             if (!infos[j].Name.Equals("Name"))
                             {
                                 object value = infos[j].GetValue(collection[i], null);
                                 object defaultvalue = GetDefaultValue(infos[j]);
                                 if (infos[j].CanWrite && value != defaultvalue)
                                 {
                                     builder.Append(string.Format("{0}=\"{1}\" ", infos[j].Name, value));
                                 }
                             }
                         }
                     }
                 }
                 builder.AppendLine("/>");
             }
             builder.AppendLine(string.Format("\t</{0}>", prop.Name));
         }
     }
     return builder.ToString();
 }