public MemberDeclarationSyntax createGetMethod(Type t, PropertyInfo[] pi) { var method = MethodDeclaration(ParseTypeName("Task"), $"Get{t.Name}AsyncTest") .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.AsyncKeyword)) .AddAttributeLists( AttributeList() .AddAttributes( getTestAttribute() ) ); foreach (var p in pi) { if (!p.ShouldIgnore()) { var ts = p.GetTypeSyntax(); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration($"_{p.Name}", EqualsValueClause(Extensions.GetDefaultValue(ts)), ts.ToString() ))); } } var stub = Identifier("stub"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration(stub.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName($"StubI{t.Name}")) .AddArgumentListArguments() ) )).WithLeadingTrivia(Comment("// Setup Stub")) ); foreach (var p in pi) { if (!p.ShouldIgnore()) { method = method.AddBodyStatements( ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(stub), IdentifierName($"{p.Name}_Get"))) .AddArgumentListArguments( Argument(ParenthesizedLambdaExpression(IdentifierName($"_{p.Name}"))) ) ), ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(stub), IdentifierName($"{p.Name}_Set")) ).AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName($"_{p.Name}"), IdentifierName("v")) ) .AddParameterListParameters( Parameter(Identifier("v")) ) ) ) ) ); } } var create = Identifier("create"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration(create.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName("StubICreateHelper")) .AddArgumentListArguments() ) ) ).WithLeadingTrivia(Comment("// create helper")), ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(create), IdentifierName($"Create{t.Name}")) ) .AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( IdentifierName(stub) ) ) ) ) ); var settings = Identifier("settings"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration(settings.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName("StubIServerSettings")) .AddArgumentListArguments() ) ) ).WithLeadingTrivia(Comment("// settings ")), ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(settings), IdentifierName("ServerUri_Get")) ) .AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( LiteralExpression(SyntaxKind.NullLiteralExpression) ) ) ) ) ); var httpClient = Identifier("httpClient"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration(httpClient.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName("StubIHttpClient")) .AddArgumentListArguments() ) ) ).WithLeadingTrivia(Comment("// Http Client")) ); var k = pi.GetKeyProperty(); var keySy = ParseTypeName(k.PropertyType.Name); Random rand = new Random(); var serverContext = Identifier("serverContext"); var results = Identifier("results"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration(serverContext.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName("ServerContext")) .AddArgumentListArguments( Argument(IdentifierName(settings)), Argument(IdentifierName(create)), Argument(IdentifierName(httpClient)) ) ) ) ).WithLeadingTrivia(Comment("// Server ")), LocalDeclarationStatement( Extensions.VariableDeclaration(key.Text, EqualsValueClause(keySy.GetRandomValue(rand)) , keySy.GetTypeString() ) ), LocalDeclarationStatement( Extensions.VariableDeclaration( results.Text, EqualsValueClause( AwaitExpression( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ) .AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ) ).WithLeadingTrivia(Comment("// leading")) ); method = method.AddBodyStatements( getStandardTests(t, results, "ServerUriNotSet", keySy.GetDefaultValue()) ); method = method.AddBodyStatements( ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(settings), IdentifierName("ServerUri_Get") ) ) .AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( ObjectCreationExpression(ParseTypeName("Uri")) .AddArgumentListArguments( Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("http://test"))) ) ) ) ) ).WithLeadingTrivia(Comment("// login exception")), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("PostAsync") ) ).AddArgumentListArguments( generateRunTaskWrapper(Block( ReturnStatement( ObjectCreationExpression(ParseTypeName("HttpClientResult")) .WithInitializer( InitializerExpression(SyntaxKind.ObjectInitializerExpression) .AddExpressions( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("StatusCode"), Extensions.MemberAccess( IdentifierName("HttpStatusCode"), IdentifierName("Ok") ) ), AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("Content"), LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("")) ) ) ) )), Parameter(Identifier("uri")), Parameter(Identifier("d")) ) ) ), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetCookieValue") ) ).AddArgumentListArguments( Argument( ParenthesizedLambdaExpression(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("Value"))) .AddParameterListParameters( Parameter(Identifier("u")), Parameter(Identifier("name")) ) ) ) ), ExpressionStatement( AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName("LoginAsync") ) ).AddArgumentListArguments( Argument("user".ToLiteral()), Argument("pass".ToLiteral()) ) ) ), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(settings), IdentifierName("ServerUri_Get") ) ).AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( ObjectCreationExpression(ParseTypeName("Uri")) .AddArgumentListArguments( Argument( "/cheese".ToLiteral() ), Argument( Extensions.MemberAccess( IdentifierName("UriKind"), IdentifierName("Relative") ) ) ) ) ) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ).AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ).WithLeadingTrivia(Comment("// invalid uri")) ) ); method = method.AddBodyStatements( getStandardTests(t, results, "ServerUriIsNotValid", keySy.GetDefaultValue()) ); var methodHit = Identifier("methodHit"); var expectedException = Identifier("expectedException"); var uri = Identifier("uri"); method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(key), keySy.GetRandomValue(rand) ) ).WithLeadingTrivia(Comment("// Unable to connect to server")), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(settings), IdentifierName("ServerUri_Get") ) ).AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( ObjectCreationExpression( ParseTypeName("Uri") ).AddArgumentListArguments( Argument( "http://test".ToLiteral() ) ) ) ) ) ), LocalDeclarationStatement( Extensions.VariableDeclaration(expectedException.Text, EqualsValueClause(LiteralExpression(SyntaxKind.NullLiteralExpression)), "Exception" ) ), LocalDeclarationStatement( Extensions.VariableDeclaration(methodHit.Text, EqualsValueClause(LiteralExpression(SyntaxKind.FalseLiteralExpression)), "bool" ) ), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetAsync") ) ).AddArgumentListArguments( generateRunTaskWrapper( Block( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.TrueLiteralExpression) ) ), assertStatment( ObjectCreationExpression( IdentifierName("Uri") ).AddArgumentListArguments( Argument( //$"http://test/api/{t.Name}/{{key}}".ToLiteral() $"http://test/api/{t.Name}/".ToInterpolatedString(key.ToStringToken()) ) ), IdentifierName(uri) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(expectedException), ObjectCreationExpression(ParseTypeName("COMException")) .AddArgumentListArguments( Argument("Message1".ToLiteral()), Argument((-2147012867).ToLiteral()) ) ) ), ThrowStatement(IdentifierName(expectedException)), ReturnStatement( ObjectCreationExpression(ParseTypeName("HttpClientResult")) .AddArgumentListArguments() ) ), Parameter(uri) ) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ).AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ), assertIsTrue(IdentifierName(methodHit), "Method not called") ); method = method.AddBodyStatements( getStandardTests(t, results, "UnableToConnectToServer", IdentifierName(key))); method = method.AddBodyStatements( assertStatment(IdentifierName(expectedException), Extensions.MemberAccess(IdentifierName(results), IdentifierName("Exception")) )); if (String.Compare(variables.GetValue("IsUWP"), "1", true) == 0) { method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.FalseLiteralExpression) ) ).WithLeadingTrivia(Comment("// COMException ")), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetAsync") ) ).AddArgumentListArguments( generateRunTaskWrapper( Block( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.TrueLiteralExpression) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(expectedException), ObjectCreationExpression(ParseTypeName("COMException")) .AddArgumentListArguments( Argument("Message2".ToLiteral()) ) ) ), ThrowStatement( IdentifierName(expectedException) ), ReturnStatement( ObjectCreationExpression(ParseTypeName("HttpClientResult")) .AddArgumentListArguments() ) ), Parameter(uri) ) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ).AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ), assertIsTrue(IdentifierName(methodHit), "Method not called") ); method = method.AddBodyStatements( getStandardTests(t, results, "Exception", key) ); method = method.AddBodyStatements( assertStatment(IdentifierName(expectedException), Extensions.MemberAccess( IdentifierName(results), IdentifierName("Exception") ) ) ); } method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.FalseLiteralExpression) ) ).WithLeadingTrivia(Comment("// Exception ")), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetAsync") ) ).AddArgumentListArguments( generateRunTaskWrapper( Block( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.TrueLiteralExpression) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(expectedException), ObjectCreationExpression(ParseTypeName("Exception")) .AddArgumentListArguments( Argument("Message3".ToLiteral()) ) ) ), ThrowStatement( IdentifierName(expectedException) ), ReturnStatement( ObjectCreationExpression(ParseTypeName("HttpClientResult")) .AddArgumentListArguments() ) ), Parameter(uri) ) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ).AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ), assertIsTrue(IdentifierName(methodHit), "Method not called") ); method = method.AddBodyStatements( getStandardTests(t, results, "Exception", key) ); method = method.AddBodyStatements( assertStatment(IdentifierName(expectedException), Extensions.MemberAccess( IdentifierName(results), IdentifierName("Exception") ) ) ); method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.FalseLiteralExpression) ) ).WithLeadingTrivia(Comment("// Unauthorized ")), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetAsync") ) ).AddArgumentListArguments( generateRunTaskWrapper( Block( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), LiteralExpression(SyntaxKind.TrueLiteralExpression) ) ), ReturnStatement( ObjectCreationExpression(ParseTypeName("HttpClientResult")) .AddArgumentListArguments() .WithInitializer( InitializerExpression(SyntaxKind.ObjectInitializerExpression) .AddExpressions( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("StatusCode"), Extensions.MemberAccess( IdentifierName("HttpStatusCode"), IdentifierName("Unauthorized") ) ), AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("Content"), "{Test: 'cheese'".ToLiteral() ) ) ) ) ), Parameter(uri) ) ) ), ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ).AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ), assertIsTrue(IdentifierName(methodHit), "Method not called") ); method = method.AddBodyStatements( getStandardTests(t, results, "Error", key) ); method = method.AddBodyStatements( ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName("Assert"), IdentifierName("IsInstanceOfType") ) ) .AddArgumentListArguments( Argument( Extensions.MemberAccess( IdentifierName(results), IdentifierName("Exception") ) ), Argument( TypeOfExpression( ParseTypeName("JsonReaderException") ) ) ) ) ); var exp = Identifier("exp"); var expected = Identifier("expected"); method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration( exp.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName($"StubI{t.Name}")) .AddArgumentListArguments() ) ) ).WithLeadingTrivia(Comment("// Success Test")) ); var jobj = Identifier("jobj"); var blocks = Block(); blocks = blocks.AddStatements( LocalDeclarationStatement( Extensions.VariableDeclaration( jobj.Text, EqualsValueClause( ObjectCreationExpression(ParseTypeName("JObject")) .AddArgumentListArguments() ) ) ) ); foreach (var prop in pi) { if (!prop.ShouldIgnore()) { method = method.AddBodyStatements( ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(exp), IdentifierName($"{prop.Name}_Get") ) ) .AddArgumentListArguments( Argument( ParenthesizedLambdaExpression( (prop.IsKey()) ? IdentifierName(key) : prop.GetTypeSyntax().GetRandomValue(rand) ) ) ) ) ); //jobj.Add(new JProperty(nameof(expected.Id), expected.Id)); blocks = blocks.AddStatements( ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(jobj), IdentifierName("Add") ) ) .AddArgumentListArguments( Argument( ObjectCreationExpression( ParseTypeName("JProperty") ).AddArgumentListArguments( Argument( InvocationExpression(IdentifierName("nameof")) .AddArgumentListArguments( Argument( Extensions.MemberAccess( IdentifierName(expected), IdentifierName(prop.Name) ) ) ) ), Argument( Extensions.MemberAccess( IdentifierName(expected), IdentifierName(prop.Name) ) ) ) ) ) ) ); } } method = method.AddBodyStatements( LocalDeclarationStatement( Extensions.VariableDeclaration( expected.Text, EqualsValueClause( IdentifierName(exp) ), $"I{t.Name}" ) ) ); method = method.AddBodyStatements(blocks.Statements.ToArray()); method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), false.ToLiteral() ) ), ExpressionStatement( InvocationExpression( Extensions.MemberAccess( IdentifierName(httpClient), IdentifierName("GetAsync") ) ) .AddArgumentListArguments( generateRunTaskWrapper( Block().AddStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(methodHit), true.ToLiteral() ) ), ReturnStatement( ObjectCreationExpression( ParseTypeName("HttpClientResult") ) .WithInitializer( InitializerExpression(SyntaxKind.ObjectInitializerExpression) .AddExpressions( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("StatusCode"), Extensions.MemberAccess( IdentifierName("HttpStatusCode"), IdentifierName("Ok") ) ), AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName("Content"), InvocationExpression( Extensions.MemberAccess( IdentifierName(jobj), IdentifierName("ToString") ) ).AddArgumentListArguments() ) ) ) ) ), Parameter(Identifier("uri")) ) ) ) ); var actual = Identifier("actual"); method = method.AddBodyStatements( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(results), AwaitExpression( InvocationExpression( Extensions.MemberAccess( IdentifierName(serverContext), IdentifierName($"Get{t.Name}Async") ) ) .AddArgumentListArguments( Argument(IdentifierName(key)) ) ) ) ), assertIsTrue(IdentifierName(methodHit), "Method not called"), assertStatment( Extensions.MemberAccess( IdentifierName("RequestStatus"), IdentifierName("Success") ), Extensions.MemberAccess( IdentifierName(results), IdentifierName("Status") ) ), assertStatment( IdentifierName(key), Extensions.MemberAccess( IdentifierName(results), IdentifierName("Key") ) ), assertIsNull( Extensions.MemberAccess( IdentifierName(results), IdentifierName("Exception") ), "Exception should be null" ), assertIsNotNull( Extensions.MemberAccess( IdentifierName(results), IdentifierName("Data") ), "Data should not be null" ), LocalDeclarationStatement( Extensions.VariableDeclaration( actual.Text, EqualsValueClause( Extensions.MemberAccess( IdentifierName(results), IdentifierName("Data") ) ) ) ) ); foreach(var prop in pi) { if (!prop.ShouldIgnore()) { method = method.AddBodyStatements( assertStatment( Extensions.MemberAccess( IdentifierName(expected), IdentifierName(prop.Name) ), Extensions.MemberAccess( IdentifierName(actual), IdentifierName(prop.Name) ) ) ); } } /* */ return method; }
private StatementSyntax[] createCommonResultIfStatments(Type t, PropertyInfo[] pi, String resultName) { var key = pi.GetKeyProperty(); var list = new List<StatementSyntax>(); /* var check = checkCommon(); if(check.Item1 != RequestStatus.Success) { return new TemperatureEntryResult(check.Item1, null, default(Guid)); } var builder = check.Item2; */ var check = Identifier("check"); list.Add( LocalDeclarationStatement( Extensions.VariableDeclaration(check.Text, EqualsValueClause( InvocationExpression( IdentifierName("checkCommon") ).AddArgumentListArguments() ) ) ) ); list.Add( IfStatement( BinaryExpression(SyntaxKind.NotEqualsExpression, Extensions.MemberAccess( IdentifierName(check), IdentifierName("Item1") ), Extensions.MemberAccess( IdentifierName("RequestStatus"), IdentifierName("Success") ) ), Block( ReturnStatement( ObjectCreationExpression(ParseTypeName(resultName)) .AddArgumentListArguments( Argument(Extensions.MemberAccess( IdentifierName(check), IdentifierName("Item1") )), Argument(LiteralExpression(SyntaxKind.NullLiteralExpression)), Argument(IdentifierName(keyName)) ) ) ) ) ); list.Add( LocalDeclarationStatement( Extensions.VariableDeclaration("builder", EqualsValueClause( Extensions.MemberAccess( IdentifierName(check), IdentifierName("Item2") ) ) ) ) ); /* HttpBaseProtocolFilter httpFilter = new HttpBaseProtocolFilter(); httpFilter.CookieManager.SetCookie(cookie);*/ return list.ToArray(); }
private MethodDeclarationSyntax createGetMethod(Type t, PropertyInfo[] pi) { var key = pi.GetKeyProperty(); var body = new List<StatementSyntax>(); body.AddRange(createCommonResultIfStatments(t, pi, $"{t.Name}Result")); body.AddRange(createGetCall(t, pi)); var method = taskBuilder.AsyncMethod( TypeArgumentList().AddArguments(ParseTypeName($"{t.Name}Result")), $"Get{t.Name}Async", Block().AddStatements(body.ToArray()) ); method = method.AddParameterListParameters( Parameter(keyName).WithType(ParseTypeName(key.PropertyType.Name))); method = method.WithModifiers(method.Modifiers.Insert(0, Token(SyntaxKind.PublicKeyword))); return method; }
private StatementSyntax[] createGetCall(Type t, PropertyInfo[] pi) { var result = Identifier("result"); var list = new List<StatementSyntax>(); var key = pi.GetKeyProperty(); list.Add(ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Path") ), InterpolatedStringExpression(Token(SyntaxKind.InterpolatedStringStartToken)) .AddContents( InterpolatedStringText() .WithTextToken( Token(TriviaList(), SyntaxKind.InterpolatedStringTextToken, $"/api/{t.Name}/", $"/api/{t.Name}/", TriviaList())), Interpolation(IdentifierName(keyName))) ) ) ); list.Add(LocalDeclarationStatement( VariableDeclaration(ParseTypeName("HttpClientResult")) .AddVariables( VariableDeclarator(result) .WithInitializer( EqualsValueClause(LiteralExpression(SyntaxKind.NullLiteralExpression)) ) ) )); var ce = Identifier("ce"); var tryStatment = TryStatement() .WithBlock( Block( ExpressionStatement( AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(result), AwaitExpression( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("client"), IdentifierName("GetAsync") ) ) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Uri") ) ) ) ) ) ))); if(String.Compare(variables.GetValue("IsUWP"), "1") == 0) { tryStatment = tryStatment.AddCatches( CatchClause() .WithDeclaration( CatchDeclaration(IdentifierName("COMException")) .WithIdentifier(ce) ) .AddBlockStatements( IfStatement( BinaryExpression(SyntaxKind.EqualsExpression, MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ce), IdentifierName("HResult") ), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(-2147012867) ) ), Block() .AddStatements( ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.UnableToConnectToServer)) ), Argument( LiteralExpression(SyntaxKind.NullLiteralExpression) ) , Argument( IdentifierName(keyName) ), Argument( IdentifierName(ce) ) ) ) ) ), ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.Exception)) ), Argument( LiteralExpression(SyntaxKind.NullLiteralExpression) ) , Argument( IdentifierName(keyName) ), Argument( IdentifierName(ce) ) ) ) )); } tryStatment = tryStatment.AddCatches( CatchClause() .WithDeclaration( CatchDeclaration(IdentifierName("Exception")) .WithIdentifier(ce) ) .AddBlockStatements( ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.Exception)) ), Argument( LiteralExpression(SyntaxKind.NullLiteralExpression) ) , Argument( IdentifierName(keyName) ), Argument( IdentifierName(ce) ) ) ) ) ).WithTrailingTrivia(Whitespace(Environment.NewLine + Environment.NewLine)); list.Add(tryStatment); var res = Identifier("res"); var token = Identifier("token"); var item = Identifier("item"); var setStatements = Block(); foreach (var prop in pi) { if (!prop.ShouldIgnore()) { setStatements = setStatements.AddStatements(getPropertyValue(item, token, prop.Name, prop.PropertyType)); } } var block = Block() .AddStatements( LocalDeclarationStatement( VariableDeclaration(IdentifierName("var")) .AddVariables( VariableDeclarator(res) .WithInitializer( EqualsValueClause( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(result), IdentifierName("Content") ) ) ) ) ).WithTrailingTrivia(Whitespace(Environment.NewLine + Environment.NewLine)), TryStatement() .AddBlockStatements( LocalDeclarationStatement( VariableDeclaration(IdentifierName("var")) .AddVariables( VariableDeclarator(token) .WithInitializer( EqualsValueClause( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("JObject"), IdentifierName("Parse") ) ).AddArgumentListArguments( Argument(IdentifierName(res)) ) ) ) ) ), LocalDeclarationStatement( VariableDeclaration(IdentifierName("var")) .AddVariables( VariableDeclarator(item) .WithInitializer( EqualsValueClause( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(helperName), IdentifierName($"Create{t.Name}") ) ).AddArgumentListArguments() ) ) ) ), IfStatement( BinaryExpression(SyntaxKind.EqualsExpression, MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(token), IdentifierName("Type") ), MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("JTokenType"), IdentifierName("Object") ) ), setStatements ), ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.Success)) ), Argument( IdentifierName(item) ) , Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(item), IdentifierName(key.Name) ) ) ) ) ) .AddCatches( CatchClause() .WithDeclaration( CatchDeclaration(ParseTypeName("Exception")) .WithIdentifier(Identifier("ex")) ) .WithBlock( Block( ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.Exception)) ), Argument( LiteralExpression(SyntaxKind.NullLiteralExpression) ) , Argument( IdentifierName(keyName) ), Argument( IdentifierName("ex") ) ) ) ) ) ) ); list.Add(IfStatement( BinaryExpression(SyntaxKind.EqualsExpression, MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(result), IdentifierName("StatusCode") ), MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("HttpStatusCode"), IdentifierName(httpBuilder.GetStatusCode("Ok")) ) ), block ) .WithElse(ElseClause(Block() .AddStatements( ReturnStatement( ObjectCreationExpression(ParseTypeName($"{t.Name}Result")) .AddArgumentListArguments( Argument( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(ServerSDKStatusConstants.EnumName), IdentifierName(ServerSDKStatusConstants.Error)) ), Argument( LiteralExpression(SyntaxKind.NullLiteralExpression) ) , Argument( IdentifierName(keyName) ) ) ) ) ))); return list.ToArray(); }