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


C# OrderedDictionary.AsReadOnly方法代码示例

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


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

示例1: GetReadOnlyDictionary

        public static IDictionary GetReadOnlyDictionary(IDictionary dictionary)
        {
            Guard.ArgumentNotNull(dictionary, "dictionary");

            OrderedDictionary result = new OrderedDictionary();
            foreach (DictionaryEntry entry in dictionary)
            {
                result.Add(entry.Key, entry.Value);
            }
            return result.AsReadOnly();
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:11,代码来源:DictionaryHelper.cs

示例2: Common

		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:OrderedDictionaryTest.cs

示例3: IsReadOnlyTests

 public void IsReadOnlyTests()
 {
     var d = new OrderedDictionary();
     Assert.False(d.IsReadOnly);
     var d2 = d.AsReadOnly();
     Assert.True(d2.IsReadOnly);
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:7,代码来源:OrderedDictionaryTests.cs

示例4: AsReadOnlyTests

        public void AsReadOnlyTests()
        {
            var _d = new OrderedDictionary();
            _d["foo"] = "bar";
            _d[(object)13] = 37;

            var d = _d.AsReadOnly();
            Assert.True(d.IsReadOnly);
            Assert.Equal("bar", d["foo"]);
            Assert.Equal(37, d[(object)13]);
            Assert.Throws<NotSupportedException>(() => { d["foo"] = "moooooooooaaah"; });
            Assert.Throws<NotSupportedException>(() => { d["asdasd"] = "moooooooooaaah"; });
            Assert.Equal(null, d["asdasd"]);
            Assert.Throws<ArgumentNullException>(() => { var a = d[null]; });
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:15,代码来源:OrderedDictionaryTests.cs

示例5: IsFixedSizeTests

 public void IsFixedSizeTests()
 {
     var d = new OrderedDictionary();
     IDictionary dic = d;
     IDictionary rodic = d.AsReadOnly();
     Assert.False(dic.IsFixedSize);
     Assert.True(rodic.IsFixedSize);
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:8,代码来源:OrderedDictionaryTests.cs

示例6: ModelDataMethodResult

 public ModelDataMethodResult(object returnValue, OrderedDictionary outputParameters) {
     ReturnValue = returnValue;
     outputParameters = outputParameters ?? new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
     _outputParameters = outputParameters.AsReadOnly();
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:5,代码来源:ModelDataMethodResult.cs

示例7: GetObjectData_IEqualityComparer

		public void GetObjectData_IEqualityComparer ()
		{
			EqualityComparer comparer = new EqualityComparer ();
			OrderedDictionary coll = new OrderedDictionary (comparer);
			coll.Add ("a", "1");
			coll.Add ("b", "2");
			coll = coll.AsReadOnly ();

			SerializationInfo si = new SerializationInfo (typeof (OrderedDictionary), new FormatterConverter ());
			coll.GetObjectData (si, new StreamingContext ());
			foreach (SerializationEntry se in si) {
				switch (se.Name) {
				case "KeyComparer":
					Assert.AreSame (comparer, se.Value, se.Name);
					break;
				case "ReadOnly":
					Assert.IsTrue ((bool) se.Value, se.Name);
					break;
				case "InitialCapacity":
					Assert.AreEqual (0, se.Value, se.Name);
					break;
				case "ArrayList":
					Assert.AreEqual (2, ((object[]) se.Value).Length, se.Name);
					break;
				default:
					string msg = String.Format ("Unexpected {0} information of type {1} with value '{2}'.",
						se.Name, se.ObjectType, se.Value);
					Assert.Fail (msg);
					break;
				}
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:OrderedDictionaryTest.cs

示例8: GetResolvedMethodData


//.........这里部分代码省略.........
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.Static |
                BindingFlags.FlattenHierarchy);

            MethodInfo matchedMethod = null;
            ParameterInfo[] matchedMethodParameters = null;


            int requiredParameterCount;
            if (oldDataObject == null) {
                requiredParameterCount = 1;
            }
            else {
                if (newDataObject == null) {
                    requiredParameterCount = 1;
                }
                else {
                    requiredParameterCount = 2;
                }
            }


            foreach (MethodInfo mi in methods) {
                if (String.Equals(methodName, mi.Name, StringComparison.OrdinalIgnoreCase)) {
                    if (mi.IsGenericMethodDefinition) {
                        // We do not support binding to generic methods, e.g. public void DoSomething<T>(T t)
                        continue;
                    }

                    ParameterInfo[] methodParameters = mi.GetParameters();

                    int methodParametersCount = methodParameters.Length;

                    if (methodParametersCount == requiredParameterCount) {
                        if (requiredParameterCount == 1 &&
                            methodParameters[0].ParameterType == dataObjectType) {
                            // Only one parameter, of proper type
                            // This is only valid for insert, delete, and non-optimistic update
                            matchedMethod = mi;
                            matchedMethodParameters = methodParameters;
                            break;
                        }
                        if (requiredParameterCount == 2 &&
                            methodParameters[0].ParameterType == dataObjectType &&
                            methodParameters[1].ParameterType == dataObjectType) {
                            // Two parameters of proper type in Update
                            // This is only valid for optimistic update
                            matchedMethod = mi;
                            matchedMethodParameters = methodParameters;
                            break;
                        }
                    }
                }
            }

            if (matchedMethod == null) {
                throw new InvalidOperationException(SR.GetString(SR.ObjectDataSourceView_MethodNotFoundForDataObject, _owner.ID, methodName, dataObjectType.FullName));
            }

            Debug.Assert(matchedMethodParameters != null, "Method parameters should not be null if a method was found");

            // Set up parameter array for method call
            OrderedDictionary parameters = new OrderedDictionary(2, StringComparer.OrdinalIgnoreCase);

            if (oldDataObject == null) {
                parameters.Add(matchedMethodParameters[0].Name, newDataObject);
            }
            else {
                if (newDataObject == null) {
                    parameters.Add(matchedMethodParameters[0].Name, oldDataObject);
                }
                else {
                    // We know that we matched on 2 objects for a optimistic update.
                    // Match the parameters based on the format string so we know which one is the old
                    // object and which is the new, then pass objects into the method in the correct order.
                    string param0Name = matchedMethodParameters[0].Name;
                    string param1Name = matchedMethodParameters[1].Name;
                    string formattedParamName = String.Format(CultureInfo.InvariantCulture, OldValuesParameterFormatString, param0Name);
                    if (String.Equals(param1Name, formattedParamName, StringComparison.OrdinalIgnoreCase)) {
                        parameters.Add(param0Name, newDataObject);
                        parameters.Add(param1Name, oldDataObject);
                    }
                    else {
                        formattedParamName = String.Format(CultureInfo.InvariantCulture, OldValuesParameterFormatString, param1Name);
                        if (String.Equals(param0Name, formattedParamName, StringComparison.OrdinalIgnoreCase)) {
                            parameters.Add(param0Name, oldDataObject);
                            parameters.Add(param1Name, newDataObject);
                        }
                        else {
                            throw new InvalidOperationException(SR.GetString(SR.ObjectDataSourceView_NoOldValuesParams, _owner.ID));
                        }
                    }
                }
            }

            // The parameters collection is always readonly in this case since we
            // do not want the user adding/removing the known objects.
            return new ObjectDataSourceMethod(operation, type, matchedMethod, parameters.AsReadOnly());
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:ObjectDataSourceView.cs

示例9: GetResolvedMethodData

 private ObjectDataSourceMethod GetResolvedMethodData(Type type, string methodName, Type dataObjectType, object oldDataObject, object newDataObject, DataSourceOperation operation)
 {
     int num;
     MethodInfo[] methods = type.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
     MethodInfo methodInfo = null;
     ParameterInfo[] infoArray2 = null;
     if (oldDataObject == null)
     {
         num = 1;
     }
     else if (newDataObject == null)
     {
         num = 1;
     }
     else
     {
         num = 2;
     }
     foreach (MethodInfo info2 in methods)
     {
         if (string.Equals(methodName, info2.Name, StringComparison.OrdinalIgnoreCase) && !info2.IsGenericMethodDefinition)
         {
             ParameterInfo[] parameters = info2.GetParameters();
             if (parameters.Length == num)
             {
                 if ((num == 1) && (parameters[0].ParameterType == dataObjectType))
                 {
                     methodInfo = info2;
                     infoArray2 = parameters;
                     break;
                 }
                 if (((num == 2) && (parameters[0].ParameterType == dataObjectType)) && (parameters[1].ParameterType == dataObjectType))
                 {
                     methodInfo = info2;
                     infoArray2 = parameters;
                     break;
                 }
             }
         }
     }
     if (methodInfo == null)
     {
         throw new InvalidOperationException(System.Web.SR.GetString("ObjectDataSourceView_MethodNotFoundForDataObject", new object[] { this._owner.ID, methodName, dataObjectType.FullName }));
     }
     OrderedDictionary dictionary = new OrderedDictionary(2, StringComparer.OrdinalIgnoreCase);
     if (oldDataObject == null)
     {
         dictionary.Add(infoArray2[0].Name, newDataObject);
     }
     else if (newDataObject == null)
     {
         dictionary.Add(infoArray2[0].Name, oldDataObject);
     }
     else
     {
         string name = infoArray2[0].Name;
         string a = infoArray2[1].Name;
         string b = string.Format(CultureInfo.InvariantCulture, this.OldValuesParameterFormatString, new object[] { name });
         if (string.Equals(a, b, StringComparison.OrdinalIgnoreCase))
         {
             dictionary.Add(name, newDataObject);
             dictionary.Add(a, oldDataObject);
         }
         else
         {
             b = string.Format(CultureInfo.InvariantCulture, this.OldValuesParameterFormatString, new object[] { a });
             if (!string.Equals(name, b, StringComparison.OrdinalIgnoreCase))
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("ObjectDataSourceView_NoOldValuesParams", new object[] { this._owner.ID }));
             }
             dictionary.Add(name, oldDataObject);
             dictionary.Add(a, newDataObject);
         }
     }
     return new ObjectDataSourceMethod(operation, type, methodInfo, dictionary.AsReadOnly());
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:76,代码来源:ObjectDataSourceView.cs


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