Exemple #1
0
 /// <summary>
 /// Returns a user-friendly name for an accelerator type.
 /// </summary>
 /// <param name="profileType">The profile to return a name for.</param>
 /// <returns>A user friendly name.</returns>
 /// <remarks>
 /// Adapted from https://codereview.stackexchange.com/questions/157871/method-that-returns-description-attribute-of-enum-value.</remarks>
 public static string ToFriendlyName(this ProfileType profileType)
 {
     return
         (profileType
          .GetType()
          .GetMember(profileType.ToString())
          .FirstOrDefault()
          ?.GetCustomAttribute <DescriptionAttribute>()
          ?.Description
          ?? profileType.ToString());
 }
Exemple #2
0
        /// <exception cref="System.MemberAccessException" />
        /// <exception cref="System.Reflection.TargetInvocationException" />
        public virtual object Create(bool initEarly)
        {
            ThrowHelper.ThrowIfNull(ClassName, "className");

            object obj = null;

            try
            {
                obj = Activator.CreateInstance(ProfileType.GetType(ClassName));
            }
            catch (TypeLoadException e)
            {
                throw new ConfigException(e);
            }
            ParameterMapping.Mapping(obj, Params);
            if (initEarly && obj is IInitializable)
            {
                ((IInitializable)obj).Init();
            }
            return(obj);
        }
Exemple #3
0
        public static string GetDescription(this ProfileType value)
        {
            var type = value.GetType();
            var name = Enum.GetName(type, value);

            if (name != null)
            {
                var field = type.GetField(name);
                if (field != null)
                {
                    var attr =
                        Attribute.GetCustomAttribute(field,
                                                     typeof(DescriptionAttribute)) as DescriptionAttribute;
                    if (attr != null)
                    {
                        return(attr.Description);
                    }
                }
            }
            return(null);
        }