Silverfrost Forums

Welcome to our forums

ATTRIBUTE routine in .Net Fortran

11 Oct 2004 5:03 #63

Hello,

I would like to have more information, if possible, concerning the ATTRIBUTE functionality in Fortran .Net. Indeed, I created a CSharp attribute class with 2 fields (unit and parameter name fields). Here is the description of my C# class: [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] public class UnitAttribute:Attribute { private string sUnitName; private string sParamName;

	///<summary>
	/// Constructor of the UnitAttribute Class
	/// Used to initialise the unit name
	///</summary>
	public UnitAttribute(string name)
	{
		sUnitName = name;			
	}
	
	///<summary>
	/// Property to get the unit name
	///</summary>
	public string Unit
	{
		get
		{
			return sUnitName;
		}
	}
	
	///<summary>
	/// Property to get and set the name of the fortran parameter
	///</summary>
	public string ParameterName
	{
		get
		{
			return sParamName;
		}
		set
		{
			sParamName = value;
		}
	}

Now I would like to use it in the .Net fortran code... So I use the ATTRIBUTE routine as described in the help documentation: ATTRIBUTE(CLASS='MyNameSpace.UnitAttribute','m',Target = 'Routine'). This works fine, but I do not know how to assign the ParameterName property with the ATTRIBUTE routine. Thanks in advance for your help.

Patrick

13 Oct 2004 2:39 #64

Patrick,

There is no underlying access to the Attribute object itself when an Attribute has been attached to a routine (or class etc.). Because of this there is no way to dynamically change properties of the said Attribute. You could try using multiple arguments to the constructor to obtain an Attribute with multiple properties, but I am afraid there is a .NET linker bug relating to this which will be looked at by the Salford support team as soon as possible.

There is a possible work around you could use and this is illustrated by the following code:

C#

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class UnitAttribute:Attribute
{
    private string sUnitName;
    private string sParamName;
    
    public UnitAttribute(string[] names)
    {
        sUnitName = names[0]; 
        sParamName = names[1];
    }

    public string Unit
    {
        get
        {
            return sUnitName;
        }
    }

    public string ParameterName
    {
        get
        {
            return sParamName;
        }
    }
}

Fortran

ATTRIBUTE(CLASS='MyNameSpace.UnitAttribute',(/'a','b'/),Target = 'Routine')

Andrew

25 Oct 2004 12:16 #72

Just to let you know... the problem related to multiple arguments to an Attribute constructor has been fixed and will be available in the next release of the compiler.

Please login to reply.