Example #1
0
        public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
        {
            Delegate del = null;
            string key = obj.GetType().Name + "." + methodName;
            Type tp;
            lock (methodLookup)
            {
                if (methodLookup.Contains(key))
                    tp = (Type)methodLookup[key];
                else
                {
                    Type[] paramList = new Type[obj.GetType().GetMethod(methodName).GetParameters().Length];
                    int n = 0;
                    foreach (ParameterInfo pi in obj.GetType().GetMethod(methodName).GetParameters()) paramList[n++] = pi.ParameterType;
                    TypeBuilder typeB = builder.DefineType("Del_" + obj.GetType().Name + "_" + methodName, TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate), PackingSize.Unspecified);
                    ConstructorBuilder conB = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(object), typeof(IntPtr) });
                    conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                    MethodBuilder mb = typeB.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, obj.GetType().GetMethod(methodName).ReturnType, paramList);
                    mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                    tp = typeB.CreateType();
                    methodLookup.Add(key, tp);
                }
            }

            del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
            return obj.Invoke(del, paramValues);
        }
Example #2
0
        //Main_12_2_3
        public static void Main_12_2_3()
        {
            //User user = new User { Name = "小王", Age = 27 };

            var user = new { Name = "小王", Age = 27 };
            var my = new { Name = "Wang", Emal = "Mail@anytao.com" };
            //等效于User v = new User { Name = "小王", Age = 27 };
            Console.WriteLine(user.Name);
            Console.WriteLine(user.GetType());

            var name = "小王";
            var age = 27;
            //等效于string v2 = "123";
            Console.WriteLine(name.GetType());
            Console.WriteLine(age.GetType());

            //创建不同的Type
            var v1 = new { Name = "Aero", Age = 27 };
            var v2 = new { Name = "Emma", Age = 22 };
            var v3 = new { Age = 27, Name = "Aero" };
            Console.WriteLine(v1.Equals(v2));
            Console.WriteLine(v1.Equals(v3));
            Console.WriteLine(ReferenceEquals(v1.GetType(), v2.GetType()));
            Console.WriteLine(ReferenceEquals(v1.GetType(), v3.GetType()));
        }
