Пример #1
0
        private static CodeExpression CreateRestrictionInitializers(RouteParameters.RouteParameters routeParameters, CodeTypeReferenceExpression parameterConstantsType, CodeExpression expression)
        {
            foreach (KeyValuePair <string, IRouteParameterType> routeParameter in routeParameters)
            {
                if (routeParameter.Value.RequiresRestriction)
                {
                    CodePropertyReferenceExpression propertyRef = new CodePropertyReferenceExpression(parameterConstantsType, routeParameter.Key);
                    CodeMethodInvokeExpression      restrict    = new CodeMethodInvokeExpression(expression, "Restrict", propertyRef);

                    if (routeParameter.Value is StringRouteParameterType)
                    {
                        StringRouteParameterType stringRouteParameterType = (StringRouteParameterType)routeParameter.Value;
                        List <CodeExpression>    expressions = new List <CodeExpression>();

                        foreach (string choice in stringRouteParameterType.anyOf)
                        {
                            expressions.Add(new CodePrimitiveExpression(choice));
                        }

                        expression = new CodeMethodInvokeExpression(restrict, "AnyOf", expressions.ToArray());
                    }
                    else if (routeParameter.Value is GuidRouteParameterType)
                    {
                        expression = new CodePropertyReferenceExpression(restrict, "ValidGuid");
                    }
                    else if (routeParameter.Value is IntRouteParameterType)
                    {
                        expression = new CodePropertyReferenceExpression(restrict, "ValidInteger");
                    }
                }
            }

            return(expression);
        }
Пример #2
0
        private void CreateParameterConstantsType(string paramatersClassName, RouteParameters.RouteParameters routeParameters)
        {
            CodeTypeDeclaration parameters = sourceGenerator.GenerateTypeDeclaration(@namespace, paramatersClassName, routeDefinitions.Name, routeDefinition.Name);

            foreach (KeyValuePair <string, IRouteParameterType> routeParameter in routeParameters)
            {
                parameters.Members.Add(sourceGenerator.NewPublicConstant(routeParameter.Key, routeParameter.Key));
            }
        }
Пример #3
0
 public PatternRouteCreator(string @namespace, ISourceGenerator sourceGenerator, INamingService namingService, PatternRouteTreeNode node, CodeTypeDeclaration routeDefinitions, CodeTypeDeclaration routes) : base(@namespace, sourceGenerator, namingService, node, routeDefinitions, routes)
 {
     requiredRouteParameters = new RequiredRouteParameters().GetFrom(node.Pattern);
     optionalRouteParameters = new OptionalRouteParameters().GetFrom(node.Pattern);
     routeParameterDefaults  = new RouteParameterDefaults().GetFrom(node.Defaults);
 }