Giter Site home page Giter Site logo

Comments (2)

daveaglick avatar daveaglick commented on July 1, 2024

Interesting - all the data is coming from Roslyn, and Statiq Docs essentially converts Roslyn symbols representations to Statiq Documents so we can more easily work with them. My guess is that the Docable theme doesn't know where to look for the value of these static readonly fields. Probably won't be too hard to add that - can you paste some code here showing exactly the pattern that you're using (I can probably guess, but want to make sure I'm replicating the problem exactly).

from statiq.docs.

Foxtrek64 avatar Foxtrek64 commented on July 1, 2024

I'm using a slightly modified version of Docable. Layout is mostly the same, but I've changed some properties here and there.

section/_Properties.cshtml

@{
    IReadOnlyList<IDocument> properties = Document.GetDocumentList(CodeAnalysisKeys.Members)
        ?.Where(x => x.GetBool(CodeAnalysisKeys.IsResult) && x.GetString(CodeAnalysisKeys.Kind) == "Property")
        .OrderBy(x => x.GetString(CodeAnalysisKeys.DisplayName))
        .ToList()
        ?? new List<IDocument>();
    if (properties?.Count > 0)
    {
        List<(string, string)> headings = (List<(string, string)>?)ViewData[Keys.Headings] ?? new List<(string, string)>();
        headings.Add(("properties", "Properties"));
        ViewData[Keys.Headings] = headings;
        <h2 id="properties">Properties</h2>
        <div class="table-responsive">
            <table class="table table-api table-striped table-hover three-cols">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Property Type</th>
                        <th>Summary</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (IDocument property in properties)
                    {
                        <tr>
                            <td>@Context.GetTypeLink(property, false)</td>
                            <td>@Context.GetTypeLink(property.GetDocument(CodeAnalysisKeys.Type))</td>
                            <td>
                                <div>@Html.Raw(property.GetString(CodeAnalysisKeys.Summary))</div>
                                @{
                                    IDocument containingType = property.GetDocument(CodeAnalysisKeys.ContainingType);
                                    if (!Document.IdEquals(containingType))
                                    {
                                        <div><small><em>Inherited from @Context.GetTypeLink(containingType)</em></small></div>
                                    }
                                    if (property.GetBool(CodeAnalysisKeys.IsStatic))
                                    {
                                        <div><small><em>static</em></small></div>
                                    }
                                }
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    }
}

section/_ConstantValue.cshtml

@using Microsoft.AspNetCore.Html;

@if (Document.GetBool(CodeAnalysisKeys.ConstantValue))
{
    List<(string, string)> headings = (List<(string, string)>?)ViewData[Keys.Headings] ?? new List<(string, string)>();
    headings.Add(("constant-value", "Constant Value"));
    ViewData[Keys.Headings] = headings;
	var constantValue = Document.Get(CodeAnalysisKeys.ConstantValue);

    <h2 id="constant-value">Constant Value</h2>
	<div class="table-responsive">
		<table class="table table-api table-striped table-hover two-cols">
			<thead>
				<tr>
					<th>Value</th>
					<th>Type</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>@(new HtmlString(constantValue?.ToString() ?? "null"))</td>
					<td>@(new HtmlString(constantValue?.GetType().Name ?? string.Empty))</td>
				</tr>
			</tbody>
		</table>
	</div>
}

Edit: Here's a small type-safe enum example:
Essentially, it aims to replicate Enum CustomerCode : T where T is anything, but it lacks some obvious features of enums such as being able to be used in a switch statement (values aren't constant), no flag support unless implemented manually, and so forth. Generally best used for when you need an explicit enumeration, such as where you'd use an enum, but where using an enum is not possible due to type restraints. These will be going away most likely when we get Discriminated Unions, but this is some time away.

public sealed class CustomerCode
{
    public string Code { get; }
    
    private CustomerCode(string code)
    {
        Code = code
    }

    public static readonly CustomerCode Contoso = new("Con01");
    public static readonly CustomerCode Microsoft = new ("Msft01");
}

from statiq.docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.