Custom ExtensionAttribute with required properties

Nov 15, 2010 at 10:02 PM

Hey

 

I'm having a problem with creating a custom extension attribute which contains required properties. This is how it looks in general:

public class MetaDataSerializerAttribute : CustomExtensionAttribute
{
    [NodeAttribute("Application", true)] 
    public string Application { get; set; }

    [NodeAttribute("Type", true)]
    public MetaDataTypes Type { get; set; }

    [NodeAttribute("Filenames", true)]
    public string[] Filenames { get; set; }

    public MetaDataSerializerAttribute()
    { }

    public MetaDataSerializerAttribute([NodeAttribute("Application")] string application, [NodeAttribute("Type")] MetaDataTypes type, [NodeAttribute("Filenames")] string[] filenames)
    {
        this.Application = application;
        this.Type = type;
        this.Filenames = filenames;
    }
}

I have also created a TypeExtensionPoint which has this attribute assigned to called IMetaDataSerializer:

[TypeExtensionPoint(ExtensionAttributeType = typeof (MetaDataSerializerAttribute))]
public interface IMetaDataSerializer : IAddin
{ ... }

Then I created an Addin with a type that implements IMetaDataSerializer like this:

[MetaDataSerializer("***", MetaDataTypes.TvEpisode, new string[] { ":filename:.nfo" }, Id = "***.TvEpisode")]
public class TvEpisode : IMetaDataSerializer
{ ... }

but no matter which overloaded version of AddinManager.GetExtensionNodes() I call it always returns an empty list and I see the following from the progress monitor:

Error while loading Addin with ID "***,0.1": Could not read extension node of type 'Mono.Addins.TypeExtensionNode`1[***.MetaDataSerializerAttribute]' from extension path '***.TvEpisode'
Source: Mono.Addins
Function: Void ReadObject(System.Object, Mono.Addins.NodeAttribute[], System.Collections.Generic.Dictionary`2[System.String,Mono.Addins.Description.ExtensionNodeType+FieldData])
Message: Required attribute 'Application' not found.
   bei Mono.Addins.ExtensionNode.ReadObject(Object ob, NodeAttribute[] attributes, Dictionary`2 fields) in ***\Mono.Addins\ExtensionNode.cs:Zeile 292.
   bei Mono.Addins.ExtensionNode.Read(NodeElement elem) in ***\Mono.Addins\ExtensionNode.cs:Zeile 233.
   bei Mono.Addins.TypeExtensionNode.Read(NodeElement elem) in ***\Mono.Addins\TypeExtensionNode.cs:Zeile 44.
   bei Mono.Addins.ExtensionTree.ReadNode(TreeNode tnode, String addin, ExtensionNodeType ntype, ExtensionNodeDescription elem, ModuleDescription module) in ***\Mono.Addins\ExtensionTree.cs:Zeile 182.

If I remove the required constraint it works just fine. Am I doing something wrong or is this a bug? 
Thanks for your help.

PS: Is there any way to access the current development sources in an SVN or something to get the latest fixes/changes?

Coordinator
Nov 16, 2010 at 9:03 AM

This looks like a bug. I'm taking a look at it.

Coordinator
Nov 17, 2010 at 1:53 PM

The bug is now fixed, although there is now another issue: attribute properties of type string[] like 'filenames' are not currently supported. Let's see if I can include support for this in the next release.

You can get the latest code from http://github.com/mono/mono-addins.

Nov 17, 2010 at 3:16 PM

Thanks a lot I will try it out later on. The problem with string[] is not so important. If need be I can work with comma-seperated strings and the split them (but of course native support would be nice to have).

Did you by any chance have time to take a look at the problem that custom attributes derived from CustomExtensionAttribute can not take a "Path" as a value? This means that if I define a path for a TypeExtensionPoint with a custom attribute it won't work because it internally looks for addins with the path defined for the extension point and using the defined attributes but as it is not possible to set a path for the addin it won't find anything.

This can be achived by replacing the TypeExtensionPoint definition from my previous example to:

[TypeExtensionPoint(Path = "some/path", ExtensionAttributeType = typeof (MetaDataSerializerAttribute))]
public interface IMetaDataSerializer : IAddin
{ ... }

without changing anything else.

 

Thanks again for your help and I'll report back whether it works or not.

Nov 18, 2010 at 9:43 PM

OK I just tried the latest git version and the error is gone. I also checked if it really reads the correct MetaData and it does (apart from the string[] which you already mentioned).

Thanks for your quick fix!