コード例 #1
0
 public virtual String this[String name]
 {
     get
     {
         ITestProperty property = pinternal.Get(name);
         if (property != null)
         {
             return(StringEx.ToString(property.Value));
         }
         return(null);
     }
     set
     {
         this.Add(name).Value = value;
     }
 }
コード例 #2
0
 protected void AddValue(XElement element, string name, object value)
 {
     //Recurise through the value(s)
     if (value != null && value.GetType().HasElementType&& value is System.Collections.IEnumerable)
     {
         //Recurse through the values
         foreach (object item in (System.Collections.IEnumerable)value)
         {
             AddValue(element, name, item);
         }
     }
     else
     {
         element.SetElementValue(name, StringEx.ToString(value));
     }
 }
コード例 #3
0
        protected void AddProperty(XElement element, string name, object value, TestPropertyFlags flags)
        {
            //Ignore all the properties that have no name or value (as to not bloat the xml)
            if (name == null || value == null)
            {
                return;
            }

            //How to serialize (elements or attributes)
            if ((flags & TestPropertyFlags.MultipleValues) != 0)
            {
                AddValue(element, name, value);
            }
            else
            {
                element.SetAttributeValue(name, StringEx.ToString(value));
            }
        }
コード例 #4
0
 protected void                  AddValue(XmlNode element, string name, object value)
 {
     //Recurise through the value(s)
     if (value != null && value.GetType().HasElementType&& value is IEnumerable)
     {
         //Recurse through the values
         foreach (object item in (IEnumerable)value)
         {
             AddValue(element, name, item);
         }
     }
     else
     {
         //<node>value</node>
         XmlElement child = _xmldoc.CreateElement(name);
         child.InnerText = StringEx.ToString(value);
         element.AppendChild(child);
     }
 }
コード例 #5
0
        protected void                  AddProperty(XmlNode element, string name, object value, TestPropertyFlags flags)
        {
            //Ignore all the properties that have no name or value (as to not bloat the xml)
            if (name == null || value == null)
            {
                return;
            }

            //How to serialize (elements or attributes)
            if ((flags & TestPropertyFlags.MultipleValues) != 0)
            {
                //Property as Element
                AddValue(element, name, value);
            }
            else
            {
                //Property as Attribute
                XmlAttribute xmlattribute = _xmldoc.CreateAttribute(name);
                xmlattribute.Value = StringEx.ToString(value);
                element.Attributes.Append(xmlattribute);
            }
        }
コード例 #6
0
ファイル: testlog.cs プロジェクト: shandan1/CollectionRef
 public static void WriteLine(object value)
 {
     WriteLine(TestLogFlags.Text, StringEx.ToString(value));
 }
コード例 #7
0
        static public Dictionary <string, string> ParseKeywords(string str, Tokens tokens)
        {
            PARSE state    = PARSE.Initial;
            int   index    = 0;
            int   keyStart = 0;
            InsensitiveDictionary keywords = new InsensitiveDictionary(5);
            string key = null;

            if (str != null)
            {
                StringBuilder builder = new StringBuilder(str.Length);
                for (; index < str.Length; index++)
                {
                    char ch = str[index];
                    switch (state)
                    {
                    case PARSE.Initial:
                        if (Char.IsLetterOrDigit(ch))
                        {
                            keyStart = index;
                            state    = PARSE.Keyword;
                        }
                        break;

                    case PARSE.Keyword:
                        if (tokens.Seperator.IndexOf(ch) >= 0)
                        {
                            state = PARSE.Initial;
                        }
                        else if (tokens.Equal.IndexOf(ch) >= 0)
                        {
                            //Note: We have a case-insentive hashtable so we don't have to lowercase
                            key   = str.Substring(keyStart, index - keyStart).Trim();
                            state = PARSE.Equal;
                        }
                        break;

                    case PARSE.Equal:
                        if (Char.IsWhiteSpace(ch))
                        {
                            break;
                        }
                        builder.Length = 0;

                        //Note: Since we allow you to alter the tokens, these are not
                        //constant values, so we cannot use a switch statement...
                        if (tokens.SingleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.SingleBegin;
                        }
                        else if (tokens.DoubleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.DoubleBegin;
                        }
                        else if (tokens.Seperator.IndexOf(ch) >= 0)
                        {
                            keywords.Update(key, String.Empty);
                            state = PARSE.Initial;
                        }
                        else
                        {
                            state = PARSE.Value;
                            builder.Append(ch);
                        }
                        break;

                    case PARSE.Value:
                        if (tokens.Seperator.IndexOf(ch) >= 0)
                        {
                            keywords.Update(key, (builder.ToString()).Trim());
                            state = PARSE.Initial;
                        }
                        else
                        {
                            builder.Append(ch);
                        }
                        break;

                    case PARSE.SingleBegin:
                        if (tokens.SingleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.SingleEnd;
                        }
                        else
                        {
                            builder.Append(ch);
                        }
                        break;

                    case PARSE.DoubleBegin:
                        if (tokens.DoubleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.DoubleEnd;
                        }
                        else
                        {
                            builder.Append(ch);
                        }
                        break;

                    case PARSE.SingleEnd:
                        if (tokens.SingleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.SingleBegin;
                            builder.Append(ch);
                        }
                        else
                        {
                            keywords.Update(key, builder.ToString());
                            state = PARSE.End;
                            goto case PARSE.End;
                        }
                        break;

                    case PARSE.DoubleEnd:
                        if (tokens.DoubleQuote.IndexOf(ch) >= 0)
                        {
                            state = PARSE.DoubleBegin;
                            builder.Append(ch);
                        }
                        else
                        {
                            keywords.Update(key, builder.ToString());
                            state = PARSE.End;
                            goto case PARSE.End;
                        }
                        break;

                    case PARSE.End:
                        if (tokens.Seperator.IndexOf(ch) >= 0)
                        {
                            state = PARSE.Initial;
                        }
                        break;

                    default:
                        throw new TestFailedException("Unhandled State: " + StringEx.ToString(state));
                    }
                }

                switch (state)
                {
                case PARSE.Initial:
                case PARSE.Keyword:
                case PARSE.End:
                    break;

                case PARSE.Equal:
                    keywords.Update(key, String.Empty);
                    break;

                case PARSE.Value:
                    keywords.Update(key, (builder.ToString()).Trim());
                    break;

                case PARSE.SingleBegin:
                case PARSE.DoubleBegin:
                case PARSE.SingleEnd:
                case PARSE.DoubleEnd:
                    keywords.Update(key, builder.ToString());
                    break;

                default:
                    throw new TestFailedException("Unhandled State: " + StringEx.ToString(state));
                }
            }
            return(keywords);
        }