public CodegenSetterBuilder Map <TI>( string name, IDictionary <string, TI> values, CodegenSetterBuilderItemConsumer <TI> consumer) { return(SetValue(name, BuildMap(values, consumer, _originator, _method, _classScope))); }
public CodegenExpression ToExpression( CodegenMethodScope parent, CodegenClassScope scope) { CodegenSetterBuilderItemConsumer<XPathPropertyDesc> xPathBuild = (o, parentXPath, scopeXPath) => o.ToCodegenExpression(parentXPath, scopeXPath); return new CodegenSetterBuilder(typeof(ConfigurationCommonEventTypeXMLDOM), typeof(ConfigurationCommonEventTypeXMLDOM), "xmlconfig", parent, scope) .Constant("RootElementName", RootElementName) .Map("XPathProperties", XPathProperties, xPathBuild) .MapOfConstants("NamespacePrefixes", NamespacePrefixes) .Constant("SchemaResource", SchemaResource) .Constant("SchemaText", SchemaText) .Constant("IsEventSenderValidatesRoot", IsEventSenderValidatesRoot) .Constant("IsAutoFragment", IsAutoFragment) .Constant("IsXPathPropertyExpr", IsXPathPropertyExpr) .Constant("XPathFunctionResolver", XPathFunctionResolver) .Constant("XPathVariableResolver", XPathVariableResolver) .Constant("IsXPathResolvePropertiesAbsolute", IsXPathResolvePropertiesAbsolute) .Constant("DefaultNamespace", DefaultNamespace) .Constant("RootElementNamespace", RootElementNamespace) .Constant("StartTimestampPropertyName", StartTimestampPropertyName) .Constant("EndTimestampPropertyName", EndTimestampPropertyName) .Build(); }
public CodegenSetterBuilder MapOfConstants <T>( string name, IDictionary <string, T> values) { CodegenSetterBuilderItemConsumer <T> consumer = ( o, parent, scope) => CodegenExpressionBuilder.Constant(o); return(SetValue(name, BuildMap(values, consumer, _originator, _method, _classScope))); }
private static CodegenExpression BuildMapValue <TV>( TV value, CodegenSetterBuilderItemConsumer <TV> valueConsumer, Type originator, CodegenMethod method, CodegenClassScope classScope) { if (value is IDictionary <string, TV> valueMap) { return(BuildMap(valueMap, valueConsumer, originator, method, classScope)); } return(valueConsumer.Invoke(value, method, classScope)); }
private static CodegenExpression BuildMap <TV>( IDictionary <string, TV> map, CodegenSetterBuilderItemConsumer <TV> valueConsumer, Type originator, CodegenMethod method, CodegenClassScope classScope) { if (map == null) { return(ConstantNull()); } if (map.IsEmpty()) { return(EnumValue(typeof(EmptyDictionary <string, TV>), "Instance")); } CodegenMethod child = method.MakeChild(typeof(IDictionary <string, TV>), originator, classScope); if (map.Count == 1) { KeyValuePair <string, TV> single = map.First(); CodegenExpression value = BuildMapValue(single.Value, valueConsumer, originator, child, classScope); child.Block.MethodReturn( StaticMethod( typeof(Collections), "SingletonMap", new[] { typeof(string), typeof(TV) }, CodegenExpressionBuilder.Constant(single.Key), value)); } else { child.Block.DeclareVar( typeof(IDictionary <string, TV>), "map", NewInstance(typeof(LinkedHashMap <string, TV>))); foreach (KeyValuePair <string, TV> entry in map) { CodegenExpression value = BuildMapValue(entry.Value, valueConsumer, originator, child, classScope); child.Block.ExprDotMethod(Ref("map"), "Put", CodegenExpressionBuilder.Constant(entry.Key), value); } child.Block.MethodReturn(Ref("map")); } return(LocalMethod(child)); }