I have a fragment of C# code that looks like this:
[OracleCustomTypeMapping(Constants.DBSchema + ".TAB_VARCHAR2_250")]
public class StringTableFactory : TableFactoryTemplate<StringTable>
{
    public override System.Array CreateStatusArray(int length)
    {
        return new OracleUdtStatus[length];
    }
}
Is there any way to change the attribute declaration, so Constants.DBSchema is read from web.config instead of having it hardcoded as a constant in code? If I put ConfigurationManager.appSettings in the attribute declaration, I am getting "An attribute argument must be a constant expression..." error.
Thanks.
Rather than passing it in as part of the constructor arguments, read it direct from the ConfigurationManager in the Attribute's constructor.
public class OracleCustomTypeMappingAttribute : Attribute
{
    public OracleCustomTypeMappingAttribute(string typeName)
    {
        var schema = ConfigurationManager.AppSettings["Schema"];
        TypeMapping = schema + "." + typeName;
        // Or whatever property needs to be set
    }
}
Then you would just do:
[OracleCustomTypeMapping("TAB_VARCHAR2_250")]
public class StringTableFactory : TableFactoryTemplate<StringTable>
{
    public override System.Array CreateStatusArray(int length)
    {
        return new OracleUdtStatus[length];
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With