Example #3
0
		/*--------------------------------------------------*/
		/// <summary>
		/// .
		/// </summary>
		/// <param name="selected"> . </param>
		/// <returns> . </returns>
		/*--------------------------------------------------*/
		static public System.Enum EnumGridToolbar(System.Enum selected, int xCount)
		{
#if UNITY_EDITOR
			string[] toolbar = System.Enum.GetNames(selected.GetType());
			System.Array values = System.Enum.GetValues(selected.GetType());

			for (int i = 0; i < toolbar.Length; i++)
			{
				string toolname = toolbar[i];
				toolname = toolname.Replace("_", " ");
				toolbar[i] = toolname;
			}

			int selected_index = 0;
			while (selected_index < values.Length)
			{
				if (selected.ToString() == values.GetValue(selected_index).ToString())
				{
					break;
				}
				selected_index++;
			}
			selected_index = UnityEngine.GUILayout.SelectionGrid(selected_index, toolbar, xCount);
			return (System.Enum)values.GetValue(selected_index);
#else
			return selected;
#endif
		}
 void buildTreeLayer(System.Exception e, TreeViewItem parent)
 {
     String exceptionInformation = "\n\r\n\r" + e.GetType().ToString() + "\n\r\n\r";
     parent.DisplayMemberPath = "Header";
     parent.Items.Add(new TreeViewStringSet() { Header = "Type", Content = e.GetType().ToString() });
     PropertyInfo[] memberList = e.GetType().GetProperties();
     foreach (PropertyInfo info in memberList)
     {
         var value = info.GetValue(e, null);
         if (value != null)
         {
             if (info.Name == "InnerException")
             {
                 TreeViewItem treeViewItem = new TreeViewItem();
                 treeViewItem.Header = info.Name;
                 buildTreeLayer(e.InnerException, treeViewItem);
                 parent.Items.Add(treeViewItem);
             }
             else
             {
                 TreeViewStringSet treeViewStringSet = new TreeViewStringSet() { Header = info.Name, Content = value.ToString() };
                 parent.Items.Add(treeViewStringSet);
                 exceptionInformation += treeViewStringSet.Header + "\n\r\n\r" + treeViewStringSet.Content + "\n\r\n\r";
             }
         }
     }
     _exceptionInformationList.Add(exceptionInformation);
 }
		/// <summary>
		/// Adds all of the elements of the "c" collection to the "target" collection.
		/// </summary>
		/// <param name="target">Collection where the new elements will be added.</param>
		/// <param name="c">Collection whose elements will be added.</param>
		/// <returns>Returns true if at least one element was added, false otherwise.</returns>
		public static bool AddAll(System.Collections.ICollection target, System.Collections.ICollection c)
		{
			System.Collections.IEnumerator e = new System.Collections.ArrayList(c).GetEnumerator();
			bool added = false;

			//Reflection. Invoke "addAll" method for proprietary classes
			System.Reflection.MethodInfo method;
			try
			{
				method = target.GetType().GetMethod("addAll");

				if (method != null)
					added = (bool) method.Invoke(target, new System.Object[] {c});
				else
				{
					method = target.GetType().GetMethod("Add");
					while (e.MoveNext() == true)
					{
						bool tempBAdded =  (int) method.Invoke(target, new System.Object[] {e.Current}) >= 0;
						added = added ? added : tempBAdded;
					}
				}
			}
			catch (System.Exception ex)
			{
				throw ex;
			}
			return added;
		}
        public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
        {
            Delegate del = null;
            DateTime now  = DateTime.Now;
            TimeSpan ts = now - lastCleanTime;
            if(ts.TotalHours>5)
            {
                delLookup.Clear();
                lastCleanTime = now;
            }
            string delKey = obj.GetType().Name+"."+methodName+obj.GetHashCode().ToString() + obj.ToString();
            if(delLookup.ContainsKey(delKey))
            {
                del =(Delegate) delLookup[delKey];
            }
            else
            {
                string key = obj.GetType().Name + "." + methodName;
                Type tp;
                if (methodLookup.Contains(key))
                {
                    tp = (Type)methodLookup[key];
                }
                else
                {
                    Type objType = obj.GetType();
                    object[] signatures = new object[paramValues.Length + 1];
                    signatures[0] = methodName;
                    Array.Copy(paramValues, 0, signatures, 1, paramValues.Length);
                    MemberInfo[] mInfo = objType.FindMembers(MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, methodFilter, signatures);
                    if (mInfo.Length != 1) return null;
                    MethodInfo methInfo = (MethodInfo)mInfo[0];
                    Type[] paramList = new Type[methInfo.GetParameters().Length];
                    ParameterInfo[] paramInfos = methInfo.GetParameters();
                    int n = 0;
                    foreach (ParameterInfo pi in paramInfos)
                    {
                        paramList[n++] = pi.ParameterType;
                    }
                    TypeBuilder typeB = builder.DefineType("Del_" +
                        obj.GetType().Name + "_" + methodName,
                        TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed,
                        typeof(MulticastDelegate), PackingSize.Unspecified);
                    ConstructorBuilder conB = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName
                        | MethodAttributes.RTSpecialName, CallingConventions.Standard,
                        new Type[] { typeof(object), typeof(IntPtr) });
                    conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                    MethodBuilder mb = typeB.DefineMethod("Invoke",
                        MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
                        methInfo.ReturnType, paramList);
                    mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                    tp = typeB.CreateType();
                    methodLookup.Add(key, tp);
                }
                del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
                delLookup.Add(delKey, del);
            }

            return obj.Invoke(del, paramValues);
        }
 /// <summary>
 /// 弹出消息框,不会导致界面变形【推荐】
 /// </summary>
 /// <param name="message">消息内容</param>
 /// <param name="page">当前页面对象,如this.Page</param>
 public static void Alert(string message, System.Web.UI.Page page)
 {
     string js = @"<Script language='JavaScript'>alert('" + message + "');</Script>";
     if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "alert"))
     {
         page.ClientScript.RegisterStartupScript(page.GetType(), "alert", js);
     }
 }
        public void RegisterInstanceWithType()
        {
            var obj = new { ID = 1 };

            ServiceContainer.Register (obj.GetType(), obj);

            Assert.That (ServiceContainer.Resolve (obj.GetType ()), Is.EqualTo (obj));
        }
