public static string UnsupportedTargetTypeForAggregateFunction(AggregateFunctionContext context) { StringBuilder error = GetIntro(context.Member); error.AppendFormat("Aggregate function '{0}' doesn't support type '{1}' as target type", context.ImplementationType, context.Member.Type); return error.ToString(); }
virtual public IEnumerable <string> GetIterationStatements(AggregateFunctionContext context, IList <AggregateExpressionPathItem> pathItems) { AggregateExpressionPathItem lastPathItem = pathItems[pathItems.Count - 1]; string finalTarget = ""; foreach (AggregateExpressionPathItem pathItem in pathItems) { if (pathItem.IsCollection) { finalTarget = pathItem.Object; } } string finalExpression = context.Member.AggregateMappingDescription.FinalExpression; string processedExpression = ""; if ((string.IsNullOrEmpty(finalExpression) || lastPathItem.IsCollection)) { processedExpression = finalTarget; } else { processedExpression = string.Format("{0}.{1}", finalTarget, finalExpression); } string fullFormat = GetFormatForExecutedExpression(context); fullFormat = fullFormat.Replace("FN_OBJ", "{0}"); fullFormat = fullFormat.Replace("CURR_ITEM", "{1}"); return(new string[] { string.Format(fullFormat, context.FunctionObjectName, processedExpression) }); }
public override CodeStatement GetAssignmentStatement(AggregateFunctionContext context) { string resultExpression = m_isArray ? string.Format("{0}.ToArray()", context.FunctionObjectName) : context.FunctionObjectName; return new CodeAssignStatement( new CodeVariableReferenceExpression("target." + context.Member.Member), new CodeArgumentReferenceExpression(resultExpression)); }
public virtual IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { CodeExpression[] parameters = new CodeExpression[0]; CodeStatement st = new CodeVariableDeclarationStatement(context.ImplementationType, context.FunctionObjectName, new CodeObjectCreateExpression(context.ImplementationType, parameters)); return new CodeStatement[] {st}; }
virtual public IEnumerable <CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { CodeExpression[] parameters = new CodeExpression[0]; CodeStatement st = new CodeVariableDeclarationStatement(context.ImplementationType, context.FunctionObjectName, new CodeObjectCreateExpression(context.ImplementationType, parameters)); return(new CodeStatement[] { st }); }
public virtual CodeStatement GetAssignmentStatement(AggregateFunctionContext context) { string resultExpression = context.FunctionObjectName + ".Result"; if (context.Member.HasFormatting) resultExpression = string.Format("string.Format(\"{0}\", {1}.Result)", context.Member.Format, context.FunctionObjectName); return new CodeAssignStatement( new CodeVariableReferenceExpression("target." + context.Member.Member), new CodeArgumentReferenceExpression(resultExpression)); }
public virtual CodeStatement GetAssignmentStatement(AggregateFunctionContext context) { m_context = context; string expression = GetResultExpression(); if (context.Member.HasFormatting) expression = string.Format("string.Format(\"{0}\", {1})", context.Member.Format, expression); return new CodeAssignStatement( new CodeVariableReferenceExpression("target." + context.Member.Member), new CodeArgumentReferenceExpression(expression)); }
public override IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { List<CodeStatement> statements = new List<CodeStatement>(base.GetInitializationStatements(context)); CodeStatement st = new CodeVariableDeclarationStatement(typeof(int), GetCounterObjectName(context), new CodeSnippetExpression("0")); statements.Add(st); return statements; }
virtual public CodeStatement GetAssignmentStatement(AggregateFunctionContext context) { string resultExpression = context.FunctionObjectName + ".Result"; if (context.Member.HasFormatting) { resultExpression = string.Format("string.Format(\"{0}\", {1}.Result)", context.Member.Format, context.FunctionObjectName); } return(new CodeAssignStatement( new CodeVariableReferenceExpression("target." + context.Member.Member), new CodeArgumentReferenceExpression(resultExpression))); }
public override IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { MemberMappingDescriptor member = context.Member; Type resultType; Type instanceType; bool isSimpleMapping = false; if (member.IsArray || member.IsList) { instanceType = member.IsArray ? member.AggregateMappingDescription.TargetType.GetElementType() : member.AggregateMappingDescription.TargetType.GetGenericArguments()[0]; resultType = typeof(List<>).MakeGenericType(instanceType); if (!instanceType.IsPrimitive && instanceType != typeof(string)) { m_expression = string.Format("{{0}}.Add({0}.AssembleFrom({{1}}));", GetAssemblerName(context)); } else { m_expression = "{0}.Add({1});"; isSimpleMapping = true; } } else { string msg = ErrorBuilder.CantAggregateOverNoncollectionError(member, "collect"); throw new OtisException(msg); //todo: test } m_isArray = member.IsArray; List<CodeStatement> statements = new List<CodeStatement>(); CodeExpression[] parameters = new CodeExpression[0]; CodeStatement st = new CodeVariableDeclarationStatement(resultType, context.FunctionObjectName, new CodeObjectCreateExpression(resultType, parameters)); statements.Add(st); if(!isSimpleMapping) { st = new CodeVariableDeclarationStatement( string.Format("IAssembler<{0}, {1}>", TypeHelper.GetTypeDefinition(instanceType), TypeHelper.GetTypeDefinition(context.SourceItemType)), GetAssemblerName(context), new CodeSnippetExpression("this")); statements.Add(st); } return statements; }
public virtual IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context) { m_context = context; if(!IsTypeSupportedAsTarget(context.Member.Type)) throw new OtisException(GetUnsupportedTargetTypeErrorMessage()); if (!IsTypeSupportedAsSource(context.SourceItemType)) throw new OtisException(GetUnsupportedSourceTypeErrorMessage()); CodeStatement st = new CodeVariableDeclarationStatement(GetFunctionObjectType(), context.FunctionObjectName, new CodeSnippetExpression(GetFunctionObjectInitialValue())); return new CodeStatement[] {st}; }
private string GetProcessedExpressionFormat(AggregateFunctionContext context) { IExpressionFormatProvider fmtProvider = context.Generator as IExpressionFormatProvider; if (fmtProvider == null) { Type realImplementationType = context.ImplementationType.IsGenericTypeDefinition ? context.ImplementationType.MakeGenericType(typeof (int)) : context.ImplementationType; fmtProvider = (IExpressionFormatProvider) Activator.CreateInstance(realImplementationType, true); } if (string.IsNullOrEmpty(fmtProvider.ExpressionFormat)) return "{1}"; else return fmtProvider.ExpressionFormat; }
public virtual IEnumerable<string> GetIterationStatements(AggregateFunctionContext context, IList<AggregateExpressionPathItem> pathItems) { AggregateExpressionPathItem lastPathItem = pathItems[pathItems.Count - 1]; string finalTarget = ""; foreach (AggregateExpressionPathItem pathItem in pathItems) if (pathItem.IsCollection) finalTarget = pathItem.Object; string finalExpression = context.Member.AggregateMappingDescription.FinalExpression; string processedExpression = ""; if ((string.IsNullOrEmpty(finalExpression) || lastPathItem.IsCollection)) processedExpression = finalTarget; else processedExpression = string.Format("{0}.{1}", finalTarget, finalExpression); string fullFormat = GetFormatForExecutedExpression(context); fullFormat = fullFormat.Replace("FN_OBJ", "{0}"); fullFormat = fullFormat.Replace("CURR_ITEM", "{1}"); return new string[] { string.Format(fullFormat, context.FunctionObjectName, processedExpression) }; }
private string GetProcessedExpressionFormat(AggregateFunctionContext context) { IExpressionFormatProvider fmtProvider = context.Generator as IExpressionFormatProvider; if (fmtProvider == null) { Type realImplementationType = context.ImplementationType.IsGenericTypeDefinition ? context.ImplementationType.MakeGenericType(typeof(int)) : context.ImplementationType; fmtProvider = (IExpressionFormatProvider)Activator.CreateInstance(realImplementationType, true); } if (string.IsNullOrEmpty(fmtProvider.ExpressionFormat)) { return("{1}"); } else { return(fmtProvider.ExpressionFormat); } }
protected override string GetFormatForExecutedExpression(AggregateFunctionContext context) { return "FN_OBJ = FN_OBJ + 1;"; }
protected virtual string GetFormatForExecutedExpression(AggregateFunctionContext context) { string processedExpressionFormat = GetProcessedExpressionFormat(context); return "{0}.ProcessValue(" + processedExpressionFormat + ")"; }
protected virtual string GetFormatForExecutedExpression(AggregateFunctionContext context) { string processedExpressionFormat = GetProcessedExpressionFormat(context); return("{0}.ProcessValue(" + processedExpressionFormat + ")"); }
protected override string GetFormatForExecutedExpression(AggregateFunctionContext context) { return string.Format("FN_OBJ.Append(CURR_ITEM); FN_OBJ.Append(\"{0}\");", Separator); // -> "{{ FN_OBJ.Append(CURR_ITEM); FN_OBJ.Append(\"separator\"); }}" // -> "{ FN_OBJ.Append(CURR_ITEM); FN_OBJ.Append(\"separator\"); }" }
protected override string GetFormatForExecutedExpression(AggregateFunctionContext context) { // todo: test return string.Format("FN_OBJ = FN_OBJ + CURR_ITEM; {0}++;", GetCounterObjectName(context)); }
protected abstract string GetFormatForExecutedExpression(AggregateFunctionContext context);
private static string GetCounterObjectName(AggregateFunctionContext context) { return context.FunctionObjectName + "_Cnt"; }
protected override string GetFormatForExecutedExpression(AggregateFunctionContext context) { // todo: test return m_expression; }
protected override string GetFormatForExecutedExpression(AggregateFunctionContext context) { // todo: test return "if(CURR_ITEM < FN_OBJ) FN_OBJ = CURR_ITEM;"; }
private static string GetAssemblerName(AggregateFunctionContext context) { return context.FunctionObjectName + "_Asm"; }