/// <summary> /// Gets associate instance for specified parameter and result types. /// All associate instances are cached and returned on the same calls further. /// </summary> /// <typeparam name="TKey">Type to provide the associate for.</typeparam> /// <typeparam name="TAssociate">Type of result to provide the associate for.</typeparam> /// <typeparam name="TResult">The type of result.</typeparam> /// <returns>Associate instance, if found; /// otherwise, <see langword="null"/>.</returns> protected TResult GetAssociate <TKey, TAssociate, TResult>() where TAssociate : class { var key = new TypePair(typeof(TKey), typeof(TResult)); return((TResult)cache.GetValue(key, _key => { Type foundFor; return ConvertAssociate <TKey, TAssociate, TResult>(CreateAssociate <TKey, TAssociate>(out foundFor)); })); }
public Pair <Delegate, object[]> Compile(LambdaExpression lambda) { var constantExtractor = new ConstantExtractor(lambda); var tree = constantExtractor.Process().ToExpressionTree(); var constants = constantExtractor.GetConstants(); var compiled = cache.GetValue(tree, _tree => ((LambdaExpression)_tree.ToExpression()).Compile()); // var compiled = ((LambdaExpression) tree.ToExpression()).Compile(); return(new Pair <Delegate, object[]>(compiled, constants)); }
private IServiceContainer GetContainer(Type serviceType) { var assembly = serviceType.Assembly; return(containers.GetValue(assembly, _assembly => { var typeRegistry = new TypeRegistry(new ServiceTypeRegistrationProcessor()); typeRegistry.Register(_assembly); return new ServiceContainer(typeRegistry.SelectMany(type => ServiceRegistration.CreateAll(type, true))); })); }
/// <inheritdoc/> public IInstanceGeneratorBase GetInstanceGenerator(Type type) { return(generators.GetValue(type, (_type, _this) => _this .GetType() .GetMethod("GetInstanceGenerator", ArrayUtils <Type> .EmptyArray) .GetGenericMethodDefinition() .MakeGenericMethod(new[] { _type }) .Invoke(_this, null) as IInstanceGeneratorBase, this)); }
/// <summary> /// Gets the sequence of type itself, all its base types and interfaces. /// Types will be ordered from the very base ones to ancestors with the specified type in the end of sequence. /// </summary> /// <param name="type">The type to get compatible types for.</param> /// <returns>The interfaces of the specified type.</returns> public static Type[] GetCompatibles(this Type type) { return orderedCompatibles.GetValue(type, _type => { var interfaces = _type.GetInterfaces(); var bases = EnumerableUtils.Unfold(_type.BaseType, t => t.BaseType); return bases .Concat(interfaces) .OrderByInheritance() .AddOne(_type) .ToArray(); }); }
public override int Compare(Type x, Type y) { if (x == y) { return(0); } return(results.GetValue(new Pair <Type>(x, y), (pair, _this) => { int result = _this.BaseComparer1.Compare(pair.First.FullName, pair.Second.FullName); if (result == 0) { result = _this.BaseComparer2.Compare(pair.First.Assembly, pair.Second.Assembly); } return result; }, this)); }
private Type GenerateAuxiliaryType(AssociationInfo association) { var masterType = association.OwnerType.UnderlyingType; var slaveType = association.TargetType.UnderlyingType; var baseType = WellKnownOrmTypes.EntitySetItemOfT1T2.MakeGenericType(masterType, slaveType); var typeName = string.Format(GeneratedTypeNameFormat, masterType.Namespace, context.NameBuilder.BuildAssociationName(association)); var result = GeneratedTypes.GetValue(typeName, (_typeName, _baseType) => TypeHelper.CreateInheritedDummyType(_typeName, _baseType, true), baseType); return(result); }
public LambdaExpression CreateLambda(Type delegateType, Expression body, ParameterExpression[] parameters) { var factory = cache.GetValue(delegateType, (_delegateType, _this) => _this.CreateFactory(_delegateType), this); return(factory.Invoke(body, parameters)); }
/// <summary> /// Creates a new instance of <see cref="IArithmetic{T}"/> /// with specified arithmetic rules applied. /// </summary> /// <param name="rules">Rules to apply (relatively to <see cref="ArithmeticRules"/> of this arithmetic).</param> /// <returns>New instance of <see cref="IArithmetic{T}"/>.</returns> public Arithmetic <T> ApplyRules(ArithmeticRules rules) { return(cachedArithmetics.GetValue(rules, (_rules, _this) => new Arithmetic <T>(_this.CreateNew(_rules)), this)); }
/// <inheritdoc/> public AdvancedComparer <T> ApplyRules(ComparisonRules rules) { return(cachedComparers.GetValue(rules, (_rules, _this) => new AdvancedComparer <T>(_this.CreateNew(_rules)), this)); }
public override int Compare(Type x, Type y) { return(x == y ? 0 : results.GetValue(new Pair <Type>(x, y), generator, this));
public LambdaExpression CreateLambda(Type delegateType, Expression body, ParameterExpression[] parameters) { var factory = cache.GetValue(delegateType, createHandler); return(factory.Invoke(body, parameters)); }
/// <summary> /// Gets the interfaces of the specified type. /// Interfaces will be ordered from the very base ones to ancestors. /// </summary> /// <param name="type">The type to get the interfaces of.</param> public static Type[] GetInterfaces(this Type type) { return orderedInterfaces.GetValue(type, _type => _type.GetInterfaces().OrderByInheritance().ToArray()); }
/// <summary> /// Fast analogue of <see cref="Type.GetInterfaceMap"/>. /// </summary> /// <param name="type">The type.</param> /// <param name="targetInterface">The target interface.</param> /// <returns>Interface map for the specified interface.</returns> public static InterfaceMapping GetInterfaceMapFast(this Type type, Type targetInterface) { return interfaceMaps.GetValue(new Pair<Type, Type>(type, targetInterface), pair => new InterfaceMapping(pair.First.GetInterfaceMap(pair.Second))); }