Example #9
0
 public virtual void Test3()
 {
     var array1 = new[] {1, 2};
     AssertEquals(OdbType.Array, OdbType.GetFromClass(array1.GetType()));
     AssertEquals(OdbType.Integer, OdbType.GetFromClass(array1.GetType()).SubType);
     var array2 = new[] {"1", "2"};
     AssertEquals(OdbType.Array, OdbType.GetFromClass(array2.GetType()));
     AssertEquals(OdbType.String, OdbType.GetFromClass(array2.GetType()).SubType);
 }
        public void GetDictionaryValueOrDefaultReturnsArrayIfArrayDesiredFromDictionaryKeyFound()
        {
            var expected = new[] { "Cameron" };
            var dictionary = new Dictionary<string, JToken> { { "fields", JToken.Parse("[ \"" + expected[0] + "\" ]") } };

            var actual = MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(dictionary, "fields", expected.GetType());

            Assert.IsType(expected.GetType(), actual);
            Assert.Equal(expected, actual);
        }
Example #11
0
        public static void DesignRule(System.Workflow.ComponentModel.Activity activity, bool UseProvider)
        {
            RuleSet ruleSet = null;
            //MessageBox.Show(activity.UserData[0].ToString());
            //MessageBox.Show(activity.GetType().ToString());
            string ruleName = activity.UserData[0].ToString();

            //load ruleset
            try
            {
                ruleSet = RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).getRuleSetDesign("", "", ruleName);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error deserializing file: " + ruleName + e.Message);
            }

            if (ruleSet == null)
            {
                MessageBox.Show("RuleSet is null");
                ruleSet = new RuleSet(ruleName);
            }

            RuleSetDialog ruleSetDialog = null;
            if (UseProvider)
            {
                TypeProvider provider = new TypeProvider(null);
                AssemblyName[] ass = activity.GetType().Assembly.GetReferencedAssemblies();
                provider.AddAssembly(activity.GetType().Assembly);
                FillWithAssemblies(provider, ass);
                ruleSetDialog = new RuleSetDialog(activity.GetType(), provider, ruleSet);
            }
            else
            {
                ruleSetDialog = new RuleSetDialog(activity, ruleSet);
            }

            var result = ruleSetDialog.ShowDialog();

            // Only update the .rules file if the OK is pressed 
            if (result == DialogResult.OK)
            {
                ruleSet = ruleSetDialog.RuleSet;
                try
                {
                    Console.WriteLine(ruleName);
                    RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).saveRuleSetDesign("", "", ruleName, ruleSet);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
        }
Example #12
0
        /// <summary>
        /// Prints all info about passed enum
        /// </summary>
        /// <exception cref="IOException">I/O exception occured. </exception>
        /// <exception cref="ArgumentNullException">Parameter <paramref name="format" /> has null value. </exception>
        /// <exception cref="FormatException">Format specification set in parameter <paramref name="format" /> is not acceptable. </exception>
        /// <exception cref="ArgumentException">Parameter value for <paramref name="enumType" /> is not Enum <see cref="T:System.Enum" />. </exception>
        /// <exception cref="InvalidOperationException">Method is called in reflection context intended only for reflection.
        /// -or-<paramref name="enumType" /> — is a build type loaded in context suited only for reflection.</exception>
        private static void EvaluateEnum (System.Enum e) {
            Console.WriteLine ("*** Info about {0} ***", e.GetType ().Name);

            Console.WriteLine ("Underlying storage type: {0}", Enum.GetUnderlyingType (e.GetType ()));

            Array enumData = Enum.GetValues (e.GetType ());
            foreach (var eData in enumData) {
                Console.WriteLine ("Name - {0}, Value - {0:D}", eData);
            }
            Console.WriteLine ();
        }
