[stringtemplate-interest] IAttributeRenderer and Type Inheritance in C#
Jonathan Buhacoff
jonathan at buhacoff.net
Thu Oct 22 10:06:29 PDT 2009
+0.5
I think this can be useful for internationalization efforts, but I'd
like to have a concrete example for everyone before I give it the
other 0.5 :)
Vincent wrote a lot of code in Microsoft-style C, so here's a diff
against StringTemplate.java in version 3.2.1 that does the same thing,
if you just register your interface renderer the same way you do your
class renderer (not what Vincent wrote), which does work:
1070a1071,1079
>
> if( renderer == null ) {
> // there's no renderer for that class specifically, so let's
try its interfaces
> Class[] interfaces = attributeClassType.getInterfaces();
> for(int i=0; i<interfaces.length && renderer==null; i++) {
> renderer =
(AttributeRenderer)attributeRenderers.get(interfaces[i]);
> }
> }
>
On Oct 22, 2009, at 8:12 AM, Vincent DARON wrote:
> Hi
>
> I would like to be able to register an IAttributeRenderer for objects
> implementing an Interface.
>
> Part of current implementation of GetAttributeRenderer
>
> public virtual IAttributeRenderer GetAttributeRenderer( Type
> attributeClassType )
> {
> IAttributeRenderer renderer = null;
> if ( _attributeRenderers != null )
> {
> if ( !
> _attributeRenderers.TryGetValue( attributeClassType, out renderer ) )
> renderer = null;
> }
> // ...snip ... //
> }
>
>
> My proposal (untested, but should be ok)
>
> public virtual IAttributeRenderer GetAttributeRenderer( Type
> attributeClassType )
> {
> IAttributeRenderer renderer = null;
> if ( _attributeRenderers != null )
> {
> foreach(Type key in _attributeRenderers.Keys)
> {
> if(key.IsAssignableFrom(attributeClassType))
> {
> renderer = _attributeRenderers[key];
> break;
> }
> }
> }
> // ...snip ... //
> }
>
>
> It will allow to register Attribute Renderer for objects implementing
> interfaces
>
> RegisterAttributeRenderer(typeof(IFormatProvider), ...);
>
> Goot idea ?
>
> Second question, is it possible to have access to source using Source
> Control (Subversion, Hg, Git, ...) ? It would be far easier to test
> and
> create patches.
>
> Thanks for answer/comments
>
> Vincent
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list