internal void Compile(MethodInvoke method) { // init method.AddElement(this); method.AddCode(method.ParameterName); method.AddLiteral(this.Prefix); method.AddLiteral(this.Suffix); // fix var family = (this.NameParts == null || !this.NameParts.Any(x => x.Name == NamePartName.Family) ? new NamePartElement() : this.NameParts.Single(x => x.Name == NamePartName.Family)); var given = (this.NameParts == null || !this.NameParts.Any(x => x.Name == NamePartName.Given) ? new NamePartElement() : this.NameParts.Single(x => x.Name == NamePartName.Given)); // name part parameters using (var lambda = method.AddLambdaExpression(false)) { // array lambda.AppendArray("NamePartParameters", new NamePartElement[] { family, given }, (part, scope) => { // init using (var m = scope.AppendMethodInvoke("new NamePartParameters", part)) { part.Compile(m); } }); } // default parameters method.AddDefaultParameters(); }
internal void Compile(MethodInvoke method) { // name method.AddElement(this); method.AddCode(method.ParameterName); method.AddLiteral(this.TextCaseSpecified ? (object)this.TextCase : null); method.AddLiteral(this.Prefix); method.AddLiteral(this.Suffix); method.AddDefaultParameters(); }
public static void AddSortComparerParameters(this MethodInvoke method, SortElement sort) { // find orders var keys = sort.Keys ?? new KeyElement[] { }; // add foreach (var key in keys) { method.AddLiteral(key.SortOrderSpecified ? key.SortOrder : SortOrder.Ascending); } }
/// <summary> /// Compiles this DatePart. /// </summary> /// <param name="method"></param> internal void Compile(MethodInvoke method) { // allowed formats? if (this.FormatSpecified) { // init var allowed = true; // allowed? switch (this.Name) { case DatePartName.Day: allowed = (this.Format == DatePartFormat.Numeric || this.Format == DatePartFormat.NumericLeadingZeros || this.Format == DatePartFormat.Ordinal); break; case DatePartName.Month: allowed = (this.Format == DatePartFormat.Long || this.Format == DatePartFormat.Short || this.Format == DatePartFormat.Numeric || this.Format == DatePartFormat.NumericLeadingZeros); break; case DatePartName.Year: allowed = (this.Format == DatePartFormat.Long || this.Format == DatePartFormat.Short); break; } // done if (!allowed) { throw new CompilerException(this, "Format '{0}' is not allowed for '{1}' date-parts.", this.Format, this.Name); } } // strip periods allowed? if (this.StripPeriodsSpecified && this.Name != DatePartName.Month) { throw new CompilerException(this, "StripPeriods is only allowed for 'Month' date-parts."); } // name method.AddElement(this); method.AddCode(method.ParameterName); method.AddLiteral(this.Name); // format if (this.FormatSpecified) { // specified format method.AddLiteral(this.Format); } else { // use default switch (this.Name) { case DatePartName.Day: method.AddLiteral(DatePartFormat.Numeric); break; case DatePartName.Month: method.AddLiteral(DatePartFormat.Long); break; case DatePartName.Year: method.AddLiteral(DatePartFormat.Long); break; default: throw new CompilerException("Invalid date-part name."); } } // affixes method.AddLiteral(this.Prefix); method.AddLiteral(this.Suffix); method.AddLiteral(this.TextCaseSpecified ? (object)this.TextCase : null); method.AddDefaultParameters(); }