Example #13
0
 static void EvaluateEnum(System.Enum e)
 {
     Console.WriteLine("information about {0}", e.GetType().Name);
     Console.WriteLine("underlying storage type: {0}", Enum.GetUnderlyingType(e.GetType()));
     Array enumData = Enum.GetValues(e.GetType());
     Console.WriteLine("this enum has {0} members", enumData.Length);
     for (int i=0; i<enumData.Length; i++)
     {
         Console.WriteLine("name: {0}, Value: {0:D}", enumData.GetValue(i));
     }
 }
Example #14
0
        public static void GenerateReport(string FileName, ReportDocument rpt, System.Web.UI.Control ClientScriptBlockControl, ExportFormatType pvtExportFormatType)
        {
            try
            {
                ExportOptions exportop = new ExportOptions();
                DiskFileDestinationOptions dest = new DiskFileDestinationOptions();

                string strFileExtensionName = ".pdf";
                switch (pvtExportFormatType)
                {
                    case ExportFormatType.PortableDocFormat: strFileExtensionName = ".pdf"; exportop.ExportFormatType = ExportFormatType.PortableDocFormat; break;
                    case ExportFormatType.WordForWindows: strFileExtensionName = ".doc"; exportop.ExportFormatType = ExportFormatType.WordForWindows; break;
                    case ExportFormatType.Excel: strFileExtensionName = ".xls"; exportop.ExportFormatType = ExportFormatType.Excel; break;
                }

                string strPath = System.Web.HttpContext.Current.Server.MapPath(@"\retailplus\temp\");
                string strFileName = FileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + strFileExtensionName;

                if (System.IO.File.Exists(strPath + strFileName))
                    System.IO.File.Delete(strPath + strFileName);

                dest.DiskFileName = strPath + strFileName;
                exportop.DestinationOptions = dest;
                exportop.ExportDestinationType = ExportDestinationType.DiskFile;
                rpt.Export(exportop); //rpt.Close(); rpt.Dispose();
                
                // remove the error
                if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat)
                {
                    // the maximum report processing jobs limit configured by your system administrator has been reached.
                    rpt.Close(); rpt.Dispose();
                }

                if (pvtExportFormatType == ExportFormatType.PortableDocFormat)
                {
                    string newWindowUrl = Constants.ROOT_DIRECTORY + "/temp/" + strFileName;
                    string javaScript = "window.open('" + newWindowUrl + "');";
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(ClientScriptBlockControl, ClientScriptBlockControl.GetType(), "openwindow", javaScript, true);
                }
                else
                {
                    string newWindowUrl = Constants.ROOT_DIRECTORY + "/temp/" + strFileName;
                    string javaScript = "window.open('" + newWindowUrl + "','_self');";
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(ClientScriptBlockControl, ClientScriptBlockControl.GetType(), "openwindow", javaScript, true);

                    //System.Diagnostics.Process p = new System.Diagnostics.Process();
                    //p.StartInfo.FileName = System.Web.HttpContext.Current.Server.MapPath(Constants.ROOT_DIRECTORY + "/temp/" + strFileName);
                    //p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                    //p.Start();
                }
            }
            catch (Exception ex) { throw ex; }
        }
Example #15
0
        RawObjStats( System.Object obj )
    {
      RawObjCount tmpNode = FindRawObjNode( obj.GetType() );
      if( tmpNode == null )
      {
        tmpNode = new RawObjCount();
        tmpNode.m_classType = obj.GetType();
        m_rawObjCounts.Add( tmpNode );
      }

      tmpNode.m_objs.Add( obj );
    }
