joelmartinez / Monodoc.Razor

razor renderer for monodoc ECMA documentation
MIT License
0 stars 0 forks source link

Link generic parameters in class and method signature #33

Open patridge opened 7 years ago

patridge commented 7 years ago

There may be more affected links, but at least one example is when a class inherits from a generic variant of a class. For example, ListView under Xamarin.Forms inherits from ItemsView<Cell>, which results in this URL. https://developer.xamarin.com/api/type/Xamarin.Forms.ItemsView%3CXamarin.Forms.Cell%3E/

In this case, ItemsView<…> should actually point to ItemsView<TVisual>, where TVisual : BindableObject. (And Cell inherits from Element which inherits from BindableObject.)

joelmartinez commented 7 years ago

Some implementation notes ... the type xml for a class that derives from a generic class with a concrete value for the type parameter looks like this:

  <Base>
    <BaseTypeName>My.Sample.SomeGenericClass&lt;System.String&gt;</BaseTypeName>
    <BaseTypeArguments>
      <BaseTypeArgument TypeParamName="T">System.String</BaseTypeArgument>
    </BaseTypeArguments>
  </Base>

link generation (#30) will have to take this into account and use the BaseTypeName, and systematically replace the arguments using the TypeParamName, in order to generate the link to the actual type being used. We should probably use the EcmaUrlParser, to parse the value of BaseTypeName (prefixed with "T:").

ultimately, this could be used to also build links to the concrete type used as the type parameter (System.String, in the example above) ... that way, SomeGenericClass links to the proper type, as does the parameter value.

joelmartinez commented 7 years ago

For methods that accept generic arguments with concrete type parameters, it is a bit more complex:

    <Member MemberName="AcceptsConcreteGenericParam">
      <MemberSignature Language="C#" Value="public void AcceptsConcreteGenericParam (My.Sample.SomeGenericClass&lt;string&gt; value);" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig instance void AcceptsConcreteGenericParam(class My.Sample.SomeGenericClass`1&lt;string&gt; value) cil managed" />
      <MemberType>Method</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>0.0.0.0</AssemblyVersion>
      </AssemblyInfo>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="value" Type="My.Sample.SomeGenericClass&lt;System.String&gt;" />
      </Parameters>
      <Docs>
        <param name="value">To be added.</param>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>

Where the type XML has the useful BaseTypeArgument, the method isn't so helpful :( This means that we will have to do an impromptu lookup when rendering this signature by creating a type link in the form of T:My.Sample.SomeGenericClass1, and then use that to lookup the value(s) of/TypeParameters/TypeParameter` to generate the proper link.