Example #1
0
        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            if (value != null)
            {
                if (value != String.Empty)
                {
                    Type   declaringType = null;
                    String commandName;

                    // Check for "ns:Class.Command" syntax.

                    int dotIndex = value.IndexOf('.');
                    if (dotIndex >= 0)
                    {
                        // We have "ns:Class.Command" syntax.

                        // Find the type name in the form of "ns:Class".
                        string typeName = value.Substring(0, dotIndex);

                        if (context == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.ValueSerializerContextUnavailable, this.GetType().Name));
                        }

                        // Get the ValueSerializer for the System.Type type
                        ValueSerializer typeSerializer = context.GetValueSerializerFor(typeof(Type));
                        if (typeSerializer == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.TypeValueSerializerUnavailable, this.GetType().Name));
                        }


                        // Use the TypeValueSerializer to parse the "ns:Class" into a System.Type.
                        declaringType = typeSerializer.ConvertFromString(typeName, context) as Type;

                        // Strip out the "Command" part of "ns:Class.Command".
                        commandName = value.Substring(dotIndex + 1).Trim();
                    }
                    else
                    {
                        // Assume the known commands
                        commandName = value.Trim();
                    }

                    // Find the command given the declaring type & name (this is shared with CommandConverter)
                    ICommand command = CommandConverter.ConvertFromHelper(declaringType, commandName);

                    if (command != null)
                    {
                        return(command);
                    }
                }
                else
                {
                    return(null); // String.Empty <==> null , (for roundtrip cases where Command property values are null)
                }
            }

            return(base.ConvertFromString(value, context));
        }
Example #2
0
 // Token: 0x06001600 RID: 5632 RVA: 0x0006D280 File Offset: 0x0006B480
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     if (value != null)
     {
         if (!(value != string.Empty))
         {
             return(null);
         }
         Type   ownerType = null;
         int    num       = value.IndexOf('.');
         string localName;
         if (num >= 0)
         {
             string value2 = value.Substring(0, num);
             if (context == null)
             {
                 throw new InvalidOperationException(SR.Get("ValueSerializerContextUnavailable", new object[]
                 {
                     base.GetType().Name
                 }));
             }
             ValueSerializer valueSerializerFor = context.GetValueSerializerFor(typeof(Type));
             if (valueSerializerFor == null)
             {
                 throw new InvalidOperationException(SR.Get("TypeValueSerializerUnavailable", new object[]
                 {
                     base.GetType().Name
                 }));
             }
             ownerType = (valueSerializerFor.ConvertFromString(value2, context) as Type);
             localName = value.Substring(num + 1).Trim();
         }
         else
         {
             localName = value.Trim();
         }
         ICommand command = CommandConverter.ConvertFromHelper(ownerType, localName);
         if (command != null)
         {
             return(command);
         }
     }
     return(base.ConvertFromString(value, context));
 }