当前位置: 首页>>代码示例>>C#>>正文


C# AttributeCollection.Add方法代码示例

本文整理汇总了C#中AttributeCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeCollection.Add方法的具体用法?C# AttributeCollection.Add怎么用?C# AttributeCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AttributeCollection的用法示例。


在下文中一共展示了AttributeCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAddingExistingAttribute

        public void TestAddingExistingAttribute()
        {
            bool exceptionThrown;
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue existingAttributeValue = new AttributeValue("Test Value");

            try
            {
                attributes.Add("Test", existingAttributeValue);
                exceptionThrown = false;
            }
            catch (ArgumentException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:25,代码来源:AttributeCollectionTests.cs

示例2: TestParse

        public void TestParse()
        {
            var saxHandler = new Mock<ISaxHandler>();

              using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
              {
            memoryStream.Write(new System.Text.UTF8Encoding().GetBytes(_xmlToParse), 0, _xmlToParse.Length);
            memoryStream.Position = 0;

            SaxReaderImpl saxReaderImpl = new SaxReaderImpl();
            saxReaderImpl.Parse(new System.IO.StreamReader(memoryStream), saxHandler.Object);
              }

              AttributeCollection element3Attributes = new AttributeCollection();
              Attribute attr1Attribute = new Attribute();
              attr1Attribute.LocalName = "attr1";
              attr1Attribute.QName = "attr1";
              attr1Attribute.Uri = string.Empty;
              attr1Attribute.Value = "val1";
              element3Attributes.Add("attr1", attr1Attribute);

              saxHandler.Verify(c => c.StartDocument(), Times.Exactly(1));
              saxHandler.Verify(c => c.EndDocument(), Times.Exactly(1));
              saxHandler.Verify(c => c.StartElement(string.Empty, "root", "root", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element1", "element1", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element2", "element2", new AttributeCollection()));
              saxHandler.Verify(c => c.StartElement(string.Empty, "element3", "element3", element3Attributes));
              saxHandler.Verify(c => c.EndElement(string.Empty, "root", "root"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element1", "element1"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element2", "element2"));
              saxHandler.Verify(c => c.EndElement(string.Empty, "element3", "element3"));
              saxHandler.Verify(c => c.Characters(It.IsAny<char[]>(), It.IsAny<int>(), It.IsAny<int>()));
        }
开发者ID:hanson-andrew,项目名称:RockSolidIoc,代码行数:33,代码来源:SaxReadersImplFixture.cs

示例3: TestAddingAttributeWithValue

        public void TestAddingAttributeWithValue()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue comparisonAttributeValue = new AttributeValue("Value");

            attributes.Add("Name", comparisonAttributeValue);

            Assert.AreEqual<string>(comparisonAttributeValue.Value, attributes["Name"].Value);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:9,代码来源:AttributeCollectionTests.cs

示例4: CreateStateFriendlyNameMetaField

        public static void CreateStateFriendlyNameMetaField()
        {
            using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit())
            {
                MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass();

                AttributeCollection attr = new AttributeCollection();
                attr.Add(McDataTypeAttribute.StringMaxLength, 255);
                attr.Add(McDataTypeAttribute.StringIsUnique, false);
                attr.Add(McDataTypeAttribute.Expression,
                        @"SELECT TOP 1 TTBS.FriendlyName FROM cls_TimeTrackingBlock_State TTBS" + Environment.NewLine +
                        @"	JOIN cls_TimeTrackingBlock TTB ON " + Environment.NewLine +
                        @"	TTB.mc_StateId = TTBS.TimeTrackingBlock_StateId" + Environment.NewLine +
                        @"	AND" + Environment.NewLine +
                        @"	TTB.[TimeTrackingBlockId] = AAA.[ParentBlockId]");

                MetaField retVal = timeTrackingEntry.CreateMetaField("StateFriendlyName",
                    "State", MetaFieldType.Text, true, "''", attr);

                scope.SaveChanges();
            }
        }
开发者ID:0anion0,项目名称:IBN,代码行数:22,代码来源:TimeTrackingEntry.cs

示例5: TestAddingWithNullAttribute

        public void TestAddingWithNullAttribute()
        {
            bool exceptionThrown;
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue comparisonAttributeValue = new AttributeValue("Value");

            try
            {
                attributes.Add(null, comparisonAttributeValue);
                exceptionThrown = false;
            }
            catch (ArgumentNullException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:18,代码来源:AttributeCollectionTests.cs

示例6: CreateAttributeCollection

        public virtual AttributeCollection CreateAttributeCollection(SlpReader reader)
        {
            var tmp = reader.ReadRawString();

            var result = new AttributeCollection();
            foreach (var item in tmp.Split(','))
            {
                var pair = item.Split('=');
                string key = null, value = null;
                if (pair.Length == 1)
                    key = reader.Unescape(pair[0]);
                else if (pair.Length == 2)
                {
                    key = reader.Unescape(pair[0]);
                    value = reader.Unescape(pair[1]);
                }
                else
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);

                result.Add(key, value);
            }

            return result;
        }
开发者ID:simongh,项目名称:slpnet,代码行数:24,代码来源:EntityFactory.cs

示例7: TestUpdatingIdenticalAttribute

        public void TestUpdatingIdenticalAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            // Try updating the attribute with the same value
            attributes.Update("Test", newAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:16,代码来源:AttributeCollectionTests.cs

示例8: TestUpdatingAttribute

        public void TestUpdatingAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue updatedAttributeValue = new AttributeValue("New Test Value");

            // Add attribute and attribute value
            attributes.Update("Test", updatedAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(updatedAttributeValue.Value, attributes["Test"].Value);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:18,代码来源:AttributeCollectionTests.cs

示例9: TestSuccessfullCheckIfAttributeExists

        public void TestSuccessfullCheckIfAttributeExists()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add the attribute
            attributes.Add("Test", newAttributeValue);

            Assert.IsTrue(attributes.ContainsAttribute("Test"));
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:10,代码来源:AttributeCollectionTests.cs

示例10: TestRemovingInvalidAttribute

        public void TestRemovingInvalidAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.IsFalse(attributes.Remove("Test5"));
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:11,代码来源:AttributeCollectionTests.cs

示例11: TestGettingAnAttributeThatExists

        public void TestGettingAnAttributeThatExists()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add the attribute
            attributes.Add("Test", newAttributeValue);

            // Check if the attribute exists (by name)
            Assert.AreEqual<AttributeValue>(attributes.GetAttributeValue("Test"), newAttributeValue);
            Assert.AreEqual<AttributeValue>(attributes["Test"], newAttributeValue);

            // Check if the attribute exists (by attribute)
            Assert.AreEqual<AttributeValue>(attributes.GetAttributeValue("Test"), newAttributeValue);
            Assert.AreEqual<AttributeValue>(attributes["Test"], newAttributeValue);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:16,代码来源:AttributeCollectionTests.cs

示例12: TestEnumeratingAttributeValues

        public void TestEnumeratingAttributeValues()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual<int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            List<AttributeValue> attributeValues = new List<AttributeValue>(attributes.AttributeValues);
            for (int i = 1; i <= attributeValues.Count; i++)
            {
                Assert.AreEqual<string>(attributeValues[i - 1].Value, "Test Value" + i);
            }
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:17,代码来源:AttributeCollectionTests.cs

示例13: TestCountingCollectionItems

        public void TestCountingCollectionItems()
        {
            AttributeCollection attributes = new AttributeCollection();

            Assert.AreEqual<int>(0, attributes.Count);

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.AreEqual<int>(4, attributes.Count);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:13,代码来源:AttributeCollectionTests.cs

示例14: TestCollectionChangedWithUpdatee

        public void TestCollectionChangedWithUpdatee()
        {
            AttributeCollection attributes = new AttributeCollection();

            bool eventRaised = false;
            NotifyCollectionChangedAction action = NotifyCollectionChangedAction.Reset;
            int newIndex = -1;
            string newAttributeName = string.Empty;
            AttributeValue newAttributeValue = null;
            int oldIndex = -1;
            string oldAttributeName = string.Empty;
            AttributeValue oldAttributeValue = null;

            attributes.Add("Test1", new AttributeValue("Test Value1"));

            // Setup the event handler
            attributes.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                action = e.Action;
                newAttributeName = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Key : string.Empty;
                newAttributeValue = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Value : null;
                newIndex = e.NewStartingIndex;
                oldAttributeName = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Key : string.Empty;
                oldAttributeValue = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Value : null;
                oldIndex = e.OldStartingIndex;

                eventRaised = true;
            };

            // Make change to property
            EnqueueCallback(() => attributes.Update("Test1", new AttributeValue("Updated Value1")));

            // Wait for event to complete
            EnqueueConditional(() => eventRaised != false);

            // Test that event was appropriately fires and handled
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", oldAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", newAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test Value1", oldAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<string>("Updated Value1", newAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<NotifyCollectionChangedAction>(action, NotifyCollectionChangedAction.Replace));

            // Reset testing fields
            EnqueueCallback(() => action = NotifyCollectionChangedAction.Reset);
            EnqueueCallback(() => newAttributeName = string.Empty);
            EnqueueCallback(() => newAttributeValue = null);
            EnqueueCallback(() => newIndex = -1);
            EnqueueCallback(() => oldAttributeName = string.Empty);
            EnqueueCallback(() => oldAttributeValue = null);
            EnqueueCallback(() => oldIndex = -1);
            EnqueueCallback(() => eventRaised = false);

            EnqueueTestComplete();
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:54,代码来源:AttributeCollectionTests.cs

示例15: CreateNewMetaField

        /// <summary>
        /// Creates the new meta field.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        public static MetaField CreateNewMetaField(DataColumn column)
        {
            if (column == null)
                throw new ArgumentNullException("column");

            MetaField retVal = null;

            string name = GetFieldName(column);
            string friendlyName = string.IsNullOrEmpty(column.ColumnName) ? name : column.ColumnName; // TODO:
            bool isNullable = column.AllowDBNull;// true;

            if (column.DataType == typeof(Int32) ||
                column.DataType == typeof(Int16))
            {
                #region MetaFieldType.Integer
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Integer, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Double) ||
                column.DataType == typeof(Single))
            {
                #region MetaFieldType.Float
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                attr.Add(McDataTypeAttribute.DecimalPrecision, 18);
                attr.Add(McDataTypeAttribute.DecimalScale, 4);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Decimal, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(DateTime))
            {
                #region MetaFieldType.DateTime
                AttributeCollection attr = new AttributeCollection();
                string defaultValue = isNullable ? string.Empty : "getutcdate()";

                //Attr.Add(McDataTypeAttribute.DateTimeMinValue, minValue);
                //Attr.Add(McDataTypeAttribute.DateTimeMaxValue, maxValue);
                //attr.Add(McDataTypeAttribute.DateTimeUseUserTimeZone, useUserTimeZone);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.DateTime, isNullable, defaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Boolean))
            {
                #region MetaFieldType.CheckboxBoolean
                AttributeCollection attr = new AttributeCollection();
                string strDefaultValue = "0";

                attr.Add(McDataTypeAttribute.BooleanLabel, friendlyName);

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.CheckboxBoolean, isNullable, strDefaultValue, attr);

                #endregion
            }
            else if (column.DataType == typeof(Guid))
            {
                #region MetaFieldType.Guid
                AttributeCollection attr = new AttributeCollection();
                string defaultValue = isNullable ? string.Empty : "newid()";

                retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Guid, isNullable, defaultValue, attr);

                #endregion
            }
            else // if (column.DataType == typeof(String))
            {
                if (column.MaxLength != -1) // Text
                {
                    #region MetaFieldType.Text
                    AttributeCollection attr = new AttributeCollection();
                    string strDefaultValue = isNullable ? string.Empty : "''";

                    attr.Add(McDataTypeAttribute.StringMaxLength, column.MaxLength);
                    attr.Add(McDataTypeAttribute.StringIsUnique, column.Unique);

                    retVal = CreateNewMetaField(name, friendlyName, MetaFieldType.Text, isNullable, strDefaultValue, attr);

                    #endregion
                }
                //else if (column.MaxLength == -1)
                //{
                //    #region MetaFieldType.Text 255 Length
                //    AttributeCollection attr = new AttributeCollection();
                //    string strDefaultValue = isNullable ? string.Empty : "''";

                //    attr.Add(McDataTypeAttribute.StringMaxLength, 255);
                //    attr.Add(McDataTypeAttribute.StringIsUnique, false);
//.........这里部分代码省略.........
开发者ID:0anion0,项目名称:IBN,代码行数:101,代码来源:ListImportParameters.cs


注:本文中的AttributeCollection.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。