public static Expression Build(TypeDefinitionExpression expression, CodeGenerationContext context) { var builder = new PropertiesToDictionaryExpressionBinder(expression.Type, context); builder.Visit(expression); return builder.propertySetterExpressions.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide); }
public static Expression Build(TypeDefinitionExpression expression, CodeGenerationContext context) { var builder = new PropertiesToDictionaryExpressionBinder(expression.Type, context); builder.Visit(expression); return(builder.propertySetterExpressions.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide)); }
private Expression CreateAllPropertiesAsDictionaryMethod(TypeDefinitionExpression expression) { var dictionaryType = new FickleType("NSMutableDictionary"); var retvalExpression = Expression.Parameter(dictionaryType, "retval"); IEnumerable <ParameterExpression> variables = new[] { retvalExpression }; var newDictionaryExpression = Expression.Assign(retvalExpression, FickleExpression.New("NSMutableDictionary", "initWithCapacity", ExpressionTypeCounter.Count(expression, (ExpressionType)ServiceExpressionType.PropertyDefinition) * 2)).ToStatement(); var makeDictionaryExpression = PropertiesToDictionaryExpressionBinder.Build(expression, this.codeGenerationContext); var returnDictionaryExpression = Expression.Return(Expression.Label(), Expression.Parameter(dictionaryType, "retval")).ToStatement(); var methodBody = Expression.Block(variables, GroupedExpressionsExpression.FlatConcat(GroupedExpressionsExpressionStyle.Wide, newDictionaryExpression, makeDictionaryExpression, returnDictionaryExpression)); return(new MethodDefinitionExpression("allPropertiesAsDictionary", new List <Expression>().ToReadOnlyCollection(), dictionaryType, methodBody, false, null)); }