private string RenderRegistry(Registry registry)
        {
            return($@"
                <table class=""container row-seperator"">
                <thead>
                    <tr>
                        <th>Plugin Type</th>
                        <th>Plugin Assembly</th>
                        <th>Singleton</th>
                        <th>Instance</th>
                        <th>Concrete Type</th>
                        <th width=""100%"">Concrete Assembly</th>
                    </tr>
                </thead>
                <tbody>
                {registry?.OrderBy(r => r.PluginType.FullName).Select(r =>
                    {
                        var pluginType = _typeCache.GetTypeDescriptor(r.PluginType);
                        var concreteType = r.ConcreteType != null ? _typeCache.GetTypeDescriptor(r.ConcreteType) : null;

                        return $@"
                            <tr>
                                <td nowrap><code>{pluginType.FriendlyFullName}</code></td>
                                <td nowrap><code>{pluginType.Type.Assembly.GetFriendlyName().HtmlEncode()}</code></td>
                                <td>{(r.IsInstance ? "<span class=\"grey\">N/A</span>" : YesNo(r.Singleton))}</td> 
                                <td>{YesNo(r.IsInstance)}</td> 
                                <td><code>{concreteType?.FriendlyFullName}</code></td>
                                <td nowrap><code>{concreteType?.Type.Assembly.GetFriendlyName().HtmlEncode()}</code></td>
                            </tr>   
                        ";
                    }).Join()}                                                          
示例#2
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;
        }
示例#3
0
        public override string ToString()
        {
            return(_registrations.OrderBy(r => r.PluginType.FullName).Select(r =>
            {
                var pluginType = _typeCache.GetTypeDescriptor(r.PluginType);
                var concreteType = r.ConcreteType != null ?
                                   _typeCache.GetTypeDescriptor(r.ConcreteType) : null;

                return new
                {
                    PluginType = pluginType.FriendlyFullName,
                    PluginAssembly = pluginType.Type.Assembly.GetFriendlyName(),
                    r.Singleton,
                    Instance = r.Instance?.GetType().GetFriendlyTypeName(true),
                    ConcreteType = concreteType?.FriendlyFullName,
                    ConcreteAssembly = concreteType?.Type.Assembly.GetFriendlyName()
                };
            })
                   .ToTable(x => new
            {
                Plugin_Type = x.PluginType,
                Plugin_Assembly = x.PluginAssembly,
                x.Singleton,
                x.Instance,
                Concrete_Type = x.ConcreteType,
                Concrete_Assembly = x.ConcreteAssembly
            }));
        }
示例#4
0
        public static ActionMethod From(MethodInfo method, ITypeCache typeCache = null)
        {
            typeCache = typeCache ?? new TypeCache();
            var typeDescriptor = typeCache.GetTypeDescriptor(method.DeclaringType);

            return(new ActionMethod(typeDescriptor, new MethodDescriptor(
                                        typeDescriptor, method, typeCache)));
        }
示例#5
0
 public PropertyDescriptor(TypeDescriptor typeDescriptor,
                           PropertyInfo propertyInfo, ITypeCache typeCache) :
     base(propertyInfo.Name, propertyInfo.ToLazy(
              x => x.GetCustomAttributes().ToArray()))
 {
     DeclaringType = typeDescriptor;
     PropertyInfo  = propertyInfo;
     _propertyType = propertyInfo.ToLazy(x => typeCache.GetTypeDescriptor(x.PropertyType));
 }
示例#6
0
 public ParameterDescriptor(TypeDescriptor typeDescriptor,
                            MethodDescriptor methodDescriptor,
                            ParameterInfo parameterInfo, ITypeCache typeCache) :
     base(parameterInfo.Name, parameterInfo.ToLazy(
              x => x.GetCustomAttributes().ToArray()))
 {
     DeclaringType  = typeDescriptor;
     Method         = methodDescriptor;
     ParameterInfo  = parameterInfo;
     Position       = parameterInfo.Position;
     _parameterType = parameterInfo.ToLazy(
         x => typeCache.GetTypeDescriptor(x.ParameterType));
 }
示例#7
0
 public PropertyDescriptor(TypeDescriptor typeDescriptor,
                           PropertyInfo propertyInfo, ITypeCache typeCache) :
     base(propertyInfo.Name, propertyInfo.ToLazy(
              x => x.GetCustomAttributes().ToArray()))
 {
     DeclaringType     = typeDescriptor;
     PropertyInfo      = propertyInfo;
     _friendlyName     = propertyInfo.ToLazy(x => x.GetFriendlyPropertyName());
     _friendlyFullName = propertyInfo.ToLazy(x => x.GetFriendlyPropertyName(true));
     _propertyType     = propertyInfo.ToLazy(x => typeCache.GetTypeDescriptor(x.PropertyType));
     _setValue         = propertyInfo.ToLazy(x => x.CompileSetter());
     _getValue         = propertyInfo.ToLazy(x => x.CompileGetter());
 }
        public void Should_only_configure_matching_behaviors_on_action()
        {
            _configuration.Behaviors.Append <TestBehavior1>(x => x.ActionMethod
                                                            .Method.Name == nameof(Handler1.Get));

            _configuration.Behaviors.Append <TestBehavior2>();

            var actions = _actionSource.GetActions(new ActionSourceContext(_configuration, null));

            var behaviors = actions.FirstOrDefault(x => x.Action == _handler1Get).Behaviors;

            behaviors.Length.ShouldEqual(3);
            behaviors.ShouldOnlyContain(
                _typeCache.GetTypeDescriptor <DefaultErrorHandlerBehavior>(),
                _typeCache.GetTypeDescriptor <TestBehavior1>(),
                _typeCache.GetTypeDescriptor <TestBehavior2>());

            behaviors = actions.FirstOrDefault(x => x.Action == _handler1Post).Behaviors;
            behaviors.Length.ShouldEqual(2);
            behaviors.ShouldOnlyContain(
                _typeCache.GetTypeDescriptor <DefaultErrorHandlerBehavior>(),
                _typeCache.GetTypeDescriptor <TestBehavior2>());
        }
示例#9
0
 public MethodDescriptor(TypeDescriptor typeDescriptor,
                         MethodInfo methodInfo, ITypeCache typeCache) :
     base(methodInfo.Name, methodInfo.ToLazy(x => x.GetCustomAttributes().ToArray()))
 {
     MethodInfo    = methodInfo;
     _friendlyName = methodInfo.ToLazy(x => x.GetFriendlyMethodName());
     DeclaringType = typeDescriptor;
     IsBclMethod   = methodInfo.IsBclMethod();
     _parameters   = methodInfo.ToLazy(x => x.GetParameters().Select(p =>
                                                                     new ParameterDescriptor(typeDescriptor, this, p, typeCache)).ToArray());
     _hasResult  = methodInfo.ReturnType.ToLazy(x => x.UnwrapTask() != typeof(void));
     _returnType = methodInfo.ToLazy(x => x.ReturnType == typeof(void) ? null :
                                     typeCache.GetTypeDescriptor(x.ReturnType));
 }
示例#10
0
 public static TypeDescriptor GetTypeDescriptor <T>(this ITypeCache typeCache)
 {
     return(typeCache.GetTypeDescriptor(typeof(T)));
 }
 public virtual List <ActionDescriptor> GetActions(ActionSourceContext context)
 {
     return(_actionMethodSources.ThatApplyTo(context, _configuration)
            .SelectMany(x => x.GetActionMethods(context)).Distinct()
            .SelectMany(a => _routeConventions.ThatApplyTo(a, context, _configuration)
                        .SelectMany(rc => rc
                                    .GetRouteDescriptors(context, a)
                                    .Select(r => new ActionDescriptor(a, r,
                                                                      _configuration.Behaviors.ThatApplyTo(context, a, r)
                                                                      .Select(x => _typeCache.GetTypeDescriptor(x)).ToArray()))))
            .ToList());
 }