Пример #1
0
            public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                AApiVersionedFieldsCTD.TypedValuePropertyDescriptor pd = (AApiVersionedFieldsCTD.TypedValuePropertyDescriptor)context.PropertyDescriptor;
                IResourceKeyCTD     rkCTD = (IResourceKeyCTD)pd.GetValue(null);
                AApiVersionedFields owner = rkCTD.owner;
                string       field        = rkCTD.field;
                object       component    = rkCTD.component;
                IResourceKey rk           = (IResourceKey)AApiVersionedFieldsCTD.GetFieldValue(owner, field).Value;

                if (typeof(IResourceKey).IsAssignableFrom(value.GetType()))
                {
                    IResourceKey rkNew = (IResourceKey)value;
                    rk.ResourceType  = rkNew.ResourceType;
                    rk.ResourceGroup = rkNew.ResourceGroup;
                    rk.Instance      = rkNew.Instance;
                    return(rk);
                }
                if (value != null && value is string)
                {
                    if (AResourceKey.TryParse((string)value, rk))
                    {
                        return(rk);
                    }
                    else
                    {
                        throw new NotSupportedException("Invalid data: " + (string)value);
                    }
                }
                return(base.ConvertFrom(context, culture, value));
            }
Пример #2
0
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value != null && value.GetType().Equals(typeof(string)))
     {
         string str = ((string)value).Trim();
         try
         {
             AApiVersionedFieldsCTD.TypedValuePropertyDescriptor pd = (AApiVersionedFieldsCTD.TypedValuePropertyDescriptor)context.PropertyDescriptor;
             ulong num = Convert.ToUInt64(str, str.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase) ? 16 : 10);
             return(Convert.ChangeType(num, pd.FieldType));
         }
         catch (Exception ex) { throw new NotSupportedException("Invalid data: " + str, ex); }
     }
     return(base.ConvertFrom(context, culture, value));
 }/**/
Пример #3
0
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value != null && value.GetType().Equals(typeof(string)))
     {
         string[] content = ((string)value).Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
         string   str     = content[0];
         try
         {
             AApiVersionedFieldsCTD.TypedValuePropertyDescriptor pd = (AApiVersionedFieldsCTD.TypedValuePropertyDescriptor)context.PropertyDescriptor;
             ulong num = Convert.ToUInt64(str, str.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase) ? 16 : 10);
             return(Enum.ToObject(pd.FieldType, num));
         }
         catch (Exception ex) { throw new NotSupportedException("Invalid data: " + str, ex); }
     }
     return(base.ConvertFrom(context, culture, value));
 }
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
            {
                ICollectionAApiVersionedFieldsCTD ctd = value as ICollectionAApiVersionedFieldsCTD;
                ICollection ary = (ICollection)ctd.owner[ctd.field].Value;

                AApiVersionedFieldsCTD.TypedValuePropertyDescriptor[] pds = new AApiVersionedFieldsCTD.TypedValuePropertyDescriptor[ary.Count];
                string fmt = "[{0:X" + ary.Count.ToString("X").Length + "}] {1}";

                for (int i = 0; i < ary.Count; i++)
                {
                    try
                    {
                        pds[i] = new AApiVersionedFieldsCTD.TypedValuePropertyDescriptor(ctd.owner, String.Format(fmt, i, ctd.field), new Attribute[] { });
                    }
                    catch (Exception ex) { throw ex; }
                }
                return(new PropertyDescriptorCollection(pds));
            }
Пример #5
0
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
            {
                ArrayCTD            ctd   = value as ArrayCTD;
                AApiVersionedFields owner = new ArrayOwner(ctd.owner, ctd.field);
                Array  ary  = ctd.Value;
                Type   type = ary.GetType().GetElementType();
                string fmt  = type.Name + " [{0:X" + ary.Length.ToString("X").Length + "}]";

                AApiVersionedFieldsCTD.TypedValuePropertyDescriptor[] pds = new AApiVersionedFieldsCTD.TypedValuePropertyDescriptor[ary.Length];
                for (int i = 0; i < ary.Length; i++)
                {
                    try
                    {
                        pds[i] = new AApiVersionedFieldsCTD.TypedValuePropertyDescriptor(owner, String.Format(fmt, i), new Attribute[] { });
                    }
                    catch (Exception ex) { throw ex; }
                }
                return(new PropertyDescriptorCollection(pds));
            }
Пример #6
0
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value != null && value.GetType().Equals(typeof(string)))
     {
         AApiVersionedFieldsCTD.TypedValuePropertyDescriptor pd = (AApiVersionedFieldsCTD.TypedValuePropertyDescriptor)context.PropertyDescriptor;
         string v = value as string;
         try
         {
             if (v.Split(' ').Length > 1)
             {
                 v = v.Split(' ')[0];
             }
             if (new List <string>(Enum.GetNames(pd.FieldType)).Contains(v))
             {
                 return(Enum.Parse(pd.FieldType, v));
             }
             return(Enum.ToObject(pd.FieldType, Convert.ToUInt64(v, v.StartsWith("0x") ? 16 : 10)));
         }
         catch (Exception ex) { throw new NotSupportedException("Invalid data: " + v, ex); }
     }
     return(base.ConvertFrom(context, culture, value));
 }