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


C# Object.SetValue方法代码示例

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


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

示例1: Parse

 public static object[] Parse(RecordInputStream in1, int nValues)
 {
     object[] result = new Object[nValues];
     for (int i = 0; i < result.Length; i++)
     {
         result.SetValue(ReadAConstantValue(in1),i);
     }
     return result;
 }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:9,代码来源:ConstantValueParser.cs

示例2: GetValues

 public override object[,] GetValues()
 {
     values_ = new Object[Rows, Cols];
     var remainingcubes = new string[Rows * Cols];
     string[] cubes;
     if (Big) cubes = bigCubes.Clone() as string[];
     else cubes = regularCubes.Clone() as string[];
     string tmpallvalues = "";
     //loop through rows and columns and insert a random number in each cell)
     for (int i = 0; i < Rows; i++) {
         for (int j = 0; j < Cols; j++) {
             // trying to get a number with a min of 0 and max of 9, skewed to lower numbers but not too many 0s
             // NextDouble gives a number b/w 0 and 1, so this gives 1 number in (0.3,3.3) and one number in
             // (0,3). Taking their product gives a number in (0,9.9) and flooring gives an int in [0,9]
             //NQR
             //randomly get an integer in [0,6] to pick which letter from the cube to choose
             int letterfromcube = rand.Next(6);
             //get a random integer in [0,remaining unused cubes) to pick the letter from
             int numRemainingCubes = Rows * Cols - Cols * i - j;
             int whichcube = rand.Next(numRemainingCubes);
             //get the cube that corresponds the one chosen above
             if (cubes != null){
                 var cubestring = cubes[whichcube];
                 //get the chosen letter from the cube specified
                 var value = cubestring.Substring(letterfromcube, 1);
                 //Q really means Qu
                 if (value == "Q") value = "Qu";
                 tmpallvalues += value;
                 SetLocation_(value.ToUpper(), i, j);
                 if (numRemainingCubes > 1) remainingcubes = new string[numRemainingCubes - 1];
                 int pos = 0;
                 //for debugging/testing algorithm write out the cube numbers and letter numbers used
                 /*using (StreamWriter file = new StreamWriter(@"d:\tmp.txt", true)){
                 file.WriteLine(letterfromcube);
                 if (numRemainingCubes == 1) file.WriteLine("end of game\n\n");
             }
             using (StreamWriter file = new StreamWriter(@"d:\whichcube.txt", true)){
                 file.WriteLine(whichcube);
                 if (numRemainingCubes == 1) file.WriteLine("end of game\n\n");
             }  */
                 //Make the cubes array just contain the unused cubes (effectively remove the cube that has just been used)
                 for (int k = 0; k < cubes.Length; k++) {
                     if (k != whichcube) {
                         remainingcubes.SetValue(cubes[k], pos);
                         pos++;
                     }
                 }
                 cubes = (string[])remainingcubes.Clone();
                 values_.SetValue(value, i, j);
             }
         }
     }
     allvalues_ = (string)tmpallvalues.Clone();
     return values_;
 }
开发者ID:ajfeigin,项目名称:boggle,代码行数:55,代码来源:BoggleGridVals.cs

