private void CehckCreateObjectExpression(CreateObjectExpression e, TypeCheckingContext context) { foreach (Expression parameter in e.Parameters) { PerformTypeChecking(parameter, context); } foreach (ConstructorInfo c in e.ObjectType.GetConstructors()) { bool isValid = true; int i = 0; foreach (ParameterInfo p in c.GetParameters()) { if (!ReflectionSnippets.Accepts(p.ParameterType, e.Parameters[i].Type)) { isValid = false; break; } i++; } if (isValid) { e.Constructor = c; break; } } if (e.Constructor == null) { StringBuilder b = new StringBuilder(); foreach (Expression parameter in e.Parameters) { b.Append(parameter.Type).Append(","); } if (e.Parameters.Length > 0) { b.Remove(b.Length - 1, 1); } context.ErrorProvider.ThrowException(string.Format("{0}.ctor({1}) not found", e.ObjectType, b), e); } e.Type = e.ObjectType; }
private void CheckCreateArrayExpression(CreateArrayExpression e, TypeCheckingContext context) { foreach (Expression element in e.Elements) { PerformTypeChecking(element, context); Type type = element is CondensedArrayExpression?element.Type.GetElementType() : element.Type; if (!ReflectionSnippets.Accepts(e.ElementType, type)) { context.ErrorProvider.ThrowException(string.Format("{0} cannot be put into {1}[]", element.Type, e.ElementType), element); } } e.Type = e.ElementType.MakeArrayType(0); }
private void CheckIndexingExpression(IndexingExpression e, TypeCheckingContext context) { PerformTypeChecking(e.Operand, context); PerformTypeChecking(e.Indexer, context); if (!e.Operand.Type.IsArray) { context.ErrorProvider.ThrowException("Only array types can use [] operator.", e); } else if (!ReflectionSnippets.Accepts(typeof(int), e.Indexer.Type)) { context.ErrorProvider.ThrowException("Indexer must be convertiable to int.", e); } else { e.Type = e.Operand.Type.GetElementType(); } }