Пример #1
0
        private IElementDef LoadType(Type type, LoadSpec spec)
        {
            if (!spec.TypeFilter(type)) return null;

            // skip primitive types
            if (IsPrimitive(type)) return null;

            // skip if defined
            var def = GetElementDef(type);
            if (def != null) return def;

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                LoadType(type.BaseType, spec);
            }

            var typeSpec = spec.ForType(type);
            var elem = Element(type, typeSpec.Names);

            type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                .Where(spec.PropertyFilter ?? (p => true))
                .ToList()
                .ForEach(property =>
                {
                    // TODO handle collections
                    LoadType(property.PropertyType, spec);

                    var propertySpec = spec.ForProperty(property);
                    // add IPropertyDef
                });

            return elem;
        }
Пример #2
0
 public void LoadFrom(Assembly assembly, LoadSpec spec)
 {
     if (assembly == null)
     {
         throw new ArgumentNullException("assembly");
     }
     if (spec == null)
     {
         throw new ArgumentNullException("spec");
     }
     assembly.GetTypes().ToList().ForEach(type => LoadType(type, spec));
 }
Пример #3
0
        private IElementDef LoadType(Type type, LoadSpec spec)
        {
            if (!spec.TypeFilter(type))
            {
                return(null);
            }

            // skip primitive types
            if (IsPrimitive(type))
            {
                return(null);
            }

            // skip if defined
            var def = GetElementDef(type);

            if (def != null)
            {
                return(def);
            }

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                LoadType(type.BaseType, spec);
            }

            var typeSpec = spec.ForType(type);
            var elem     = Element(type, typeSpec.Names);

            type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
            .Where(spec.PropertyFilter ?? (p => true))
            .ToList()
            .ForEach(property =>
            {
                // TODO handle collections
                LoadType(property.PropertyType, spec);

                var propertySpec = spec.ForProperty(property);
                // add IPropertyDef
            });

            return(elem);
        }
Пример #4
0
 public void LoadFrom(Assembly assembly, LoadSpec spec)
 {
     if (assembly == null) throw new ArgumentNullException("assembly");
     if (spec == null) throw new ArgumentNullException("spec");
     assembly.GetTypes().ToList().ForEach(type => LoadType(type, spec));
 }