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 GenericConstructedType( classType, genericArgs.Select(a => a.Entity).Cast <IType>().ToArray()); constructor = classType.GetConstructors().First(); var result = new MethodInvocationExpression { Target = CreateReference(constructor.DeclaringType) }; result.Target.Entity = constructor; result.ExpressionType = constructor.DeclaringType; return(result); }
IType GetEnumeratorItemTypeFromAttribute(IType iteratorType) { // If iterator type is external get its attributes via reflection if (iteratorType is ExternalType) { return(GetExternalEnumeratorItemType(iteratorType)); } // If iterator type is a generic constructed type, map its attribute from its definition GenericConstructedType constructedType = iteratorType as GenericConstructedType; if (constructedType != null) { return(constructedType.GenericMapping.Map( GetEnumeratorItemTypeFromAttribute(constructedType.GenericDefinition))); } // If iterator type is internal get its attributes from its type definition AbstractInternalType internalType = (AbstractInternalType)iteratorType; IType enumeratorItemTypeAttribute = Map(typeof(EnumeratorItemTypeAttribute)); foreach (Attribute attribute in internalType.TypeDefinition.Attributes) { IConstructor constructor = GetEntity(attribute) as IConstructor; if (null != constructor) { if (constructor.DeclaringType == enumeratorItemTypeAttribute) { return(GetType(attribute.Arguments[0])); } } } return(null); }