[stringtemplate-interest] IAttributeRenderer and Type Inheritance in C#

Vincent DARON vdaron at ask.be
Thu Oct 22 08:12:15 PDT 2009


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


More information about the stringtemplate-interest mailing list