public virtual ExpressionSyntax New(object instance, GenerationContext context) { if (instance == null) { return(LiteralExpression(SyntaxKind.NullLiteralExpression)); } var t = instance.GetType(); var r = EarlyChecks(t, instance, context); if (r != null) { return(r); } if (!context.DefinedVariable(instance, out string instanceName)) { var initNodes = ProduceInlineableProperties(instanceName, instance, context); var result = NewInstanceExpression(t, context); var vbl = SingletonSeparatedList <VariableDeclaratorSyntax>( VariableDeclarator(Identifier(instanceName) ).WithInitializer(EqualsValueClause(result))); var assign = LocalDeclarationStatement(VariableDeclaration(Var) .WithVariables(vbl)); context.Declarations.Enqueue(assign); foreach (var nd in initNodes) { context.Declarations.Enqueue(nd); } ProduceNestedProperties(instanceName, instance, context); ProduceCollectionProperties(instanceName, instance, context); ProduceDictionaryProperties(instanceName, instance, context); } return(IdentifierName(instanceName)); }