Oh, one of those -- an excellent exercise. According to the file date, I wrote the following last October (probably in response to a post here):
namespace PIEBALD.Lib.LibExt.Convert
{
public interface IConvert
{
double Convert ( double Value ) ;
}
public enum Language
{
CSharp
,
VisualBasic
}
\[System.AttributeUsageAttribute(System.AttributeTargets.Field , AllowMultiple=false , Inherited=false)\]
public sealed class ConverterAttribute : System.Attribute
{
public ConverterAttribute
(
string Function
,
Language Language
)
{
this.Function = Function ;
this.Language = Language ;
return ;
}
public string Function { get ; private set ; }
public Language Language { get ; private set ; }
}
public enum Conversion
{
\[ConverterAttribute("Value \* 2.54",Language.VisualBasic)\]
FromInchToCentimeter
,
\[ConverterAttribute("Value / 2.54",Language.VisualBasic)\]
FromCentimeterToInch
,
\[ConverterAttribute("( Value - 32.0 ) \* 5.0 / 9.0",Language.CSharp)\]
FromFahrenheitToCelsius
,
\[ConverterAttribute("Value \* 9.0 / 5.0 + 32.0",Language.CSharp)\]
FromCelsiusToFahrenheit
}
public static class LibExt
{
private static readonly System.Collections.Generic.Dictionary<Conversion,IConvert> conversion ;
static LibExt
(
)
{
conversion = new System.Collections.Generic.Dictionary<Conversion,IConvert>() ;
return ;
}
private static void
Add
(
Conversion Conversion
)
{
System.Reflection.FieldInfo fi = typeof(Conversion).GetField
(
Conversion.ToString()
,
System.Reflection.BindingFlags.Public
|
System.Reflection.BindingFlags.Static
) ;
foreach
(
ConverterAttribute att
in
fi.GetCustomAttributes ( typeof(ConverterAttribute) , false )
)
{
string code = null ;
switch ( att.Language )
{
case Language.CSharp :
{