private IEnumerable <SitecoreClassConfig> GetClass(string assembly, string namesp) { Assembly assem = Assembly.Load(assembly); if (assem != null) { try { return(assem.GetTypes().Select(x => { if (x != null && x.Namespace != null && (x.Namespace.Equals(namesp) || x.Namespace.StartsWith(namesp + "."))) { IEnumerable <object> attrs = x.GetCustomAttributes(true); SitecoreClassAttribute attr = attrs.FirstOrDefault(y => y is SitecoreClassAttribute) as SitecoreClassAttribute; if (attr != null) { var config = new SitecoreClassConfig() { Type = x, ClassAttribute = attr, }; //TODO need to wrap in exception handler if (!attr.BranchId.IsNullOrEmpty()) { config.BranchId = new Guid(attr.BranchId); } if (!attr.TemplateId.IsNullOrEmpty()) { config.TemplateId = new Guid(attr.TemplateId); } return config; } } return null; }).Where(x => x != null).ToList()); } catch (ReflectionTypeLoadException ex) { throw new MapperException("Failed to load types {0}".Formatted(ex.LoaderExceptions.First().Message), ex); } } else { return(new List <SitecoreClassConfig>()); } }
private IEnumerable <SitecoreClassConfig> ProcessAssembly(Assembly assem, Func <Type, bool> predicate) { if (assem != null) { try { return(assem.GetTypes().Select(x => { if (predicate(x)) { IEnumerable <object> attrs = x.GetCustomAttributes(true); SitecoreClassAttribute attr = attrs.FirstOrDefault(y => y is SitecoreClassAttribute) as SitecoreClassAttribute; if (attr != null) { var config = new SitecoreClassConfig() { Type = x, ClassAttribute = attr, }; //TODO need to wrap in exception handler if (!attr.BranchId.IsNullOrEmpty()) { config.BranchId = new Guid(attr.BranchId); } if (!attr.TemplateId.IsNullOrEmpty()) { config.TemplateId = new Guid(attr.TemplateId); } return config; } } return null; }).Where(x => x != null).ToList()); } catch (ReflectionTypeLoadException ex) { throw new MapperException("Failed to load types {0}".Formatted(ex.LoaderExceptions.First().Message), ex); } } else { return(new List <SitecoreClassConfig>()); } }
private IEnumerable <SitecoreClassConfig> GetClass(string assembly, string namesp) { Assembly assem = Assembly.Load(assembly); if (assem != null) { return(assem.GetTypes().Select(x => { if (x != null && x.Namespace != null && x.Namespace.StartsWith(namesp)) { IEnumerable <object> attrs = x.GetCustomAttributes(true); SitecoreClassAttribute attr = attrs.FirstOrDefault(y => y is SitecoreClassAttribute) as SitecoreClassAttribute; if (attr != null) { var config = new SitecoreClassConfig() { Type = x, ClassAttribute = attr, }; //TODO need to wrap in exception handler if (!attr.BranchId.IsNullOrEmpty()) { config.BranchId = new Guid(attr.BranchId); } if (!attr.TemplateId.IsNullOrEmpty()) { config.TemplateId = new Guid(attr.TemplateId); } return config; } } return null; }).Where(x => x != null).ToList()); } else { return(new List <SitecoreClassConfig>()); } }