public ResourceClassBuilder(SourceFileContext ctx, ResourceDetails.Definition def) { _ctx = ctx; _def = def; ResourceNameTypeTyp = Typ.Nested(def.ResourceNameTyp, "ResourceNameType", isEnum: true); PatternDetails = _def.Patterns.Where(x => !x.IsWildcard).Select(x => new PatternDetails(ctx, def, x)).ToList(); }
public PathElement(SourceFileContext ctx, ResourceDetails.Definition def, string rawPathElement) { var nameWithoutId = rawPathElement.RemoveSuffix("_id"); var nameWithId = $"{nameWithoutId}_id"; UpperCamel = nameWithoutId.ToUpperCamelCase(); LowerCamel = nameWithoutId.ToLowerCamelCase(); Parameter = RoslynBuilder.Parameter(ctx.Type <string>(), nameWithId.ToLowerCamelCase()); ParameterWithDefault = RoslynBuilder.Parameter(ctx.Type <string>(), nameWithId.ToLowerCamelCase(), @default: Null); ParameterXmlDoc = XmlDoc.Param(Parameter, "The ", XmlDoc.C(nameWithoutId.ToUpperCamelCase()), " ID. Must not be ", null, " or empty."); var summarySuffix = def.Patterns.Count > 1 ? new object[] { "May be ", null, ", depending on which resource name is contained by this instance." } : new object[] { "Will not be ", null, ", unless this instance contains an unparsed resource name." }; Property = AutoProperty(Public, ctx.Type <string>(), nameWithId.ToUpperCamelCase()) .WithXmlDoc(XmlDoc.Summary(new object[] { "The ", XmlDoc.C(nameWithoutId.ToUpperCamelCase()), " ID. " }.Concat(summarySuffix).ToArray())); }
public PatternDetails(SourceFileContext ctx, ResourceDetails.Definition def, ResourceDetails.Definition.Pattern pattern) { PatternString = pattern.PatternString; PathSegments = pattern.Template.Segments.Select(x => new PathSegment(ctx, def, x)).ToList(); if (pattern.Template.ParameterNames.Count() == 0) { // Path-template contains no parameters, special naming required. UpperName = PatternString.ToUpperCamelCase(); LowerName = PatternString.ToLowerCamelCase(); } else { // Standard naming, concat all parameter names. UpperName = string.Join("", PathElements.Select(x => x.UpperCamel)); LowerName = string.Join("", PathElements.Take(1).Select(x => x.LowerCamel).Concat(PathElements.Skip(1).Select(x => x.UpperCamel))); } PathTemplateField = Field(Private | Static, ctx.Type <PathTemplate>(), $"s_{LowerName}").WithInitializer(New(ctx.Type <PathTemplate>())(pattern.Template.PathTemplateString)); }
public PathSegment(SourceFileContext ctx, ResourceDetails.Definition def, ResourcePattern.Segment segment) { Segment = segment; Elements = segment.ParameterNames.Select(x => new PathElement(ctx, def, x)).ToList(); }