using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Revit.SDK.Samples.ProjectInfo.CS
{
///
/// Converter for Enumeration types of RevitAPI
///
public abstract class RevitEnumConverter : EnumConverter
{
#region Fields
///
/// Dictionary contains enum and string map
///
Dictionary m_map = null;
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected abstract Dictionary EnumMap
{
get;
}
#endregion
#region Constructors
///
/// Initialize private variables
///
/// Enumeration type
public RevitEnumConverter(Type type)
: base(type)
{
m_map = EnumMap;
}
#endregion
#region Methods
///
/// Returns a collection of standard values from the default context for the
/// data type this type converter is designed for.
///
/// All enum items
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(m_map.Keys);
}
///
/// Returns an enum item from a string
///
/// An System.ComponentModel.ITypeDescriptorContext
/// that provides a format context.
/// An optional System.Globalization.CultureInfo.
/// If not supplied, the current culture is assumed.
/// string to be converted to
/// An enum item
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
object enumValue = value;
string valueText = value.ToString();
foreach (KeyValuePair pair in m_map)
{
if (pair.Value == valueText)
{
enumValue = pair.Key.ToString();
}
}
return base.ConvertFrom(context, culture, enumValue);
}
///
/// Convert enum item to string
///
/// An ITypeDescriptorContext that provides a format context.
/// A CultureInfo. If null is passed, the current culture is assumed.
/// The Object to convert.
/// The Type to convert the value parameter to.
/// Corresponding string related with the enum item
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
object enumValue = base.ConvertTo(context, culture, value, destinationType);
object enumObject = Enum.Parse(this.EnumType, enumValue.ToString());
return m_map[enumObject];
}
#endregion
};
///
/// Converter for BuildingType
///
public class BuildingTypeConverter : RevitEnumConverter
{
#region Constructors
///
/// Constructor
///
/// enumeration type
public BuildingTypeConverter(Type type) : base(type) { }
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected override Dictionary EnumMap
{
get
{
return RevitStartInfo.BuildingTypeMap;
}
}
#endregion
};
///
/// Converter for ExportComplexityConverter
///
public class ExportComplexityConverter : RevitEnumConverter
{
#region Constructors
///
/// Constructor
///
/// enumeration type
public ExportComplexityConverter(Type type) : base(type) { }
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected override Dictionary EnumMap
{
get
{
return RevitStartInfo.ExportComplexityMap;
}
}
#endregion
};
///
/// Converter for ServiceType
///
public class ServiceTypeConverter : RevitEnumConverter
{
#region Constructors
///
/// Constructor
///
/// enumeration type
public ServiceTypeConverter(Type type) : base(type) { }
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected override Dictionary EnumMap
{
get
{
return RevitStartInfo.ServiceTypeMap;
}
}
#endregion
};
///
/// Converter for HVACLoadLoadsReportType
///
public class HVACLoadLoadsReportTypeConverter : RevitEnumConverter
{
#region Constructors
///
/// Constructor
///
/// enumeration type
public HVACLoadLoadsReportTypeConverter(Type type) : base(type) { }
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected override Dictionary EnumMap
{
get
{
return RevitStartInfo.HVACLoadLoadsReportTypeMap;
}
}
#endregion
};
///
/// Converter for HVACLoadConstructionClass
///
public class HVACLoadConstructionClassConverter : RevitEnumConverter
{
#region Constructors
///
/// Constructor
///
/// enumeration type
public HVACLoadConstructionClassConverter(Type type) : base(type) { }
#endregion
#region Properties
///
/// Gets the enum-string map
///
protected override Dictionary EnumMap
{
get
{
return RevitStartInfo.HVACLoadConstructionClassMap;
}
}
#endregion
};
}