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


C# Hashtable.Clone方法代码示例

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


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

示例1: OnPostprocessAllAssets

 static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
 {
     foreach (var ass in importedAssets)
     {
         if (ass.EndsWith(".txt"))
         {
             StreamReader sr = new StreamReader(ass);
             var s = sr.ReadLine();
             if (s == "[Terrain Importer]")
             {
                 var baseparam = new Hashtable();
                 baseparam["terrainWidth"] = "1000";
                 baseparam["terrainHeight"] = "200";
                 baseparam["terrainLength"] = "1000";
                 baseparam["terrainTileX"] = "0";
                 baseparam["terrainTileY"] = "0";
                 baseparam["equalizeLayers"] = 0;
                 baseparam["heightFormat"] = "r16littleendian";
                 var param = (Hashtable)baseparam.Clone();
                 var currentoutput = "";
                 while (sr.Peek() >= 0)
                 {
                     s = sr.ReadLine();
                     if (s.StartsWith("[") && s.EndsWith("]"))
                     {
                         if (currentoutput == "")
                         {
                             baseparam = (Hashtable)param.Clone();
                         }
                         else
                         {
                             GenerateTerrain(currentoutput, param, Path.GetDirectoryName(ass));
                         }
                         currentoutput = s.Substring(1, s.Length - 2);
                         param = (Hashtable)baseparam.Clone();
                     }
                     else if (s == "" || s.StartsWith("//") || s.StartsWith("#"))
                     {
                         
                     }
                     else
                     {
                         var kv = s.Split("="[0]);
                         param[kv[0]] = kv[1];
                     }
                 }
                 if (currentoutput == "")
                 {
                     GenerateTerrain(Path.GetFileNameWithoutExtension(ass) + "-terrain", param, Path.GetDirectoryName(ass));
                 }
                 else
                 {
                     GenerateTerrain(currentoutput, param, Path.GetDirectoryName(ass));
                 }
             }
             sr.Close();
         }
     }
 }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:59,代码来源:TerrainImporter.cs

示例2: TestCloneShallowCopyReferenceTypes

        public void TestCloneShallowCopyReferenceTypes()
        {
            //[]Clone is a shallow copy, so the objects of the objets reference should be the same
            string strValue;

            var hsh1 = new Hashtable();
            for (int i = 0; i < 10; i++)
            {
                hsh1.Add(i, new Foo());
            }

            var hsh2 = (Hashtable)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "Hello World";
                Assert.True(strValue.Equals(((Foo)hsh2[i]).strValue), "Error, Expected value not returned, " + strValue);
            }

            strValue = "Good Bye";
            ((Foo)hsh1[0]).strValue = strValue;
            Assert.True(strValue.Equals(((Foo)hsh1[0]).strValue), "Error, Expected value not returned, " + strValue);

            //da test
            Assert.True(strValue.Equals(((Foo)hsh2[0]).strValue), "Error, Expected value not returned, " + strValue);

            //if we change the object, of course, the previous should not happen
            hsh2[0] = new Foo();

            strValue = "Good Bye";
            Assert.True(strValue.Equals(((Foo)hsh1[0]).strValue), "Error, Expected value not returned, " + strValue);

            strValue = "Hello World";
            Assert.True(strValue.Equals(((Foo)hsh2[0]).strValue), "Error, Expected value not returned, " + strValue);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:34,代码来源:CloneTests.cs

