public static AcNamedValues Parse(string InString) { AcNamedValues vlus = new AcNamedValues(); TextTraits traits = new TextTraits(); traits.OpenNamedBracedPatterns.Replace("[", Text.Enums.DelimClassification.OpenNamedBraced); traits.DividerPatterns.AddDistinct(",", Text.Enums.DelimClassification.DividerSymbol); WordCursor csr = Scanner.PositionBeginWord(InString, traits); while (true) { csr = Scanner.ScanNextWord(InString, csr); if (csr.IsEndOfString == true) { break; } else if ((csr.IsDelimOnly == false) && (csr.Word.Class == WordClassification.ContentBraced)) { KeyValuePair <string, string> pair = ParsePair(csr.Word.BracedText); vlus.Add(pair.Key, pair.Value); } else { throw new ApplicationException( "serialized AcNamedValues string in invalid format"); } } return(vlus); }
// convert from string to AcNamedValues public override object ConvertFrom( ITypeDescriptorContext context, CultureInfo culture, object InValue) { if (InValue is string) { return(AcNamedValues.Parse((string)InValue)); } else { return(base.ConvertFrom(context, culture, InValue)); } }
// Convert from AcNamedValue to string. public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object InValue, Type destinationType) { if (destinationType == typeof(string)) { AcNamedValues vlus = InValue as AcNamedValues; return(vlus.ToString()); } else { return(base.ConvertTo(context, culture, InValue, destinationType)); } }