Example #16
0
 public void 测试GetSet默认行为()
 {
     var a = new {id = 1, name = "blqw"};
     var id = ComponentServices.GetGeter(a.GetType().GetProperty("id"))(a);
     Assert.AreEqual(a.id, id);
     ComponentServices.GetSeter(a.GetType().GetProperty("id"))(a, 2);
     Assert.AreEqual(2, a.id);
     var name = ComponentServices.GetGeter(a.GetType().GetProperty("name"))(a);
     Assert.AreEqual(a.name, name);
     ComponentServices.GetSeter(a.GetType().GetProperty("name"))(a, "zzj");
     Assert.AreEqual("zzj", a.name);
 }
        private ApiException MapException(System.Exception exception)
        {
            Type type;
            ApiException apiException;

            if (_dataAccessExceptionMapping.TryGetValue(exception.GetType(), out type))
            {
                var statusCode = _dataAccessStatusCodeMapping[exception.GetType()];
                apiException = new ApiException(exception.Message, statusCode);
            }
            else
                apiException = new ApiException(exception, HttpStatusCode.BadRequest);

            return apiException;
        }
Example #18
0
File: Lan.cs Project: mnisl/OD
	///<summary></summary>
	public static void C(System.Windows.Forms.Control sender,System.Windows.Forms.Control[] controls,bool isRecursive) {
		for(int i=0;i<controls.Length;i++) {
			if(controls[i].GetType()==typeof(UI.ODGrid)) {
				((UI.ODGrid)controls[i]).Title=Lans.ConvertString(((UI.ODGrid)controls[i]).TranslationName,((UI.ODGrid)controls[i]).Title);
				foreach(UI.ODGridColumn col in ((UI.ODGrid)controls[i]).Columns) {
					col.Heading=Lans.ConvertString(((UI.ODGrid)controls[i]).TranslationName,col.Heading);
				}
				continue;
			}
			controls[i].Text=Lans.ConvertString(sender.GetType().Name,controls[i].Text);
			if(isRecursive) {
				Cchildren(sender.GetType().Name,controls[i]);
			}
		}
	}
        public void ReflectionOnAnonymousTypes()
        {
            var id = 4;
            var name = "Freddy";
            var now = DateTime.Now;

            var anonymous = new { id, name, now };

            var idValue = (int)anonymous.GetType().GetProperty("id").GetValue(anonymous, null);
            Assert.That(idValue, Is.EqualTo(id));
            var nameValue = (string)anonymous.GetType().GetProperty("name").GetValue(anonymous, null);
            Assert.That(nameValue, Is.EqualTo(name));
            var nowValue = (DateTime)anonymous.GetType().GetProperty("now").GetValue(anonymous, null);
            Assert.That(nowValue, Is.EqualTo(now));
        }
