Пример #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
 /// <summary>
 /// Tests whether a string can be converted to an <see cref="IResourceKey"/> and,
 /// if so, sets <paramref name="result"/> to the converted value.
 /// </summary>
 /// <param name="value">A potential string representation of an <see cref="IResourceKey"/>.</param>
 /// <param name="result">The eqivalent <see cref="IResourceKey"/> value for <paramref name="value"/>.</param>
 /// <returns>True if <paramref name="value"/> has the format
 /// "0xHHHHHHHH-0xHHHHHHHH-0xHHHHHHHHHHHHHHHH"; otherwise false.
 /// </returns>
 public static bool TryParse(string value, out IResourceKey result)
 {
     result = new RK();
     return(AResourceKey.TryParse(value, result));
 }