예제 #1
0
        public static IEnumerable <ExcelClassMap> RegisterClassMapsInNamespace(this ExcelImporter importer, Assembly assembly, string namespaceString)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            if (namespaceString == null)
            {
                throw new ArgumentNullException(nameof(namespaceString));
            }

            if (namespaceString.Length == 0)
            {
                throw new ArgumentException("The namespace cannot be empty.", nameof(namespaceString));
            }

            IEnumerable <Type> classMapTypes = assembly
                                               .GetTypes()
                                               .Where(type => typeof(ExcelClassMap).IsAssignableFrom(type) && type.Namespace == namespaceString);

            ExcelClassMap[] classMaps = classMapTypes.Select(Activator.CreateInstance).OfType <ExcelClassMap>().ToArray();
            if (classMaps.Length == 0)
            {
                throw new ArgumentException($"No classmaps found in the namespace \"{namespaceString}\" in the assembly \"{assembly}\".", nameof(namespaceString));
            }

            foreach (ExcelClassMap classMap in classMaps)
            {
                importer.Configuration.RegisterClassMap(classMap);
            }

            return(classMaps);
        }
예제 #2
0
 internal ExcelSheet(IExcelDataReader reader, int index, ExcelImporter importer)
 {
     Reader = reader;
     Name   = reader.Name;
     if (reader.VisibleState == "visible")
     {
         Visibility = ExcelSheetVisibility.Visible;
     }
     else if (reader.VisibleState == "hidden")
     {
         Visibility = ExcelSheetVisibility.Hidden;
     }
     else
     {
         Visibility = ExcelSheetVisibility.VeryHidden;
     }
     Index    = index;
     Importer = importer;
 }
예제 #3
0
        public static IEnumerable <ExcelClassMap> RegisterClassMapsInNamespace(this ExcelImporter importer,
                                                                               Assembly assembly,
                                                                               string namespaceString)
        {
            if (namespaceString == null)
            {
                throw new ArgumentNullException(nameof(namespaceString));
            }

            if (namespaceString.Length == 0)
            {
                throw new ArgumentException("The namespace cannot be empty.", nameof(namespaceString));
            }

            if (!assembly.GetTypes().Any())
            {
                throw new ArgumentException("The assembly doesn't have any types.", nameof(assembly));
            }

            var classes = assembly
                          .GetTypes()
                          .Where(t => (t.IsAssignableFrom(typeof(ExcelClassMap)) || t.IsAssignableToGenericType(typeof(ExcelClassMap <>))) && t.Namespace == namespaceString);

            var objects = classes.Select(Activator.CreateInstance).OfType <ExcelClassMap>().ToList();

            if (!objects.Any())
            {
                throw new ArgumentException("No classmaps found in this namespace.", nameof(assembly));
            }

            foreach (var o in objects)
            {
                importer.Configuration.RegisterClassMap(o);
            }

            return(objects);
        }
예제 #4
0
 public static IEnumerable <ExcelClassMap> RegisterClassMapsInNamespace(this ExcelImporter importer,
                                                                        string namespaceString)
 {
     return(RegisterClassMapsInNamespace(importer, Assembly.GetExecutingAssembly(), namespaceString));
 }