//"x in y" should return true whenever "for (var z in y) if (z === x) return true" returns true public static bool JScriptIn(Object v1, Object v2){ bool result = false; if (v2 is ScriptObject) return !(((ScriptObject)v2).GetMemberValue(Convert.ToString(v1)) is Missing); else if (v2 is Array){ Array arr = (Array)v2; double d = Convert.ToNumber(v1); int i = (int)d; return d == i && arr.GetLowerBound(0) <= i && i <= arr.GetUpperBound(0); }else if (v2 is IEnumerable){ if (v1 == null) return false; //Do not enumerate when a direct lookup is available if (v2 is IDictionary) return ((IDictionary)v2).Contains(v1); if (v2 is IExpando){ MemberInfo[] members = ((IReflect)v2).GetMember(Convert.ToString(v1), BindingFlags.Instance|BindingFlags.DeclaredOnly|BindingFlags.Public); return members.Length > 0; } IEnumerator enu = ((IEnumerable)v2).GetEnumerator(); while (!result && enu.MoveNext()) if (v1.Equals(enu.Current)) return true; }else if (v2 is IEnumerator){ if (v1 == null) return false; IEnumerator enu = (IEnumerator)v2; while (!result && enu.MoveNext()) if (v1.Equals(enu.Current)) return true; } throw new JScriptException(JSError.ObjectExpected); }
/// <seealso cref="Graph.getEdge(Object, Object)"> /// </seealso> public override Edge getEdge(System.Object sourceVertex, System.Object targetVertex) { if (Enclosing_Instance.containsVertex(sourceVertex) && Enclosing_Instance.containsVertex(targetVertex)) { System.Collections.IEnumerator iter = getEdgeContainer(sourceVertex).m_vertexEdges.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (iter.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" Edge e = (Edge)iter.Current; bool equalStraight = sourceVertex.Equals(e.Source) && targetVertex.Equals(e.Target); bool equalInverted = sourceVertex.Equals(e.Target) && targetVertex.Equals(e.Source); if (equalStraight || equalInverted) { return(e); } } } return(null); }
public static void AssertEqualsHashCode(Object o, Object o2) { if (o.Equals(o2)) { if (!o2.Equals(o)) { Assert.Fail( String.Empty + o + " equals " + o2 + " but not vice versa"); } // Test for the guarantee that equal objects // must have equal hash codes if (o2.GetHashCode() != o.GetHashCode()) { // Don't use Assert.AreEqual directly because it has // quite a lot of overhead Assert.Fail( String.Empty + o + " and " + o2 + " don't have equal hash codes"); } } else { if (o2.Equals(o)) { Assert.Fail(String.Empty + o + " does not equal " + o2 + " but not vice versa"); } // At least check that GetHashCode doesn't throw try { o.GetHashCode(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { o2.GetHashCode(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } } }
public String getPatientName(Object markerID) { if (markerID.Equals("PatientMarkerConfig.txt")) return "Smith, John"; else if (markerID.Equals(2)) return "Doe, Jane"; return "No Patient"; }
/// <summary> Get the boolean value associated with an index. /// The string values "true" and "false" are converted to boolean. /// /// </summary> /// <param name="index">The index must be between 0 and length() - 1. /// </param> /// <returns> The truth. /// </returns> /// <throws> JSONException If there is no value for the index or if the </throws> /// <summary> value is not convertable to boolean. /// </summary> public virtual bool getBoolean(int index) { System.Object o = get_Renamed(index); if (o.Equals(false) || (o is System.String && ((System.String)o).ToUpper().Equals("false".ToUpper()))) { return(false); } else if (o.Equals(true) || (o is System.String && ((System.String)o).ToUpper().Equals("true".ToUpper()))) { return(true); } throw new JSONException("JSONArray[" + index + "] is not a Boolean."); }
public object Convert(Object value , Type targetType , Object parameter , System.Globalization.CultureInfo culture) { if (value.Equals("儿童")) { return new SolidColorBrush(Colors.Yellow); } if (value.Equals("成人")) { return new SolidColorBrush(Colors.Orange); } else return new SolidColorBrush(Colors.Gray); }
static void Main(string[] args) { Object o = new Object(); Object p = new Object(); Object q = o; Console.WriteLine(o.Equals(p)); Console.WriteLine(o.Equals(q)); Console.WriteLine(Object.Equals(p, q)); Console.ReadKey(); }
/// <seealso cref="org._3pq.jgrapht.Edge.oppositeVertex(java.lang.Object)"> /// </seealso> public virtual System.Object oppositeVertex(System.Object v) { if (v.Equals(m_source)) { return(m_target); } else if (v.Equals(m_target)) { return(m_source); } else { throw new System.ArgumentException("no such vertex"); } }
protected void AssertArgumentNotEquals(Object anObject1, Object anObject2, String aMessage) { if (anObject1.Equals(anObject2)) { throw new ArgumentException(aMessage); } }
public static void IsNull(System.Object argument, string argumentName) { if (argument == null || argument.Equals(null)) { throw new ArgumentNullException(argumentName); } }
/// <summary> Calculates the value of the logical expression /// * /// arg1 == arg2 /// * /// All class types are supported. Uses equals() to /// determine equivalence. This should work as we represent /// with the types we already support, and anything else that /// implements equals() to mean more than identical references. /// * /// * /// </summary> /// <param name="context"> internal context used to evaluate the LHS and RHS /// </param> /// <returns>true if equivalent, false if not equivalent, /// false if not compatible arguments, or false /// if either LHS or RHS is null /// /// </returns> public override bool evaluate(InternalContextAdapter context) { System.Object left = jjtGetChild(0).value_Renamed(context); System.Object right = jjtGetChild(1).value_Renamed(context); /* * they could be null if they are references and not in the context */ if (left == null || right == null) { rsvc.error((left == null?"Left":"Right") + " side (" + jjtGetChild((left == null?0:1)).literal() + ") of '==' operation " + "has null value. " + "If a reference, it may not be in the context." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return(false); } /* * check to see if they are the same class. I don't think this is slower * as I don't think that getClass() results in object creation, and we can * extend == to handle all classes */ if (left.GetType().Equals(right.GetType())) { return(left.Equals(right)); } else { rsvc.error("Error in evaluation of == expression." + " Both arguments must be of the same Class." + " Currently left = " + left.GetType() + ", right = " + right.GetType() + ". " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "] (ASTEQNode)"); } return(false); }
/// <seealso cref="Graph.addEdge(Object, Object)"> /// </seealso> public override Edge addEdge(System.Object sourceVertex, System.Object targetVertex) { assertVertexExist(sourceVertex); assertVertexExist(targetVertex); if (!m_allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) { return(null); } if (!m_allowingLoops && sourceVertex.Equals(targetVertex)) { throw new System.ArgumentException(LOOPS_NOT_ALLOWED); } Edge e = m_edgeFactory.createEdge(sourceVertex, targetVertex); if (containsEdge(e)) { // this restriction should stay! return(null); } else { m_edgeSet.Add(e); m_specifics.addEdgeToTouchingVertices(e); return(e); } }
public void OnSyncOne(Object InObj, int InIndex, Object InValue) { if (null == InObj) { throw new ArgumentNullException(); } if (0 > InIndex || InIndex >= propertyInfoLength) { throw new IndexOutOfRangeException(InIndex + "< 0 || " + InIndex + " >= " + propertyInfoLength); } if (InObj.GetType() != classType) { throw new ArgumentException("The input type not matched."); } if (null != InValue) { PropertyInfo info = propertyInfos[InIndex]; Object oldValue = info.GetValue(InObj, null); if (!InValue.Equals(oldValue)) { Object value = InValue; if (null == oldValue) { value = ChangeType(InValue, info.PropertyType); //Convert.ChangeType(InValue, info.PropertyType); } info.SetValue(InObj, value, null); if (InObj is Base) { (InObj as Base).OnPropertyChanged(info.Name, oldValue, InValue); } } } }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { if (e == null) { throw new System.NullReferenceException(); } else if (containsEdge(e)) { return(false); } System.Object sourceVertex = e.Source; System.Object targetVertex = e.Target; assertVertexExist(sourceVertex); assertVertexExist(targetVertex); assertCompatibleWithEdgeFactory(e); if (!m_allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) { return(false); } if (!m_allowingLoops && sourceVertex.Equals(targetVertex)) { throw new System.ArgumentException(LOOPS_NOT_ALLOWED); } m_edgeSet.Add(e); m_specifics.addEdgeToTouchingVertices(e); return(true); }
public static bool AreObjectsEqual(Object x, Object y) { if (x == y) return true; if (x is ArrayList) { if (!(y is ArrayList)) return false; ArrayList a = x as ArrayList; ArrayList b = y as ArrayList; if (a.Count != b.Count) { return false; } else { for (int i=0; i < a.Count; ++i) { if (!AreObjectsEqual(a[i], b[i])) return false; } return true; } } else { return x.Equals(y); } }
public static bool equals(System.Collections.IList a1, System.Collections.IList a2) { if (a1 == a2) { return(true); } if (a1 == null || a2 == null) { return(false); } int length = a1.Count; if (a2.Count != length) { return(false); } for (int i = 0; i < length; i++) { System.Object o1 = a1[i]; System.Object o2 = a2[i]; if (!(o1 == null?o2 == null:o1.Equals(o2))) { return(false); } } return(true); }
public void AddOrUpdateWeight(T1 value, float weight) { if (weight == 0) { throw new ArgumentException("weighted value cannot have a 0% chance."); } WeightedChance <T1> existing = this._weights.FirstOrDefault(x => Object.Equals(x.Value, value)); if (existing == null) { var instance = new T2 { Value = value, Weight = weight }; this._weights.Add(instance); } else { existing.Weight = weight; } this._adjusted = false; }
private static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs, bool expectedResult) { if ((lhs == null) && (rhs == null)) { assertTrue( "Your check is dubious...why would you expect null != null?", expectedResult); return; } if ((lhs == null) || (rhs == null)) { assertFalse( "Your check is dubious...why would you expect an object " + "to be equal to null?", expectedResult); } if (lhs != null) { assertEquals(expectedResult, lhs.Equals(rhs)); } if (rhs != null) { assertEquals(expectedResult, rhs.Equals(lhs)); } if (expectedResult) { var hashMessage = "hashCode() values for equal objects should be the same"; assertTrue(hashMessage, lhs.GetHashCode() == rhs.GetHashCode()); } }
/// <summary> /// Returns a portion of the list whose keys are greater that the lowerLimit parameter less than the upperLimit parameter. /// </summary> /// <param name="l">The list where the portion will be extracted.</param> /// <param name="limit">The start element of the portion to extract.</param> /// <param name="limit">The end element of the portion to extract.</param> /// <returns>The portion of the collection.</returns> public static System.Collections.SortedList SubMap(System.Collections.SortedList list, System.Object lowerLimit, System.Object upperLimit) { System.Collections.Comparer comparer = System.Collections.Comparer.Default; System.Collections.SortedList newList = new System.Collections.SortedList(); if (list != null) { if ((list.Count > 0) && (!(lowerLimit.Equals(upperLimit)))) { int index = 0; while (comparer.Compare(list.GetKey(index), lowerLimit) < 0) { index++; } for (; index < list.Count; index++) { if (comparer.Compare(list.GetKey(index), upperLimit) >= 0) { break; } newList.Add(list.GetKey(index), list[list.GetKey(index)]); } } } return(newList); }
public static bool equals(System.Object a, System.Object b) { a = unwrap(a); b = unwrap(b); if (a == null) { return(b == null); } else if (a is System.Collections.ArrayList) { return(b is System.Collections.ArrayList && vectorEquals((System.Collections.ArrayList)a, (System.Collections.ArrayList)b)); } else { //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" if (a is System.Collections.Hashtable) { //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" return(b is System.Collections.Hashtable && hashMapEquals((System.Collections.Hashtable)a, (System.Collections.Hashtable)b)); } else { return(a.Equals(b)); } } }
/// <summary> /// Compares the entire members of one array whith the other one. /// </summary> /// <param name="array1">The array to be compared.</param> /// <param name="array2">The array to be compared with.</param> /// <returns>Returns true if the two specified arrays of Objects are equal /// to one another. The two arrays are considered equal if both arrays /// contain the same number of elements, and all corresponding pairs of /// elements in the two arrays are equal. Two objects e1 and e2 are /// considered equal if (e1==null ? e2==null : e1.equals(e2)). In other /// words, the two arrays are equal if they contain the same elements in /// the same order. Also, two array references are considered equal if /// both are null.</returns> public static bool Equals(System.Array array1, System.Array array2) { bool result = false; if ((array1 == null) && (array2 == null)) { result = true; } else if ((array1 != null) && (array2 != null)) { if (array1.Length == array2.Length) { int length = array1.Length; result = true; for (int index = 0; index < length; index++) { System.Object o1 = array1.GetValue(index); System.Object o2 = array2.GetValue(index); if (o1 == null && o2 == null) { continue; // they match } else if (o1 == null || !o1.Equals(o2)) { result = false; break; } } } } return(result); }
public virtual void assertEqual(Object result, Object expecting) { if (result == null && expecting != null) { throw new FailedAssertionException("expecting \"" + expecting + "\"; found null"); } assertTrue(result.Equals(expecting), "expecting \"" + expecting + "\"; found \"" + result + "\""); }
public virtual bool evaluate(System.Object object1, System.Object object2) { if (object1 == null) { return(object2 == null); } return(object1.Equals(object2)); }
bool HashCodesMatchEquals(System.Object obj1, System.Object obj2) { if (obj1.Equals(obj2)) { return(obj1.GetHashCode() == obj2.GetHashCode()); } return(obj1.GetHashCode() != obj2.GetHashCode()); }
private bool SubEqual(System.Object o1, System.Object o2) { if (o1 == null) { return(o2 == null); } return(o1.Equals(o2)); }
public override bool evaluate(System.Object object1, System.Object object2) { if (object1 == null) { return(!(object2 == null)); } return(!object1.Equals(object2)); }
protected virtual void inventoryFullOnPurchase(System.Object o) { if (o.Equals(this)) { EventManager.instance.returnInventoryFullEvent -= this.inventoryFullOnPurchase; EventManager.instance.returnInventoryNotFullEvent -= this.inventoryNotFullOnPurchase; } }
public static void IsEquals(Object expectedValue, Object actualValue, string message) { if (actualValue.Equals(expectedValue)) return; string s = message != null ? ": " + message : String.Empty; string format = String.Format("Expected {0} but encountered {1}{2}", expectedValue, actualValue, s); throw new AssertionFailedException(format); }
public static bool IsNotNull(System.Object obj) { if (obj != null && !obj.Equals(null)) { return(true); } return(false); }
protected virtual void returnUnaffordable(System.Object o) { if (o.Equals(this)) { EventManager.instance.returnPointCountGreaterOrEqualEvent -= this.returnAffordable; EventManager.instance.returnPointCountLessEvent -= this.returnUnaffordable; } }
public bool Equals(EventPattern <TEventArgs> other) #endif { if ((object)other == null) { return(false); } return(((TSender)sender == null ? (TSender)other.sender == null : sender.Equals(other.sender)) && e.Equals(other.e)); }
/// <summary> /// 判空 /// </summary> /// <param name="sysObj"></param> /// <returns></returns> private bool IsNull(SystemObject sysObj) { if (sysObj == null || sysObj.Equals(null)) { return(true); } return(false); }
/// <include file='doc\Object.uex' path='docs/doc[@for="Object.Equals1"]/*' /> public static bool Equals(Object objA, Object objB) { if (objA==objB) { return true; } if (objA==null || objB==null) { return false; } return objA.Equals(objB); }
protected new bool Equals(Object o1, Object o2) { if (o1 == null) { return o2 == null; } else if (o2 == null) { return false; } else { return o1.Equals(o2); } }
public static void StateButton <T>(String text, T state, T value, Action <int> onStateChange, params GUILayoutOption[] options) { bool result; if ((result = GUILayout.Toggle(Object.Equals(state, value), text, GUI.skin.button, options)) != Object.Equals(state, value)) { onStateChange.Invoke(result ? 1 : -1); } }
public static void StateButton(GUIContent text, int state, int value, Action <int> onStateChange, params GUILayoutOption[] options) { bool result; if ((result = GUILayout.Toggle(Object.Equals(state, value), text, GUI.skin.button, options)) != Object.Equals(state, value)) { onStateChange.Invoke(result ? value : ~value); } }
public static void AreEqual(Object a, Object b, string message, bool launchDebugger) { if (a.Equals(b) == false) { if (launchDebugger) DebugUtil.LaunchDebugger(); throw new Exception(message + ", '" + a.ToString() + "' != '" + b.ToString() + "'"); } }
public new bool Equals(Object x, Object y) { if (x != null) { var tObj = x as IStructuralEquatable; return tObj != null ? tObj.Equals(y, this) : x.Equals(y); } return y == null; }
public void RemoveWeight(T1 value) { T2 existing = this._weights.FirstOrDefault(x => Object.Equals(x.Value, value)); if (existing != null) { this._weights.Remove(existing); this._adjusted = false; } }
public void TestEquals1() { { Object x = new Object(); Object y = new Object(); Assert("Object should equal itself", x.Equals(x)); Assert("object should not equal null", !x.Equals(null)); Assert("Different objects should not equal 1", !x.Equals(y)); Assert("Different objects should not equal 2", !y.Equals(x)); } { double x = Double.NaN; double y = Double.NaN; Assert("NaNs should always equal each other", ((Object)x).Equals(y)); } }
/// <summary> /// Static version allows repeated call without needed to grab lock for array each time. /// </summary> /// <param name="elem"></param> /// <param name="elementData"></param> /// <param name="length"></param> /// <returns></returns> private static int IndexOf(Object elem, Object[] elementData, int length) { if (elem == null) { for (int i = 0; i < length; i++) if (elementData[i] == null) return i; } else { for (int i = 0; i < length; i++) if (elem.Equals(elementData[i])) return i; } return -1; }
private System.String parseTempFolder(System.Object prefix, System.Object sufix) { // Temp folder if (prefix != null && sufix != null && !prefix.Equals(System.String.Empty) && !sufix.Equals(System.String.Empty)) { return(System.IO.Path.Combine(prefix.ToString(), sufix.ToString())); } else { return(null); } }
private Object _itemByValue(Object value) { if((value != null) && (this.cbo.Items.Count > 0)){ //this.cbo.SelectedItem = this.currentValue; if (this.cbo.Items.First() is EnumWrapper) { var rslt = this.cbo.Items.Cast<EnumWrapper>().FirstOrDefault((itm) => { return value.Equals(itm.Value); }); return rslt; } else return this.cbo.Items.First(); }else return null; }
public void TestObjectStaticEquals() { var mock = new Mock <InfoA>(); Object o = new InfoA(); mock.Setup(m => m.Equals(o)).Returns(false); Assert.That(Object.Equals(null, mock.Object), Is.False); mock.Verify(m => m.Equals(o), Times.Never); Assert.That(Object.Equals(mock.Object, o), Is.False); mock.Verify(m => m.Equals(o), Times.Once); }
public bool Equals(Object x, Object y) { //noinspection ObjectEquality if (x == y) { return true; } if (null == x || null == y) { return false; } return x.Equals(y); }
public void AssertEquals(Object a, Object b) { if (a != b) { if ((a == null && b != null) || (a != null && b == null)) { throw new SystemException("Values are not equal as one is null"); } if (a.GetType() != b.GetType()) { throw new SystemException("Comparing objects of different types '"+a.GetType()+"' and '"+b.GetType()+"'"); } if (!a.Equals(b)) { throw new SystemException("Values are not equal '"+a+"' and '"+b+"'"); } } }
public void TestChangeProperty(Unit unit, String propertyName, Object inputValue, Object expectedOutputValue) { Console.WriteLine("\nTesting changing an existing property's value"); unit.SetProperty(propertyName, inputValue); Object outputValue = unit.GetProperty(propertyName); if (expectedOutputValue.Equals(outputValue)) Console.WriteLine("Test passed"); else Console.WriteLine("Test failed: " + outputValue + " didn't match " + expectedOutputValue); }
public void TestUnitSpecificProperty(Unit unit, String propertyName, Object inputValue, Object expectedOutputValue) { Console.WriteLine("\nTesting setting/getting a unit-specific property"); unit.SetProperty(propertyName, inputValue); Object outputValue = unit.GetProperty(propertyName); if (expectedOutputValue.Equals(outputValue)) Console.WriteLine("Test passed"); else Console.WriteLine("Test failed: " + outputValue + " didn't match " + expectedOutputValue); }
private System.Object eval(System.Object oLhs, System.Object oRhs) { if (!(oLhs is System.String)) { return(Result.RESULT_UNKNOWN); } if (!(oRhs is System.String)) { return(Result.RESULT_UNKNOWN); } return((oLhs.Equals(oRhs))?Result.RESULT_TRUE:Result.RESULT_FALSE); }
public override bool containsValue (Object findValue) { if (findValue == null) { return false; } for (Enumeration e = getAttributeNames (); e.hasMoreElements (); ) { Object value = getAttribute ((String) e.nextElement ()); if (findValue.Equals (value)) { return true; } } return false; }
static void Main(string[] args) { Object o = new Object(); Object p = new Object(); Console.WriteLine(o.Equals(p)); String a = new String(new char[] {'a', 'g', 'n', 'a', 'l', 'd', 'o'}); String b = "agnaldo"; Console.WriteLine(a.Equals(b)); Console.ReadKey(); }
public bool IsDefaultValue(System.Object obj) { if (!hasDefaultValue) { return(false); } if (defaultValue == null) { return(obj == null); } return(defaultValue.Equals(obj)); }
public static void AssertEqualsHashCode(Object o, Object o2) { if (o.Equals(o2)) { if (!o2.Equals(o)) Assert.Fail( String.Format(CultureInfo.InvariantCulture, "{0} equals {1}, but not vice versa", o, o2)); // Test for the guarantee that equal objects // must have equal hash codes if (o2.GetHashCode() != o.GetHashCode()) { // Don't use Assert.AreEqual directly because it has // quite a lot of overhead Assert.Fail( String.Format(CultureInfo.InvariantCulture, "{0} and {1} don't have equal hash codes", o, o2)); } } else { if (o2.Equals(o)) Assert.Fail( String.Format(CultureInfo.InvariantCulture, "{0} does not equal {1}, but not vice versa", o, o2)); } }
static void Main(string[] args) { //System.Object //TODAS as classes e structs herdam de Object //Tipo: class e struct (e ...) //Membro: campo, propriedade, método, evento (e ...) //Tipo nome; //nome = new Tipo(); //new cria uma instância da classe (objeto) Object //Object é reference type Object o = new Object(); Console.WriteLine(o.ToString()); //representação String do objeto //Namespace.Tipo Console.WriteLine(o.GetHashCode()); //representação numérica do objeto //SE hashcodes de dois objetos são diferentes, //os objetos SÃO diferentes //SE os hashcodes forem iguais PODE SER que os //objetos sejam iguais Console.WriteLine(o.GetType().Name); //retorna o Type de um objeto //esse type será usado em Reflection, //entre outras coisas Object p = new Object(); Console.WriteLine(o.Equals(p)); //Equals compara dois objetos //o = p = null; //Não podemos acessar membros de null //não há objeto onde buscar esses membros //Console.WriteLine(o.Equals(p)); //Equals, ToString, GetHashCode e GetType são //métodos de INSTÂNCIA Console.WriteLine(Object.Equals(o, p)); Console.WriteLine(Object.ReferenceEquals(o, p)); //Equals e ReferenceEquals são métodos static Console.ReadKey(); }
static new public int Equals(IntPtr l) { try { System.Object self = (System.Object)checkSelf(l); System.Object a1; checkType(l, 2, out a1); var ret = self.Equals(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
// Compare two objects for equality. public static bool Equals(Object objA, Object objB) { if(objA == objB) { return true; } else if(objA != null && objB != null) { return objA.Equals(objB); } else { return false; } }
/** * Finds an item in a list * * @param item Item to be inserted * @return The position in the list of the item * or -1 if the item is not found */ public int contains(Object item) { if (!isEmpty()) { // Start at the beginning of the list // Stop when the item is found for (int i = 0; i < getCurrLength(); i++) { if (item.Equals(items[i])) { return i; } } } return -1; }
// Compares values of custom-attribute fields. private static bool AreFieldValuesEqual(Object thisValue, Object thatValue) { if (thisValue == null && thatValue == null) return true; if (thisValue == null || thatValue == null) return false; Type thisValueType = thisValue.GetType(); if (thisValueType.IsArray) { // Ensure both are arrays of the same type. if (!thisValueType.Equals(thatValue.GetType())) { return false; } Array thisValueArray = thisValue as Array; Array thatValueArray = thatValue as Array; if (thisValueArray.Length != thatValueArray.Length) { return false; } // Attributes can only contain single-dimension arrays, so we don't need to worry about // multidimensional arrays. Contract.Assert(thisValueArray.Rank == 1 && thatValueArray.Rank == 1); for (int j = 0; j < thisValueArray.Length; j++) { if (!AreFieldValuesEqual(thisValueArray.GetValue(j), thatValueArray.GetValue(j))) { return false; } } } else { // An object of type Attribute will cause a stack overflow. // However, this should never happen because custom attributes cannot contain values other than // constants, single-dimensional arrays and typeof expressions. Contract.Assert(!(thisValue is Attribute)); if (!thisValue.Equals(thatValue)) return false; } return true; }
public bool CompareObjects(Object obj1, Object obj2) { var result = false; if (obj1.Equals(obj2)) { return true; } Type type = obj1.GetType(); if (type.FullName.Equals(obj2.GetType().FullName)) { if (type.IsPrimitive) { return false; } if (type.IsArray) { MethodInfo lengthProperty = type.GetProperty("Length").GetGetMethod(); var arrayLength = (int) lengthProperty.Invoke(obj1, new object[] {}); if (!CompareObjects(arrayLength, lengthProperty.Invoke(obj2, new object[][] {}))) { return false; } MethodInfo getValueMethod = type.GetMethod("GetValue", new[] {Type.GetType("System.Int32")}); result = true; for (int i = 0; i < arrayLength; i++) { var propValue1 = getValueMethod.Invoke(obj1, new object[] {i}); var propValue2 = getValueMethod.Invoke(obj2, new object[] {i}); result = result && CompareObjects(propValue1, propValue2); } return result; } //May not work properly with some complex types! var propInfo = type.GetProperties(); result = true; foreach (var propertyInfo in propInfo) { var propValue1 = propertyInfo.GetGetMethod().Invoke(obj1, new object[] {}); var propValue2 = propertyInfo.GetGetMethod().Invoke(obj2, new object[] {}); result = result && CompareObjects(propValue1, propValue2); } } return result; }
public bool ChkStr(Object obj) { try { if (obj.Equals("") || obj == null) { return true; } else { return false; } } catch { return true; } }