Example #20
0
		public virtual System.Int32 Compare ( System.Object x , System.Object y )
		{
			//Cell object
			if (x==null && y==null)
				return 0;
			if (x==null)
				return -1;
			if (y==null)
				return 1;
	
			if (x is IComparable)
			{
				if (x.GetType().Equals(y.GetType()) == false)
					return -1;
				return ((IComparable)x).CompareTo(y);
			}
			if (y is IComparable)
			{
				if (x.GetType().Equals(y.GetType()) == false)
					return -1;
				return (-1* ((IComparable)y).CompareTo(x));
			}
	
			//Cell.Value object
			object vx = ((Cells.ICell)x).Value;
			object vy = ((Cells.ICell)y).Value;
			if (vx==null && vy==null)
				return 0;
			if (vx==null)
				return -1;
			if (vy==null)
				return 1;
	
			if (vx is IComparable)
			{
				if (vx.GetType().Equals(vy.GetType()) == false)
					return -1;
				return ((IComparable)vx).CompareTo(vy);
			}
			if (vy is IComparable)
			{
				if (vx.GetType().Equals(vy.GetType()) == false)
					return -1;
				return (-1* ((IComparable)vy).CompareTo(vx));
			}
	
			throw new ArgumentException("Invalid cell object, no IComparable interface found");
		}
        public void Write_BuiltsXmlNodesAndAddsObjectToCache_IfAnArray()
        {
            var parentNode = NewMock<INodeWriter>();
            var arrayNode = CreateXmlNode("array");
            var itemsNode = CreateXmlNode("items");

            object value = new[] {1, 3};

            StubTypeMapper();

            Expect.Once.On(valueCache).Method("Add").With(value).Will(Return.Value(23));

            Expect.Once.On(ownerDocument).Method("CreateArrayElement").With(value.GetType().ToString(), 23, parentNode).
                Will(
                Return.Value(arrayNode));
            Expect.Once.On(ownerDocument).Method("CreateItemsElement").With(arrayNode).Will(Return.Value(itemsNode));

            Expect.Once.On(itemsNode).Method("Dispose").WithNoArguments();
            Expect.Once.On(arrayNode).Method("Dispose").WithNoArguments();

            Expect.Once.On(objectWriter).Method("Write").With(1, itemsNode, typeof (Int32));
            Expect.Once.On(objectWriter).Method("Write").With(3, itemsNode, typeof (Int32));

            writer.Write(value, parentNode, value.GetType());
        }
        public void ArrayLiterals()
        {
            var array = new[] { 42 };
            Assert.AreEqual (typeof(int[]), array.GetType (), "You don't have to specify a type if the elements can be inferred");
            Assert.AreEqual (new int[] { 42 }, array, "These arrays are literally equal... But you won't see this string in the error message.");

            //Are arrays 0-based or 1-based?
            Assert.AreEqual (42, array [0], "Well, it's either 0 or 1.. you have a 110010-110010 chance of getting it right.");

            //This is important because...
            Assert.IsTrue (array.IsFixedSize, "...because Fixed Size arrays are not dynamic");

            //Begin RJG
            // Moved this Throws() call to a separate FixedSizeArraysCannotGrow() method below
            //...it means we can't do this: array[1] = 13;
            //Assert.Throws(typeof(FILL_ME_IN), delegate() { array[1] = 13; });
            //End RJG

            //This is because the array is fixed at length 1. You could write a function
            //which created a new array bigger than the last, copied the elements over, and
            //returned the new array. Or you could do this:
            var dynamicArray = new List<int> ();
            dynamicArray.Add (42);
            CollectionAssert.AreEqual (array, dynamicArray.ToArray (), "Dynamic arrays can grow");

            dynamicArray.Add (13);
            CollectionAssert.AreEqual ((new int[] { 42, (int)13 }), dynamicArray.ToArray (), "Identify all of the elements in the array");
        }
Example #23
0
		/// <summary>Compares for equality with another object.</summary>
		/// <remarks>Comparison is performed by value.</remarks>
		public override bool Equals(System.Object other)
		{
			if (other == null || GetType() != other.GetType())
				return false;

			return this.Equals((CpuSimdFeature)other);
		}
Example #24
0
	private void CallLua(string luafunc, System.Object param)
	{
		if (wLua.L == null)
			return;
		if (m_luaTableRef == LUAREF.LUA_NOREF || m_luaInstanceRef == LUAREF.LUA_NOREF)
			return;
		IntPtr L = wLua.L.L;

		int oldTop = LuaDLL.lua_gettop(L);
		LuaDLL.lua_rawgeti(L, (int)LuaIndexes.LUA_REGISTRYINDEX, m_luaTableRef); //t
		LuaDLL.lua_getfield(L, -1, luafunc);//t,func
		if (LuaDLL.lua_isnil(L, -1))
		{
			LuaDLL.lua_settop(L, oldTop);
			return;
		}
		LuaDLL.lua_rawgeti(L, (int)LuaIndexes.LUA_REGISTRYINDEX, m_luaInstanceRef); //t,func,instance
        if (param.GetType().Equals(typeof(string))) //t,func,instance,param
			LuaDLL.lua_pushstring(L, (string)param);
		else
			LuaDLL.lua_pushinteger(L, (int)param);
		wLua.L.Call(2);	//t
		LuaDLL.lua_settop(L, oldTop);
		return;
	}
