Beispiel #1
0
        private TypeDescriptor(Type type, Type originalType, ITypeCache typeCache)
            : base(type.Name, type.ToLazy(x => x.GetCustomAttributes().ToArray()))
        {
            Type = type;
            AssemblyDescriptor = typeCache.GetAssemblyDescriptor(type.Assembly);
            IsBclType = type.IsBclType();
            _isSimpleType = type.ToLazy(x => x.IsSimpleType());
            _friendlyName = type.ToLazy(x => x.GetFriendlyTypeName());
            _friendlyFullName = type.ToLazy(x => x.GetFriendlyTypeName(true));
            _baseName = type.ToLazy(x => x.GetNonGenericName());
            _tryCreate = type.ToLazy(x => x.CompileTryCreate());
            _hasDefaultConstructor = type.ToLazy(x => x.GetConstructor(Type.EmptyTypes) != null);

            _methods = type.ToLazy(x => x.GetMethods().Select(y =>
                new MethodDescriptor(this, y, typeCache)).ToArray());
            _properties = type.ToLazy(x => x.GetProperties().Select(y =>
                new PropertyDescriptor(this, y, typeCache)).ToArray());

            _isNullable = type.ToLazy(x => x.IsNullable());
            _underlyingNullableType = type.ToLazy(x => typeCache
                .GetTypeDescriptor(x.GetUnderlyingNullableType()));

            _arrayElementType = type.ToLazy(x => typeCache
                .GetTypeDescriptor(x.TryGetArrayElementType()));
            _genericListCastableType = type.ToLazy(x => typeCache
                .GetTypeDescriptor(x.TryGetGenericListCastableElementType()));

            IsTask = originalType.IsTask();
            IsTaskWithResult = !IsTask && type != originalType;
        }
Beispiel #2
0
 public virtual IEnumerable <ActionMethod> GetActionMethods()
 {
     return(_configuration.Assemblies
            .SelectMany(x => _typeCache.GetAssemblyDescriptor(x).Types)
            .Where(x =>
                   (_configuration.HandlerNameConvention ??
                    DefaultHandlerNameConvention).IsMatch(x.Name) &&
                   (_configuration.HandlerFilter?.Invoke(_configuration, x) ?? true))
            .SelectMany(t => t.Methods
                        .Where(m => !m.MethodInfo.IsGenericMethodDefinition && !m.IsBclMethod &&
                               (_configuration.ActionNameConvention ?? DefaultActionNameConvention)
                                   (_configuration).IsMatch(m.Name) &&
                               (_configuration.ActionFilter?.Invoke(_configuration, m) ?? true))
                        .Select(m => new ActionMethod(t, m))));
 }