Exemplo n.º 1
0
        public override IEnumerable <IField> GetFields(Predicate <IField> filter = null, GetMemberOptions options = GetMemberOptions.None)
        {
            // The fields from the underlying type (Item1..Item7 and Rest)
            foreach (var field in UnderlyingType.GetFields(filter, options))
            {
                yield return(field);
            }

            /*for (int i = 0; i < ElementTypes.Length; i++) {
             *      var type = ElementTypes[i];
             *      var name = ElementNames[i];
             *      int pos = i + 1;
             *      string itemName = "Item" + pos;
             *      if (name != itemName && name != null)
             *              yield return MakeField(type, name);
             *      if (pos >= RestPosition)
             *              yield return MakeField(type, itemName);
             * }*/
        }
Exemplo n.º 2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw new NotSupportedException("Cannot convert from (null).");
            }

            var valueString = value as string;

            if (valueString != null)
            {
                FieldInfo fieldInfo = UnderlyingType.GetFields().FirstOrDefault(info => valueString == GetDisplayName(info));

                if (fieldInfo != null)
                {
                    return(Enum.Parse(UnderlyingType, fieldInfo.Name));
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }