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()}
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; }
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 })); }
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))); }
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)); }
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)); }
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>()); }
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)); }
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()); }