Example #25
0
        public static void EqualityTest()
        {
            // Make 2 anonymous classes with identical name/value pairs.
            var firstProduct = new { Color = "Blue", Name = "Widget", RetailPrice = 55 };
            var secondProduct = new { Color = "Blue", Name = "Widget", RetailPrice = 55 };

            // Are they considered equal when using Equals()?
            if (firstProduct.Equals(secondProduct))
                Console.WriteLine("Same anonymous object!");
            else
                Console.WriteLine("Not the same anonymous object!");

            // Are they considered equal when using ==?
            if (firstProduct == secondProduct)
                Console.WriteLine("Same anonymous object!");
            else
                Console.WriteLine("Not the same anonymous object!");

            // Are these objects the same underlying type?
            if (firstProduct.GetType().Name == secondProduct.GetType().Name)
                Console.WriteLine("We are both the same type!");
            else
                Console.WriteLine("We are different types!");

            // Show all the details.
            Console.WriteLine();
            ReflectOverAnonymousType(firstProduct);
            ReflectOverAnonymousType(secondProduct);
        }
Example #26
0
File: Lan.cs Project: mnisl/OD
	///<summary>Converts a string to the current language.</summary>
	public static string g(System.Object sender,string text) {
		string retVal=Lans.ConvertString(sender.GetType().Name,text);
		//if(itemInserted) {
		//	Lans.RefreshCache();
		//}
		return retVal;
	}
Example #27
0
 public static void popupClientMessage(System.Web.UI.Page p, string Message,string runScript)
 {
     Message = Message.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "��").Replace("'", "��");
     string strScript = "<script language='javascript'>"+runScript+"window.alert('" + Message + "');</script>";
     //p.RegisterStartupScript("successAlert", strScript);
     p.ClientScript.RegisterStartupScript(p.GetType(), "successAlert", strScript);
 }
Example #28
0
 // this function will resize our temporary string array that is used to store the parsed Line.
 //This will contain the data in parsed form.
 public static System.Array resizeArray(System.Array oldArray, int newSize)
 {
     int oldSize = oldArray.Length;
     System.Type elementType = oldArray.GetType().GetElementType();
     System.Array newArray = System.Array.CreateInstance(elementType, newSize);
     return newArray;
 }
        public When_resolving_two_types_with_same_name()
        {
            var a = new A { Int32Value = 0, StringValue = "" };
            var b = new { Int32Value = 0, StringValue = "" };

            var typeInfoA = new TypeInfo(a.GetType());
            var typeInfoB = new TypeInfo(b.GetType());

            typeInfoA.Name = "TestTypeName";
            typeInfoB.Name = "TestTypeName";

            typeInfoA.Namespace = "TestNamespace";
            typeInfoB.Namespace = "TestNamespace";

            typeInfoA.DeclaringType = null;
            typeInfoB.DeclaringType = null;

            var typeResolver = new TypeResolver();

            resolvedTypeA1 = typeResolver.ResolveType(typeInfoA);
            resolvedTypeB1 = typeResolver.ResolveType(typeInfoB);

            resolvedTypeA2 = typeResolver.ResolveType(typeInfoA);
            resolvedTypeB2 = typeResolver.ResolveType(typeInfoB);
        }
Example #30
0
        public void ArrayLiterals()
        {
            //You don't have to specify a type if the arguments can be inferred
            var array = new [] { 42 };
            Assert.Equal(typeof(int[]), array.GetType());
            Assert.Equal(new int[] { 42 }, array);

            //Are arrays 0-based or 1-based?
            Assert.Equal(42, array[((int)0)]);

            //This is important because...
            Assert.True(array.IsFixedSize);

            //...it means we can't do this: array[1] = 13;
            Assert.Throws(typeof(IndexOutOfRangeException), delegate() { array[1] = 13; });

            //This is because the array is fixed at length 1. You could write a function
            //which created a new array bigger than the last, copied the elements over, and
            //returned the new array. Or you could do this:
            List<int> dynamicArray = new List<int>();
            dynamicArray.Add(42);
            Assert.Equal(array, dynamicArray.ToArray());

            dynamicArray.Add(13);
            Assert.Equal((new int[] { 42, (int)13}), dynamicArray.ToArray());
        }