示例3: Start

    void Start(){
    	playerDelegate = gameObject.GetComponent<PlayerDelegate>();

    	inputList = new Hashtable();
    	inputList.Add("X thrust", "X thrust");
    	inputList.Add("Z thrust", "Z thrust");
    	inputList.Add("Roll thrust", "Roll thrust");
    	inputList.Add("Mouse X", "Mouse X");
    	inputList.Add("Mouse Y", "Mouse Y");
    	inputList.Add("Fire left", "Fire left");
    	inputList.Add("Fire right", "Fire right");
    	inputList.Add("Shield left", "Shield left");
    	inputList.Add("Shield right", "Shield right");
    	inputList.Add("Camera select", "Camera select");
    	inputList.Add("Boost left", "Boost left");
    	inputList.Add("Boost right", "Boost right");
    	inputList.Add("Boost up", "Boost up");
    	inputList.Add("Boost down", "Boost down");
    	inputList.Add("Pause", "Pause");
    	foreach(string key in ((Hashtable)inputList.Clone()).Keys){
    		if(player2){
    			inputList[key] = inputList[key] + " 2";
    		}
    	}

		if(player2){
    		controllerName = Input.GetJoystickNames()[1];
    	}
    	else{
    		controllerName = Input.GetJoystickNames()[0];
    	}
    	if(controllerName == "Controller (Xbox 360 Wireless Receiver for Windows)"){
    		isXboxController = true;
    		isPs4Controller = false;
    		Debug.Log("Xbox controller");
    	}else if(controllerName == "Ps4 controller name"){
    		isXboxController = false;
    		isPs4Controller = true;
    		Debug.Log("Ps4 controller");
    	}else{
    		isXboxController = false;
    		isPs4Controller = false;
    		Debug.Log("Some other controller");
    	}
    	if(player2){
    		joystickNumber = 2;
    	}else{
    		joystickNumber = 1;
    	}

    	dpadThreshold = 0.1f;
    	fireThreshold = 0.1f;
    	
    	leftWeaponFiring = false;
    	rightWeaponFiring = false;

    	boosting = false;
    }
开发者ID:biikatto,项目名称:zeroweight,代码行数:58,代码来源:PlayerControl.cs

