private static void CalculateSimpleAverage(RewriteDesign design, TypedValueBridge selectionValue, LocalVariable sumVariable) { if (!AssertResultSizeGreaterEqual(design, 1)) { return; } design.ForAdd(sumVariable.AddAssign(selectionValue)); design.ResultAdd(Return(sumVariable / design.GetResultSize())); }
public static LocalVariable TryGetVariable(RewriteDesign design, TypedValueBridge value) { if (value?.Value?.Value == null) { return(null); } var expression = value.Expression; while (expression is ParenthesizedExpressionSyntax parenthesizedExpressionSyntax) { expression = parenthesizedExpressionSyntax.Expression; } return(design.Variables.FirstOrDefault(x => x.Name == expression.ToString())); }
private static void CalculateNullableAverage(RewriteDesign design, TypeBridge elementType, TypedValueBridge selectionValue, LocalVariable sumVariable) { var inlinedValue = selectionValue.Reusable(design); design.ForAdd(If(inlinedValue.IsEqual(null), Continue())); design.ForAdd(sumVariable.AddAssign(inlinedValue.Cast(elementType))); design.Indexer = null; if (design.Unchecked) { design.ResultAdd(sumVariable.Cast(design.ReturnType.Type) / design.Indexer); } else { design.ResultAdd(Return(SyntaxFactory.ConditionalExpression(design.Indexer.IsEqual(0), Null, sumVariable.Cast(design.ReturnType.Type) / design.Indexer))); } }
public static ValueBridge Is(this TypedValueBridge a, TypeBridge type) => BinaryExpression(SyntaxKind.IsExpression, a, type);
public static LocalVariable CreateLocalVariable(RewriteDesign design, TypedValueBridge value) => CreateLocalVariable(design, value.Type, value);