Beispiel #1
0
        public MethodInvocationExpression CreateGenericConstructorInvocation(IType classType,
                                                                             IEnumerable <TypeReference> genericArgs)
        {
            var          gpp = classType as IGenericParametersProvider;
            IConstructor constructor;

            if (gpp == null || !genericArgs.Any())
            {
                constructor = classType.GetConstructors().First();
                return(CreateConstructorInvocation(constructor));
            }

            classType = new Generics.GenericConstructedType(
                classType,
                genericArgs.Select(a => a.Entity).Cast <IType>().ToArray());
            constructor = classType.GetConstructors().First();

            var result = new MethodInvocationExpression();

            result.Target         = CreateGenericReference(CreateReference(constructor.DeclaringType), genericArgs);
            result.Target.Entity  = constructor;
            result.ExpressionType = constructor.DeclaringType;

            return(result);
        }
Beispiel #2
0
        protected GenericMappedType(IType sourceType, GenericConstructedType containingType)
        {
            if (sourceType.DeclaringEntity != ((IConstructedTypeInfo)containingType).GenericDefinition)
            {
                throw new ArgumentException("Mapping type onto invalid container");
            }

            _sourceType     = sourceType;
            _containingType = containingType;
        }
Beispiel #3
0
        public static GenericMappedType Create(IType sourceType, GenericConstructedType containingType)
        {
            var pair = new KeyValuePair <IType, GenericConstructedType>(sourceType, containingType);
            GenericMappedType result;

            if (!_cache.TryGetValue(pair, out result))
            {
                result       = new GenericMappedType(sourceType, containingType);
                _cache[pair] = result;
            }
            return(result);
        }