示例4: PerformActionOnAllHashtableWrappers

        public static void PerformActionOnAllHashtableWrappers(Hashtable hashtable, Action<Hashtable> action)
        {
            // Synchronized returns a slightly different version of Hashtable
            Hashtable[] hashtableTypes =
            {
                (Hashtable)hashtable.Clone(),
                Hashtable.Synchronized(hashtable)
            };

            foreach (Hashtable hashtableType in hashtableTypes)
            {
                action(hashtableType);
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:14,代码来源:Helpers.cs

示例5: TestCloneBasic

        public void TestCloneBasic()
        {
            Hashtable hsh1;
            Hashtable hsh2;

            string strKey;
            string strValue;

            //[] empty Hashtable clone
            hsh1 = new Hashtable();
            hsh2 = (Hashtable)hsh1.Clone();

            Assert.Equal(0, hsh2.Count);
            Assert.False(hsh2.IsReadOnly, "Error, Expected value not returned, <<" + hsh1.IsReadOnly + ">> <<" + hsh2.IsReadOnly + ">>");
            Assert.False(hsh2.IsSynchronized, "Error, Expected value not returned, <<" + hsh1.IsSynchronized + ">> <<" + hsh2.IsSynchronized + ">>");

            //[] Clone should exactly replicate a collection to another object reference
            //afterwards these 2 should not hold the same object references
            hsh1 = new Hashtable();
            for (int i = 0; i < 10; i++)
            {
                strKey = "Key_" + i;
                strValue = "string_" + i;
                hsh1.Add(strKey, strValue);
            }

            hsh2 = (Hashtable)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "string_" + i;

                Assert.True(strValue.Equals((string)hsh2["Key_" + i]), "Error, Expected value not returned, " + strValue);
            }

            //now we remove an object from the original list
            hsh1.Remove("Key_9");
            Assert.Equal(hsh1["Key_9"], null);

            strValue = "string_" + 9;
            Assert.True(strValue.Equals((string)hsh2["Key_9"]), "Error, Expected value not returned, <<" + hsh1[9] + ">>");

            //[]now we try other test cases
            //are all the 'other' properties of the Hashtable the same?
            hsh1 = new Hashtable(1000);
            hsh2 = (Hashtable)hsh1.Clone();

            Assert.Equal(hsh1.Count, hsh2.Count);
            Assert.Equal(hsh1.IsReadOnly, hsh2.IsReadOnly);
            Assert.Equal(hsh1.IsSynchronized, hsh2.IsSynchronized);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:50,代码来源:CloneTests.cs

示例6: TestClonedHashtableSameAsOriginal

        public void TestClonedHashtableSameAsOriginal()
        {
            string strKey;
            string strValue;

            //1) create a HT, add elements
            //2) create another HT out of the first
            //3) Remove elements from 2) and add
            //4) Clone 3)
            var hsh1 = new Hashtable();
            for (int i = 0; i < 10; i++)
            {
                strKey = "Key_" + i;
                strValue = "string_" + i;
                hsh1.Add(strKey, strValue);
            }

            var hsh2 = new Hashtable(hsh1);
            hsh2.Remove("Key_0");
            hsh2.Remove("Key_1");
            hsh2.Remove("Key_2");

            Assert.Equal(hsh2.Count, 7);
            hsh2["Key_10"] = "string_10";
            hsh2["Key_11"] = "string_11";
            hsh2["Key_12"] = "string_12";

            var hsh3 = (Hashtable)hsh2.Clone();

            Assert.Equal(10, hsh3.Count);

            for (int i = 3; i < 13; i++)
            {
                Assert.True(hsh3.Contains("Key_" + i));
                Assert.True(hsh3.ContainsKey("Key_" + i));
                Assert.True(hsh3.ContainsValue("string_" + i));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:38,代码来源:CloneTests.cs

示例7: addAction

 public virtual void addAction(Action<Hashtable> actionFunction, Hashtable actArg)
 {
     this.actionFunction = actionFunction.Clone() as Action<Hashtable>;
     actionFunctionArgs = actArg.Clone() as Hashtable;
 }
开发者ID:holycattle,项目名称:towercraft,代码行数:5,代码来源:BaseEvent.cs

示例8: TestCanCastClonedHashtableToInterfaces

        public void TestCanCastClonedHashtableToInterfaces()
        {
            ICollection icol1;
            IDictionary idic1;
            Hashtable iclone1;

            //[]we try to cast the returned object from Clone() to different types
            var hsh1 = new Hashtable();

            icol1 = (ICollection)hsh1.Clone();
            Assert.Equal(hsh1.Count, icol1.Count);

            idic1 = (IDictionary)hsh1.Clone();
            Assert.Equal(hsh1.Count, idic1.Count);

            iclone1 = (Hashtable)hsh1.Clone();
            Assert.Equal(hsh1.Count, iclone1.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:18,代码来源:CloneTests.cs

示例9: ColorFrom

 public static void ColorFrom(GameObject target, Hashtable args)
 {
     Color color = default(Color);
     Color color2 = default(Color);
     args = iTween.CleanArgs(args);
     if (!args.Contains("includechildren") || (bool)args["includechildren"])
     {
         foreach (Transform transform in target.transform)
         {
             Hashtable hashtable = (Hashtable)args.Clone();
             hashtable["ischild"] = true;
             iTween.ColorFrom(transform.gameObject, hashtable);
         }
     }
     if (!args.Contains("easetype"))
     {
         args.Add("easetype", iTween.EaseType.linear);
     }
     if (target.GetComponent(typeof(GUITexture)))
     {
         color = (color2 = target.GetComponent<GUITexture>().color);
     }
     else if (target.GetComponent(typeof(GUIText)))
     {
         color = (color2 = target.GetComponent<GUIText>().material.color);
     }
     else if (target.GetComponent<Renderer>())
     {
         color = (color2 = target.GetComponent<Renderer>().material.color);
     }
     else if (target.GetComponent<Light>())
     {
         color = (color2 = target.GetComponent<Light>().color);
     }
     if (args.Contains("color"))
     {
         color = (Color)args["color"];
     }
     else
     {
         if (args.Contains("r"))
         {
             color.r = (float)args["r"];
         }
         if (args.Contains("g"))
         {
             color.g = (float)args["g"];
         }
         if (args.Contains("b"))
         {
             color.b = (float)args["b"];
         }
         if (args.Contains("a"))
         {
             color.a = (float)args["a"];
         }
     }
     if (args.Contains("amount"))
     {
         color.a = (float)args["amount"];
         args.Remove("amount");
     }
     else if (args.Contains("alpha"))
     {
         color.a = (float)args["alpha"];
         args.Remove("alpha");
     }
     if (target.GetComponent(typeof(GUITexture)))
     {
         target.GetComponent<GUITexture>().color = color;
     }
     else if (target.GetComponent(typeof(GUIText)))
     {
         target.GetComponent<GUIText>().material.color = color;
     }
     else if (target.GetComponent<Renderer>())
     {
         target.GetComponent<Renderer>().material.color = color;
     }
     else if (target.GetComponent<Light>())
     {
         target.GetComponent<Light>().color = color;
     }
     args["color"] = color2;
     args["type"] = "color";
     args["method"] = "to";
     iTween.Launch(target, args);
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:88,代码来源:iTween.cs

示例10: ColorTo

 public static void ColorTo(GameObject target, Hashtable args)
 {
     args = iTween.CleanArgs(args);
     if (!args.Contains("includechildren") || (bool)args["includechildren"])
     {
         foreach (Transform transform in target.transform)
         {
             Hashtable hashtable = (Hashtable)args.Clone();
             hashtable["ischild"] = true;
             iTween.ColorTo(transform.gameObject, hashtable);
         }
     }
     if (!args.Contains("easetype"))
     {
         args.Add("easetype", iTween.EaseType.linear);
     }
     args["type"] = "color";
     args["method"] = "to";
     iTween.Launch(target, args);
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:20,代码来源:iTween.cs

示例11: ColorTo

    /// <summary>
    /// Changes a GameObject's color values over time with FULL customization options.  If a GUIText or GUITexture component is attached, they will become the target of the animation.
    /// </summary>
    /// <param name="color">
    /// A <see cref="Color"/> to change the GameObject's color to.
    /// </param>
    /// <param name="r">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color red.
    /// </param>
    /// <param name="g">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
    /// </param>
    /// <param name="b">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
    /// </param>
    /// <param name="a">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the alpha.
    /// </param> 
    /// <param name="namedcolorvalue">
    /// A <see cref="NamedColorValue"/> or <see cref="System.String"/> for the individual setting of the alpha.
    /// </param> 
    /// <param name="includechildren">
    /// A <see cref="System.Boolean"/> for whether or not to include children of this GameObject. True by default.
    /// </param>
    /// <param name="time">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
    /// </param>
    /// <param name="delay">
    /// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
    /// </param>
    /// <param name="easetype">
    /// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
    /// </param>   
    /// <param name="looptype">
    /// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
    /// </param>
    /// <param name="onstart">
    /// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
    /// </param>
    /// <param name="onstarttarget">
    /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
    /// </param>
    /// <param name="onstartparams">
    /// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
    /// </param>
    /// <param name="onupdate"> 
    /// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
    /// </param>
    /// <param name="onupdatetarget">
    /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
    /// </param>
    /// <param name="onupdateparams">
    /// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
    /// </param> 
    /// <param name="oncomplete">
    /// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
    /// </param>
    /// <param name="oncompletetarget">
    /// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
    /// </param>
    /// <param name="oncompleteparams">
    /// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
    /// </param>
    public static void ColorTo(GameObject target, Hashtable args)
    {
        //clean args:
        args = iTween.CleanArgs(args);

        //handle children:
        if(!args.Contains("includechildren") || (bool)args["includechildren"]){
            foreach(Transform child in target.transform){
                Hashtable argsCopy = (Hashtable)args.Clone();
                argsCopy["ischild"]=true;
                ColorTo(child.gameObject,argsCopy);
            }
        }

        //set a default easeType of linear if none is supplied since eased color interpolation is nearly unrecognizable:
        if (!args.Contains("easetype")) {
            args.Add("easetype",EaseType.linear);
        }

        //establish iTween:
        args["type"]="color";
        args["method"]="to";
        Launch(target,args);
    }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:87,代码来源:iTween.cs

示例12: runTest


//.........这里部分代码省略.........
             hsh3 = new Hashtable();
             for(int i=0; i<iNumberOfElements; i++)
             {
                 if(!hsh2.Contains("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742ds8f! Expected value not returned, " + hsh2.Contains("Key_" + i));
                 }				
                 if(!hsh2.ContainsKey("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742389dsaf! Expected value not returned, " + hsh2.ContainsKey("Key_" + i));
                 }				
                 if(!hsh2.ContainsValue("Value_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_563fgd! Expected value not returned, " + hsh2.ContainsValue("Value_" + i));
                 }				
                 if(!hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_87429dsfd! Expected value not returned, " + ((DictionaryEntry)strValueArr[i]).Value);
                 }				
                 try
                 {
                     hsh3.Add(strValueArr[i], null);
                 }
                 catch(Exception)
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_74298dsd! Exception thrown for  " + strValueArr[i]);
                 }
             }
             hsh4 = (Hashtable)hsh2.Clone();
             if(hsh4.Count != hsh1.Count) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_342342! Expected value not returned, " + hsh4.Count);
             }				
             strValueArr = new DictionaryEntry[hsh4.Count];
             hsh4.CopyTo(strValueArr, 0);
             hsh3 = new Hashtable();
             for(int i=0; i<iNumberOfElements; i++)
             {
                 if(!hsh4.Contains("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742ds8f! Expected value not returned, " + hsh4.Contains("Key_" + i));
                 }				
                 if(!hsh4.ContainsKey("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742389dsaf! Expected value not returned, " + hsh4.ContainsKey("Key_" + i));
                 }				
                 if(!hsh4.ContainsValue("Value_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_6-4142dsf! Expected value not returned, " + hsh4.ContainsValue("Value_" + i));
                 }				
                 if(!hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_87429dsfd! Expected value not returned, " + ((DictionaryEntry)strValueArr[i]).Value);
                 }				
                 try
                 {
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co3922synchronized.cs

示例13: LoadSelectedItem

    /// <summary>
    /// Loads selected item parameters into the selector.
    /// </summary>
    /// <param name="properties">Name-value collection representing item to load</param>
    public void LoadSelectedItem(Hashtable properties)
    {
        if ((properties != null) && (properties.Count > 0))
        {
            Hashtable temp = (Hashtable)properties.Clone();

            if ((properties[DialogParameters.AV_URL] != null) && ((properties[DialogParameters.LAST_TYPE] == null) || ((MediaTypeEnum)properties[DialogParameters.LAST_TYPE] == MediaTypeEnum.AudioVideo)))
            {
                drpMediaType.SelectedValue = "av";
                txtUrl.Text = properties[DialogParameters.AV_URL].ToString();
            }
            else if ((properties[DialogParameters.FLASH_URL] != null) && ((properties[DialogParameters.LAST_TYPE] == null) || ((MediaTypeEnum)properties[DialogParameters.LAST_TYPE] == MediaTypeEnum.Flash)))
            {
                drpMediaType.SelectedValue = "flash";
                txtUrl.Text = properties[DialogParameters.FLASH_URL].ToString();
            }
            else if ((properties[DialogParameters.IMG_URL] != null) && ((properties[DialogParameters.LAST_TYPE] == null) || ((MediaTypeEnum)properties[DialogParameters.LAST_TYPE] == MediaTypeEnum.Image)))
            {
                drpMediaType.SelectedValue = "image";

                /*int width = ValidationHelper.GetInteger(temp[DialogParameters.IMG_WIDTH], 0);
                int height = ValidationHelper.GetInteger(temp[DialogParameters.IMG_HEIGHT], 0);

                int originalWidth = ValidationHelper.GetInteger(temp[DialogParameters.IMG_ORIGINALWIDTH], 0);
                int originalHeight = ValidationHelper.GetInteger(temp[DialogParameters.IMG_ORIGINALHEIGHT], 0);*/
                // Update URL
                string url = ValidationHelper.GetString(properties[DialogParameters.IMG_URL], "");
                txtUrl.Text = url;
            }
            else if ((properties[DialogParameters.URL_URL] != null) && ((properties[DialogParameters.LAST_TYPE] == null) || ((MediaTypeEnum)properties[DialogParameters.LAST_TYPE] == MediaTypeEnum.Unknown)))
            {
                txtUrl.Text = properties[DialogParameters.URL_URL].ToString();
            }
            if (!String.IsNullOrEmpty(txtUrl.Text))
            {
                ShowProperties();
                // Load temp properties because ShowProperties() change original properties
                Properties.LoadItemProperties(temp);
            }
        }
    }
开发者ID:arvind-web-developer,项目名称:csharp-projects-Jemena-Kentico-CMS,代码行数:45,代码来源:WebContentSelector.ascx.cs

示例14: TestClone_IsShallowCopy

        public static void TestClone_IsShallowCopy()
        {
            var hash = new Hashtable();
            for (int i = 0; i < 10; i++)
            {
                hash.Add(i, new Foo());
            }

            Hashtable clone = (Hashtable)hash.Clone();
            for (int i = 0; i < clone.Count; i++)
            {
                Assert.Equal("Hello World", ((Foo)clone[i]).StringValue);
                Assert.Same(hash[i], clone[i]);
            }

            // Change object in original hashtable
            ((Foo)hash[1]).StringValue = "Goodbye";
            Assert.Equal("Goodbye", ((Foo)clone[1]).StringValue);

            // Removing an object from the original hashtable doesn't change the clone
            hash.Remove(0);
            Assert.True(clone.Contains(0));
        }
开发者ID:benpye,项目名称:corefx,代码行数:23,代码来源:HashtableTests.cs

示例15: TestSynchronizedBasic

        public void TestSynchronizedBasic()
        {
            Hashtable hsh1;

            string strValue;

            Task[] workers;
            Action ts1;
            int iNumberOfWorkers = 3;
            DictionaryEntry[] strValueArr;
            string[] strKeyArr;
            Hashtable hsh3;
            Hashtable hsh4;
            IDictionaryEnumerator idic;

            object oValue;

            //[]Vanila - Syncronized returns a wrapped HT. We must make sure that all the methods
            //are accounted for here for the wrapper
            hsh1 = new Hashtable();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                hsh1.Add("Key_" + i, "Value_" + i);
            }

            _hsh2 = Hashtable.Synchronized(hsh1);
            //Count
            Assert.Equal(_hsh2.Count, hsh1.Count);

            //get/set item
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                Assert.True(((string)_hsh2["Key_" + i]).Equals("Value_" + i));
            }

            Assert.Throws<ArgumentNullException>(() =>
                {
                    oValue = _hsh2[null];
                });

            _hsh2.Clear();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                _hsh2["Key_" + i] = "Value_" + i;
            }

            strValueArr = new DictionaryEntry[_hsh2.Count];
            _hsh2.CopyTo(strValueArr, 0);
            //ContainsXXX
            hsh3 = new Hashtable();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                Assert.True(_hsh2.Contains("Key_" + i));
                Assert.True(_hsh2.ContainsKey("Key_" + i));
                Assert.True(_hsh2.ContainsValue("Value_" + i));

                //we still need a way to make sure that there are all these unique values here -see below code for that
                Assert.True(hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value));

                hsh3.Add(strValueArr[i], null);
            }

            hsh4 = (Hashtable)_hsh2.Clone();

            Assert.Equal(hsh4.Count, hsh1.Count);
            strValueArr = new DictionaryEntry[hsh4.Count];
            hsh4.CopyTo(strValueArr, 0);
            //ContainsXXX
            hsh3 = new Hashtable();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                Assert.True(hsh4.Contains("Key_" + i));
                Assert.True(hsh4.ContainsKey("Key_" + i));
                Assert.True(hsh4.ContainsValue("Value_" + i));

                //we still need a way to make sure that there are all these unique values here -see below code for that
                Assert.True(hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value));

                hsh3.Add(((DictionaryEntry)strValueArr[i]).Value, null);
            }

            Assert.False(hsh4.IsReadOnly);
            Assert.True(hsh4.IsSynchronized);

            //Phew, back to other methods
            idic = _hsh2.GetEnumerator();
            hsh3 = new Hashtable();
            hsh4 = new Hashtable();
            while (idic.MoveNext())
            {
                Assert.True(_hsh2.ContainsKey(idic.Key));
                Assert.True(_hsh2.ContainsValue(idic.Value));
                hsh3.Add(idic.Key, null);
                hsh4.Add(idic.Value, null);
            }

            hsh4 = (Hashtable)_hsh2.Clone();
            strValueArr = new DictionaryEntry[hsh4.Count];
            hsh4.CopyTo(strValueArr, 0);
            hsh3 = new Hashtable();
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:SynchronizedTests.cs


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