private ExpressionSyntax StructuralEquatableEqualityForCase(CaseValue caseValue) { return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ParenthesizedExpression( CastExpression( GeneratorHelpers.StructuralEquatableName, MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(caseValue.Name) ) ) ), IdentifierName("Equals") ) ) .WithArgumentList( ArgumentList( SeparatedList <ArgumentSyntax>( new SyntaxNodeOrToken[] { Argument( IdentifierName(caseValue.Name) ), Token(SyntaxKind.CommaToken), Argument(GeneratorHelpers.StructuralEqualityComparerMemberAccess) } ) ) )); }
public static bool IsStructuralEquatableType(CaseValue caseValue, SemanticModel semanticModel) { var structuralEquatableMembers = semanticModel.Compilation.GetTypeByMetadataName("System.Collections.IStructuralEquatable").GetMembers(); var type = caseValue.SymbolInfo; return(structuralEquatableMembers.Any(m => type.FindImplementationForInterfaceMember(m) != null)); }
private ExpressionSyntax EqualityForCase(CaseValue caseValue, SemanticModel semanticModel) { if (GeneratorHelpers.IsStructuralEquatableType(caseValue, semanticModel)) { return(StructuralEquatableEqualityForCase(caseValue)); } return(DefaultEqualityForCase(caseValue)); }
private static InvocationExpressionSyntax GenerateDefaultCaseValueEqual(CaseValue caseValue) { return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, QualifiedName( QualifiedName( QualifiedName( IdentifierName("System"), IdentifierName("Collections") ), IdentifierName("Generic") ), GenericName(Identifier("EqualityComparer")) .WithTypeArgumentList( TypeArgumentList( SingletonSeparatedList <TypeSyntax>(caseValue.Type) ) ) ), IdentifierName("Default") ), IdentifierName("Equals") ) ).WithArgumentList( ArgumentList( SeparatedList <ArgumentSyntax>( new SyntaxNodeOrToken[] { Argument( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(caseValue.Name) ) ), Token(SyntaxKind.CommaToken), Argument( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("value"), IdentifierName(caseValue.Name) ) ) } ) ) )); }
private static ExpressionSyntax WrapEqualityWithNullGuard(CaseValue caseValue, ExpressionSyntax expressionSyntax) { if (caseValue.SymbolInfo.IsValueType) { return(expressionSyntax); } var leftSyntax = MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(caseValue.Name) ); var rightSyntax = MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("value"), IdentifierName(caseValue.Name) ); return(BinaryExpression( SyntaxKind.LogicalOrExpression, BinaryExpression( SyntaxKind.LogicalAndExpression, BinaryExpression( SyntaxKind.EqualsExpression, leftSyntax, LiteralExpression( SyntaxKind.NullLiteralExpression ) ), BinaryExpression( SyntaxKind.EqualsExpression, rightSyntax, LiteralExpression( SyntaxKind.NullLiteralExpression ) ) ), BinaryExpression( SyntaxKind.LogicalAndExpression, BinaryExpression( SyntaxKind.NotEqualsExpression, leftSyntax, LiteralExpression( SyntaxKind.NullLiteralExpression ) ), expressionSyntax ) )); }
public override int GetHashCode() { unchecked { int hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (ControlAnnotation != null ? ControlAnnotation.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ControlValue != null ? ControlValue.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (CaseValue != null ? CaseValue.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (IdentityAnnotation != null ? IdentityAnnotation.GetHashCode() : 0); hashCode = (hashCode * 397) ^ AverageTechnicalReplicates.GetHashCode(); hashCode = (hashCode * 397) ^ SumTransitions.GetHashCode(); hashCode = (hashCode * 397) ^ NormalizationMethod.GetHashCode(); hashCode = (hashCode * 397) ^ IncludeInteractionTransitions.GetHashCode(); hashCode = (hashCode * 397) ^ SummarizationMethod.GetHashCode(); hashCode = (hashCode * 397) ^ ConfidenceLevel.GetHashCode(); hashCode = (hashCode * 397) ^ PerProtein.GetHashCode(); return(hashCode); } }
private static StatementSyntax GenerateReferenceTypeToStringStatement(CaseValue c) { var variableName = c.Name.Text + "String"; return(LocalDeclarationStatement( VariableDeclaration( IdentifierName("var") ) .WithVariables( SingletonSeparatedList <VariableDeclaratorSyntax>( VariableDeclarator( Identifier(variableName) ) .WithInitializer( EqualsValueClause( ConditionalExpression( BinaryExpression( SyntaxKind.EqualsExpression, IdentifierName(c.Name), LiteralExpression( SyntaxKind.NullLiteralExpression ) ), LiteralExpression( SyntaxKind.StringLiteralExpression, Literal("null") ), InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(c.Name), IdentifierName("ToString") ) ) ) ) ) ) ) )); }
public override int GetHashCode() { unchecked { int hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (ControlAnnotation != null ? ControlAnnotation.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ControlValue != null ? ControlValue.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (CaseValue != null ? CaseValue.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (IdentityAnnotation != null ? IdentityAnnotation.GetHashCode() : 0); hashCode = (hashCode * 397) ^ AverageTechnicalReplicates.GetHashCode(); hashCode = (hashCode * 397) ^ (NormalizationMethod != null ? NormalizationMethod.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IncludeInteractionTransitions.GetHashCode(); hashCode = (hashCode * 397) ^ (SummarizationMethod != null ? SummarizationMethod.GetHashCode() : 0); hashCode = (hashCode * 397) ^ ConfidenceLevelTimes100.GetHashCode(); hashCode = (hashCode * 397) ^ PerProtein.GetHashCode(); hashCode = (hashCode * 397) ^ UseZeroForMissingPeaks.GetHashCode(); hashCode = (hashCode * 397) ^ QValueCutoff.GetHashCode(); hashCode = (hashCode * 397) ^ (ColorRows != null ? ColorRows.GetHashCode() : 0); return(hashCode); } }
protected ExpressionSyntax HashCodeForCaseValue(CaseValue caseValue, SemanticModel semanticModel) { if (GeneratorHelpers.IsStructuralEquatableType(caseValue, semanticModel)) { return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ParenthesizedExpression( CastExpression( GeneratorHelpers.StructuralEquatableName, IdentifierName(caseValue.Name) ) ), IdentifierName("GetHashCode") ) ) .WithArgumentList( ArgumentList( SingletonSeparatedList <ArgumentSyntax>( Argument(GeneratorHelpers.StructuralEqualityComparerMemberAccess) ) ) )); } if (caseValue.SymbolInfo.IsValueType) { return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(caseValue.Name), IdentifierName("GetHashCode") ) )); } return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, ParenthesizedExpression( ConditionalAccessExpression( IdentifierName(caseValue.Name), InvocationExpression( MemberBindingExpression(IdentifierName("GetHashCode")) ) ) ), IdentifierName("GetValueOrDefault") ) ) .WithArgumentList( ArgumentList( SingletonSeparatedList( Argument( PrefixUnaryExpression( SyntaxKind.UnaryMinusExpression, LiteralExpression( SyntaxKind.NumericLiteralExpression, Literal(1) ) ) ) ) ) )); }
public String Parse(String code, ConfigurationDetail configurationDetail, bool isExecute) { level++; outputText += SpaceLevel() + "Parsing Code " + code + "<br/>"; // Check stack // Loop round, finding the placeholders String resultingCode = ""; String originalCode = code; while (code.IndexOf("${") >= 0) { if (code.IndexOf("${") > 0) { resultingCode += code.Substring(0, code.IndexOf("${")); } code = code.Substring(code.IndexOf("${") + 2); int endPos = code.IndexOf("}"); if (code.IndexOf("${") >= 0 && code.IndexOf("${") < endPos) { throw new Exception("Unterminated placeholder seen " + originalCode); } String placeHolder = code.Substring(0, endPos); code = code.Substring(endPos + 1); String name = placeHolder.Substring(2); switch (placeHolder.Substring(0, 1)) { case "d": if (!constants.Exists(x => x.Name.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Constant " + name + " cannot be found"); } resultingCode += ProcessType(constants.Find(x => x.Name.ToUpper().Equals(name.ToUpper())).Value, constants.Find(x => x.Name.ToUpper().Equals(name.ToUpper())).ValueType); break; case "e": if (!expressions.Exists(x => x.Name.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Expression " + name + " cannot be found"); } Expression expression = expressions.Find(x => x.Name.ToUpper().Equals(name.ToUpper())); if (!expression.IsProcessed) { outputText += SpaceLevel() + "Evaluating Expression " + name + "<br/>"; CheckStack(name, ActionType.ExpressionAction); expression.Value = ProcessType(Parse(expression.Code, configurationDetail, true), expression.ValueType); RemoveStack(name, ActionType.ExpressionAction); // Execute code expression.IsProcessed = true; outputText += SpaceLevel() + "Expression Evaluated as " + expression.Value + "<br/>"; } else { outputText += SpaceLevel() + "Using Expression " + name + " " + expression.Value + "<br/>"; } resultingCode += expression.Value; break; case "q": if (!conditions.Exists(x => x.Name.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Condition " + name + " cannot be found"); } Condition condition = conditions.Find(x => x.Name.ToUpper().Equals(name.ToUpper())); if (!condition.IsProcessed) { outputText += SpaceLevel() + "Evaluating Condition " + name + "<br/>"; CheckStack(name, ActionType.ConditionAction); condition.Value = Parse(condition.Question, configurationDetail, true) == "1" ? true : false; RemoveStack(name, ActionType.ConditionAction); condition.IsProcessed = true; } else { outputText += SpaceLevel() + "Using Condition " + name + " " + condition.Value + "<br/>"; } if (condition.Value) { resultingCode += Process(condition.TrueActionName, condition.TrueActionType, configurationDetail); } else { resultingCode += Process(condition.FalseActionName, condition.FalseActionType, configurationDetail); } break; case "c": if (!cases.Exists(x => x.Name.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Case " + name + " cannot be found"); } Case theCase = cases.Find(x => x.Name.ToUpper().Equals(name.ToUpper())); if (!theCase.IsProcessed) { outputText += SpaceLevel() + "Evaluating Case " + name + "/" + theCase.ExpressionName + "<br/>"; String parameterValue = Parse("${p:" + theCase.ExpressionName + "}", configurationDetail, false); CaseValue caseValue = null; if (caseValues.Exists(x => x.CaseName.ToUpper().Equals(theCase.Name.ToUpper()) && (x.Value != null && x.Value.ToUpper().Equals(parameterValue.ToUpper())))) { caseValue = caseValues.Find(x => x.CaseName.ToUpper().Equals(theCase.Name.ToUpper()) && x.Value.ToUpper().Equals(parameterValue.ToUpper())); } else { if (caseValues.Exists(x => x.CaseName.ToUpper().Equals(theCase.Name.ToUpper()) && (x.Value == null || x.Value == ""))) { caseValue = caseValues.Find(x => x.CaseName.ToUpper().Equals(theCase.Name.ToUpper()) && (x.Value == null || x.Value == "")); } else { throw new Exception("NO Case value or null entry " + parameterValue + " for case " + name); } } theCase.Value = Process(caseValue.ActionName, caseValue.ActionType, configurationDetail); // Execute question theCase.IsProcessed = true; } else { outputText += SpaceLevel() + "Using Case " + name + " " + theCase.Value + "<br/>"; } resultingCode += theCase.Value; break; case "o": if (!configurationDetail.ConfigurationTypeOutputs.Exists(x => x.Name.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Output " + name + " cannot be found"); } ConfigurationTypeOutput output = configurationDetail.ConfigurationTypeOutputs.Find(x => x.Name.ToUpper().Equals(name.ToUpper())); if (!output.IsProcessed) { outputText += SpaceLevel() + "Evaluating Output " + name + "<br/>"; output.Value = Process(output.Action, output.ActionType, configurationDetail); output.IsProcessed = true; outputText += SpaceLevel() + "Output Evaluated as " + output.Value + "<br/>"; } else { outputText += SpaceLevel() + "Using Output " + name + " " + output.Value + "<br/>"; } resultingCode += output.Value; break; case "p": if (!configurationDetail.ConfigurationParameterValues.Exists(x => x.ParameterName.ToUpper().Equals(name.ToUpper()))) { throw new Exception("Parameter " + name + " cannot be found"); } String value = configurationDetail.ConfigurationParameterValues.Find(x => x.ParameterName.ToUpper().Equals(name.ToUpper())).Value; outputText += SpaceLevel() + "Using Parameter " + name + " " + value + "<br/>"; resultingCode += value; break; } } resultingCode += code; if (isExecute) { outputText += SpaceLevel() + "Executing " + resultingCode + "<br/>"; MethodInfo function = CreateFunction(resultingCode); var executeFunction = (Func <double>)Delegate.CreateDelegate(typeof(Func <double>), function); var result = executeFunction(); outputText += SpaceLevel() + "Result " + result.ToString() + "<br/>"; if (level <= 4) { if (level == 1) { outputText += "<b style='color:red'>OUTPUT" + originalCode + " = " + result.ToString() + "</b><br />"; } else if (level == 2) { outputText += "<b style='color:blue'>" + SpaceLevel() + originalCode + " = " + result.ToString() + "</b><br />"; } else if (level == 3) { outputText += "<b style='color:green'>" + SpaceLevel() + originalCode + " = " + result.ToString() + "</b><br />"; } else if (level == 4) { outputText += "<b style='color:purple'>" + SpaceLevel() + originalCode + " = " + result.ToString() + "</b><br />"; } } else { outputText += SpaceLevel() + originalCode + " = " + result.ToString() + "<br/>"; } level--; return(result.ToString()); } else { if (level <= 4) { if (level == 1) { outputText += "<b style='color:red'>RETURNING OUTPUT" + originalCode + " = " + resultingCode + "</b><br />"; } else if (level == 2) { outputText += "<b style='color:blue'>RETURNING OUTPUT" + SpaceLevel() + originalCode + " = " + resultingCode + "</b><br />"; } else if (level == 3) { outputText += "<b style='color:green'>RETURNING OUTPUT" + SpaceLevel() + originalCode + " = " + resultingCode + "</b><br />"; } else if (level == 4) { outputText += "<b style='color:purple'>RETURNING OUTPUT" + SpaceLevel() + originalCode + " = " + resultingCode + "</b><br />"; } } else { outputText += SpaceLevel() + "Returning " + originalCode + " = " + resultingCode + "<br/>"; } level--; return(resultingCode); } }
private static bool CanHaveNullGuard(CaseValue c) { return(c.SymbolInfo.IsReferenceType || c.SymbolInfo.TypeKind == TypeKind.TypeParameter && !c.SymbolInfo.IsValueType); }