/// <summary> /// Creates a field that holds <see cref="QueryTypeProperties{T}"/> for the module. /// </summary> protected FieldDeclarationSyntax CreatePropertiesField( Module module, string resultClassName, FieldDeclarationSyntax propsField, SortType?sortType) { var queryTypePropertiesType = SyntaxEx.GenericName("QueryTypeProperties", resultClassName); var propertiesInitializer = SyntaxEx.ObjectCreation( queryTypePropertiesType, SyntaxEx.Literal(module.Name), SyntaxEx.Literal(module.Prefix), module.QueryType == null ? (ExpressionSyntax)SyntaxEx.NullLiteral() : SyntaxEx.MemberAccess("QueryType", module.QueryType.ToString()), sortType == null ? (ExpressionSyntax)SyntaxEx.NullLiteral() : SyntaxEx.MemberAccess("SortType", sortType.ToString()), CreateTupleListExpression(GetBaseParameters(module)), propsField == null ? (ExpressionSyntax)SyntaxEx.NullLiteral() : (NamedNode)propsField, resultClassName == "object" ? (ExpressionSyntax)SyntaxEx.LambdaExpression("_", SyntaxEx.NullLiteral()) : SyntaxEx.MemberAccess(resultClassName, "Parse")); return(SyntaxEx.FieldDeclaration( new[] { SyntaxKind.PrivateKeyword, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword }, queryTypePropertiesType, ClassNameBase + "Properties", propertiesInitializer)); }
/// <summary> /// Creates a field that holds information about property groups for the given module. /// </summary> protected FieldDeclarationSyntax CreatePropsField(IEnumerable <PropertyGroup> propertyGroups) { var initializers = from pg in propertyGroups from p in pg.Properties group pg.Name by p.Name into g select new[] { SyntaxEx.Literal(g.Key), SyntaxEx.ArrayCreation(null, g.Select(SyntaxEx.Literal)) }; var propsInitializer = SyntaxEx.ObjectCreation("Dictionary<string, string[]>", null, initializers); var propsField = SyntaxEx.FieldDeclaration( new[] { SyntaxKind.PrivateKeyword, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword }, "IDictionary<string, string[]>", ClassNameBase + "Props", propsInitializer); return(propsField); }