示例3: TestSetValue4

	public void TestSetValue4() {
		{
			int[] c1 = { 1, 2, 3 };
			long[] c2 = new long [3];

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++) {
				Assert ("#M81(" + i + ")", c1[i] == c2[i]);
				AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
			}
		}
		{
			long[] c1 = { 1, 2, 3 };
			int[] c2 = new int [3];
			bool errorThrown = false;
			try {
				c2.SetValue (c1 [0], 0);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#M83", errorThrown);
		}
		{
			int[] c1 = { 1, 2, 3 };
			Object[] c2 = new Object [3];

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++)
				AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
		}
		{
			Object[] c1 = new Object [3];
			Object[] c2 = new Object [3];
			c1[0] = new Object ();

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++)
				AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
		}
		{
			Object[] c1 = new Object [3];
			string[] c2 = new String [3];
			string test = "hello";
			c1[0] = test;

			c2.SetValue (c1 [0], 0);
			AssertEquals ("#M86", c1[0], c2[0]);
			AssertEquals ("#M87", "hello", c2[0]);
		}
		{
			char[] c1 = { 'a', 'b', 'c' };
			string[] c2 = new string [3];
			try {
				c2.SetValue (c1 [0], 0);
				Fail ("#M88");
			} catch (InvalidCastException) {}
		}
		{
			Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
			long[] c2 = new long [3];
			try {
				c2.SetValue (c1 [0], 0);
				Fail ("#M89");
			} catch (ArgumentException) {}
		}
		{
			Type[] types = {
				typeof (Boolean),
				typeof (Byte),
				typeof (Char),
				typeof (Double),
				typeof (Int16),
				typeof (Int32),
				typeof (Int64),
				typeof (SByte),
				typeof (Single),
				typeof (UInt16),
				typeof (UInt32),
				typeof (UInt64)
			};

			bool v1 = true;
			Byte v2 = 1;
			Char v3 = 'a';
			Double v4 = -1.2;
			Int16 v5 = -32;
			Int32 v6 = -234;
			Int64 v7 = -34523;
			SByte v8 = -1;
			Single v9 = -4.8F;
			UInt16 v10 = 24234;
			UInt32 v11 = 235354;
			UInt64 v12 = 234552;

//.........这里部分代码省略.........
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:101,代码来源:ArrayTest.cs

示例4: OnExternalInterface

 void OnExternalInterface(long MovieID, String command, IntPtr ptr, int numArgs, int valueSize)
 {
     int sfValueSize = Marshal.SizeOf(typeof(Value));
     int count = 0;
     
     // Array of types passed to ExternalInterface
     Type[] typeArray;
     System.Object[] args;
     
     // Note that we can't preallocate typeArray and args since we have to pass them to the 
     // GetMethod function below and there is no way to pass the size of the array, so the
     // array can't contain any null values.
     typeArray = new Type[numArgs];
     args = new System.Object[numArgs];
   
     for (int i = 0; i < numArgs; i++)
     {
         // Can't add an integer offset to IntPtr as you would with C/C++ pointer 
         IntPtr data = new IntPtr(ptr.ToInt32() + sfValueSize * i);
         
         // This Value makes a copy of the data and will be garbage collected.
         Value val = GetValueData(data);
         // Value val = (Value)Marshal.PtrToStructure(data, typeof(Value)); // Unsupported on iOS.
         
         if (val.IsString())
         {
             String str = val.GetString();
             typeArray.SetValue(typeof(String), count);
             args.SetValue(str, count);
             count++;
         }
         else if (val.IsNumber())
         {
             double num = val.GetNumber();
             Console.Write(num);
             typeArray.SetValue(typeof(double), count);
             args.SetValue(num, count);
             count++;
         }    
         else if (val.IsBoolean())
         {
             Boolean boolVal = val.GetBool();
             typeArray.SetValue(typeof(Boolean), count);
             args.SetValue(boolVal, count);
             count++;
         }    
         else if (val.IsUInt())
         {
             UInt32 uintVal = val.GetUInt();
             typeArray.SetValue(typeof(UInt32), count);
             args.SetValue(uintVal, count);
             count++;
         }    
         else if (val.IsInt())
         {
             Int32 intVal = val.GetInt();
             typeArray.SetValue(typeof(Int32), count);
             args.SetValue(intVal, count);
             count++;
         }    
         else if (val.IsObject())
         {
             Value newval = val.GetObject();
             typeArray.SetValue(typeof(Value), count);
             args.SetValue(newval, count);
             count++;
         }
     }
     
     // Preallocated memory is destroyed in the destructor
     /* This code can be uncommented if delegates are being used for EI implementation.
     if (ptr != pValues_PreAllocated)
     {
         Console.WriteLine("Destroying Value Array");
         Marshal.FreeCoTaskMem(ptr);
     }
     */
     
     // At this point, count must be = numArgs, since we should be able to determine the type of each Value. If not,
     // there is some problem.
     if (count != numArgs)
     {
         LogMessage("Invalid Type passed in ExternalInterface!");
         return;
     }
     
     for (int j = 0; j < SFMovieList.Count; j++) // Loop through List with for
     {
         Movie movie = SFMovieList[j];
         long mId = movie.GetID();
         if (MovieID != mId) continue;
         
         Type SFMovieClass = movie.GetType();
         UnityEngine.Debug.Log("ExternalInterface arrived");
         // Command passed as an argument is the method we want to call
         MethodInfo methodInfo;
         if (typeArray == null)
         {
             methodInfo = SFMovieClass.GetMethod(command);
         }
//.........这里部分代码省略.........
开发者ID:BiDuc,项目名称:Stereoscopic_Scatterplot,代码行数:101,代码来源:SFManager.cs

示例5: callJS

 bool callJS(params Object[] args)
 {
     Object[] a = new Object[args.Length + 2];
     a.SetValue(HtmlUploaderID, 0);
     a.SetValue(HtmlFrontentID, 1);
     Array.Copy(args, 0, a, 2, args.Length);
     bool wasError = false;
     try
     {
         ScriptObject lu = (ScriptObject)HtmlPage.Window.GetProperty(HtmlProxyName);
         lu.Invoke("callFEMethod", a);
     }
     catch (Exception)
     {
         wasError = true;
     }
     return wasError;
 }
开发者ID:dmitry-dedukhin,项目名称:lightweight-uploader,代码行数:18,代码来源:UploaderControl.xaml.cs

示例6: loadComboBoxes

        private bool loadComboBoxes()
        {
            //Prüfen ob die Datei existiert
            if (System.IO.File.Exists(Application.StartupPath + "//database/base.xml") == false)
            {
                MessageBox.Show(Locales.GetString("error_basefile_not_found"), Locales.GetString("error_messagebox_title"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            try
            {
                foreach (DataTable dataTable in this.baseXMLData.Tables) dataTable.BeginLoadData();
                this.baseXMLData.ReadXml(Application.StartupPath + "//database/base.xml");
                foreach (DataTable dataTable in this.baseXMLData.Tables) dataTable.EndLoadData();

                //Stats-Kategorien in eigene Tabellen speichern
                for (int i = 0; i < 11; i++)
                {
                    bonusData.SetValue(this.baseXMLData.Copy(), i);
                    foreach (DataRow row in bonusData[i].Tables["bonus"].Rows)
                    {
                        if (bonusData[i].Tables.Contains("stats_" + row["category"].ToString()) == false)
                        {
                            bonusData[i].Tables.Add("stats_" + row["category"].ToString());
                            bonusData[i].Tables["stats_" + row["category"].ToString()].Columns.Add("id");
                            bonusData[i].Tables["stats_" + row["category"].ToString()].Columns.Add("name");
                        }

                        object[] values = new Object[2];
                        values.SetValue(row["id"], 0);
                        values.SetValue(row["name"], 1);
                        bonusData[i].Tables["stats_" + row["category"].ToString()].Rows.Add(values);
                    }

                    ComboBox control = (ComboBox)this.Controls.Find("effectCat" + (i+1), true)[0];
                    control.DataSource = bonusData[i].Tables["bonus_category"];
                    control.ValueMember = "name";
                    control.DisplayMember = "name";
                    control.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(Locales.GetString("error_reading_basefile"), Locales.GetString("error_messagebox_title"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }
开发者ID:Dawn-of-Light,项目名称:ItemCreator,代码行数:49,代码来源:MainForm.cs

示例7: TryReadObject

        private Boolean TryReadObject(Type type, ref Object value)
        {
            // 不支持基本类型
            if (Type.GetTypeCode(type) != TypeCode.Object) return false;
            // 不支持基类不是Object的特殊类型
            //if (type.BaseType != typeof(Object)) return false;
            if (!typeof(Object).IsAssignableFrom(type)) return false;

            var ims = Host.IgnoreMembers;

            var ms = GetMembers(type).Where(e => !ims.Contains(e.Name)).ToList();
            WriteLog("BinaryRead类{0} 共有成员{1}个", type.Name, ms.Count);

            if (value == null) value = type.CreateInstance();

            // 提前准备名值对
            var dic = ReadPair();
            if (dic.Count == 0) return true;

            Host.Hosts.Push(value);

            // 获取成员
            for (int i = 0; i < ms.Count; i++)
            {
                var member = ms[i];

                var mtype = GetMemberType(member);
                Host.Member = member;
                WriteLog("    {0}.{1}", member.DeclaringType.Name, member.Name);

                var name = member.Name;
                var att = member.GetCustomAttribute<XmlElementAttribute>();
                if (att != null) name = att.ElementName;

                Object v = null;
                if (TryReadPair(dic, name, mtype, ref v)) value.SetValue(member, v);
            }
            Host.Hosts.Pop();

            return true;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:41,代码来源:BinaryPair.cs

示例8: TryRead

        /// <summary>尝试读取指定类型对象</summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Boolean TryRead(Type type, ref Object value)
        {
            if (type == null)
            {
                if (value == null) return false;
                type = value.GetType();
            }

            // 不支持基本类型
            if (Type.GetTypeCode(type) != TypeCode.Object) return false;
            // 不支持基类不是Object的特殊类型
            //if (type.BaseType != typeof(Object)) return false;
            if (!typeof(Object).IsAssignableFrom(type)) return false;

            var ms = GetMembers(type);
            WriteLog("JsonRead类{0} 共有成员{1}个", type.Name, ms.Count);

            if (value == null) value = type.CreateInstance();

            Host.Hosts.Push(value);

            // 成员序列化访问器
            var ac = value as IMemberAccessor;

            // 获取成员
            for (int i = 0; i < ms.Count; i++)
            {
                var member = ms[i];
                if (IgnoreMembers != null && IgnoreMembers.Contains(member.Name)) continue;

                var mtype = GetMemberType(member);
                Host.Member = member;
                WriteLog("    {0}.{1}", member.DeclaringType.Name, member.Name);

                // 成员访问器优先
                if (ac != null)
                {
                    // 访问器直接写入成员
                    if (ac.Read(Host, member))
                    {
                        // 访问器内部可能直接操作Hosts修改了父级对象,典型应用在于某些类需要根据某个字段值决定采用哪个派生类
                        var obj = Host.Hosts.Peek();
                        if (obj != value)
                        {
                            value = obj;
                            ms = GetMembers(value.GetType());
                            ac = value as IMemberAccessor;
                        }

                        continue;
                    }
                }

                Object v = null;
                if (!Host.TryRead(mtype, ref v))
                {
                    Host.Hosts.Pop();
                    return false;
                }

                value.SetValue(member, v);
            }
            Host.Hosts.Pop();

            return true;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:70,代码来源:JsonComposite.cs


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