internal static bool TryCreate_Generic(ParameterExpression variableExpression, [NotNullWhen(true)] out ExpressionExtensionData <TData>?expressionData, [NotNullWhen(true)] out Expression?newExpression, Type[] typeArguments, params Expression[] constructorArguments) { newExpression = default; expressionData = default; var constructorArgumentTypes = constructorArguments.Select(arg => arg.Type).ToArray(); if (MethodLookups.TryGet_Constructor_GenericType(out var constructorInfo, typeof(TData), typeArguments, constructorArgumentTypes) == false) { return(false); } newExpression = Expression.New(constructorInfo, constructorArguments); if (variableExpression.Type != newExpression.Type) { throw new NotImplementedException(); } if (variableExpression.Type != typeof(TData)) { throw new NotImplementedException(); } expressionData = new ExpressionExtensionData <TData>(variableExpression); return(true); }
internal static bool TryCreate(ParameterExpression variableExpression, [NotNullWhen(true)] out ExpressionExtensionData <TData>?expressionData, [NotNullWhen(true)] out Expression?newExpression, params Expression[] constructorArguments) { return(TryCreate_Generic(variableExpression, out expressionData, out newExpression, Type.EmptyTypes, constructorArguments)); }
internal static bool TryCreate(ParameterExpression expression, [NotNullWhen(true)] out ExpressionExtensionData <TData>?expressionData) { expressionData = default; if (expression.Type == typeof(TData)) { expressionData = new ExpressionExtensionData <TData>(expression); } return(expressionData != null); }