Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / Object.cs / 1 / Object.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: Object
**
**
** Object is the root class for all CLR objects. This class
** defines only the basics.
**
**
===========================================================*/
namespace System {
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using CultureInfo = System.Globalization.CultureInfo;
using FieldInfo = System.Reflection.FieldInfo;
using BindingFlags = System.Reflection.BindingFlags;
using RemotingException = System.Runtime.Remoting.RemotingException;
// The Object is the root class for all object in the CLR System. Object
// is the super class for all other CLR objects and provide a set of methods and low level
// services to subclasses. These services include object synchronization and support for clone
// operations.
//
//This class contains no data and does not need to be serializable
[Serializable()]
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
public class Object
{
// Creates a new instance of an Object.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public Object()
{
}
// Returns a String which represents the object instance. The default
// for an object is to return the fully qualified name of the class.
//
public virtual String ToString()
{
return GetType().ToString();
}
// Returns a boolean indicating if the passed in object obj is
// Equal to this. Equality is defined as object equality for reference
// types and bitwise equality for value types using a loader trick to
// replace Equals with EqualsValue for value types).
//
public virtual bool Equals(Object obj)
{
return InternalEquals(this, obj);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool InternalEquals(Object objA, Object objB);
public static bool Equals(Object objA, Object objB)
{
if (objA==objB) {
return true;
}
if (objA==null || objB==null) {
return false;
}
return objA.Equals(objB);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static bool ReferenceEquals (Object objA, Object objB) {
return objA == objB;
}
// GetHashCode is intended to serve as a hash function for this object.
// Based on the contents of the object, the hash function will return a suitable
// value with a relatively random distribution over the various inputs.
//
// The default implementation returns the [....] block index for this instance.
// Calling it on the same object multiple times will return the same value, so
// it will technically meet the needs of a hash function, but it's less than ideal.
// Objects (& especially value classes) should override this method.
//
public virtual int GetHashCode()
{
return InternalGetHashCode(this);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int InternalGetHashCode(Object obj);
// Returns a Type object which represent this object instance.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern Type GetType();
// Allow an object to free resources before the object is reclaimed by the GC.
//
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
~Object()
{
}
// Returns a new object instance that is a memberwise copy of this
// object. This is always a shallow copy of the instance. The method is protected
// so that other object may only call this method on themselves. It is entended to
// support the ICloneable interface.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
protected extern Object MemberwiseClone();
// Sets the value specified in the variant on the field
//
private void FieldSetter(String typeName, String fieldName, Object val)
{
// Extract the field info object
FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
if (fldInfo.IsInitOnly)
throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
// Make sure that the value is compatible with the type
// of field
System.Runtime.Remoting.Messaging.Message.CoerceArg(val, fldInfo.FieldType);
// Set the value
fldInfo.SetValue(this, val);
}
// Gets the value specified in the variant on the field
//
private void FieldGetter(String typeName, String fieldName, ref Object val)
{
// Extract the field info object
FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
// Get the value
val = fldInfo.GetValue(this);
}
// Gets the field info object given the type name and field name.
//
private FieldInfo GetFieldInfo(String typeName, String fieldName)
{
Type t = GetType();
while(null != t)
{
if(t.FullName.Equals(typeName))
{
break;
}
t = t.BaseType;
}
if (null == t)
{
throw new RemotingException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"),
typeName));
}
FieldInfo fldInfo = t.GetField(fieldName, BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.IgnoreCase);
if(null == fldInfo)
{
throw new RemotingException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadField"),
fieldName, typeName));
}
return fldInfo;
}
}
// Internal methodtable used to instantiate the "canonical" methodtable for generic instantiations.
// The name "__Canon" will never been seen by users but it will appear a lot in debugger stack traces
// involving generics so it is kept deliberately short as to avoid being a nuisance.
[Serializable()]
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
internal class __Canon
{
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: Object
**
**
** Object is the root class for all CLR objects. This class
** defines only the basics.
**
**
===========================================================*/
namespace System {
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using CultureInfo = System.Globalization.CultureInfo;
using FieldInfo = System.Reflection.FieldInfo;
using BindingFlags = System.Reflection.BindingFlags;
using RemotingException = System.Runtime.Remoting.RemotingException;
// The Object is the root class for all object in the CLR System. Object
// is the super class for all other CLR objects and provide a set of methods and low level
// services to subclasses. These services include object synchronization and support for clone
// operations.
//
//This class contains no data and does not need to be serializable
[Serializable()]
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
public class Object
{
// Creates a new instance of an Object.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public Object()
{
}
// Returns a String which represents the object instance. The default
// for an object is to return the fully qualified name of the class.
//
public virtual String ToString()
{
return GetType().ToString();
}
// Returns a boolean indicating if the passed in object obj is
// Equal to this. Equality is defined as object equality for reference
// types and bitwise equality for value types using a loader trick to
// replace Equals with EqualsValue for value types).
//
public virtual bool Equals(Object obj)
{
return InternalEquals(this, obj);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool InternalEquals(Object objA, Object objB);
public static bool Equals(Object objA, Object objB)
{
if (objA==objB) {
return true;
}
if (objA==null || objB==null) {
return false;
}
return objA.Equals(objB);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static bool ReferenceEquals (Object objA, Object objB) {
return objA == objB;
}
// GetHashCode is intended to serve as a hash function for this object.
// Based on the contents of the object, the hash function will return a suitable
// value with a relatively random distribution over the various inputs.
//
// The default implementation returns the [....] block index for this instance.
// Calling it on the same object multiple times will return the same value, so
// it will technically meet the needs of a hash function, but it's less than ideal.
// Objects (& especially value classes) should override this method.
//
public virtual int GetHashCode()
{
return InternalGetHashCode(this);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int InternalGetHashCode(Object obj);
// Returns a Type object which represent this object instance.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern Type GetType();
// Allow an object to free resources before the object is reclaimed by the GC.
//
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
~Object()
{
}
// Returns a new object instance that is a memberwise copy of this
// object. This is always a shallow copy of the instance. The method is protected
// so that other object may only call this method on themselves. It is entended to
// support the ICloneable interface.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
protected extern Object MemberwiseClone();
// Sets the value specified in the variant on the field
//
private void FieldSetter(String typeName, String fieldName, Object val)
{
// Extract the field info object
FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
if (fldInfo.IsInitOnly)
throw new FieldAccessException(Environment.GetResourceString("FieldAccess_InitOnly"));
// Make sure that the value is compatible with the type
// of field
System.Runtime.Remoting.Messaging.Message.CoerceArg(val, fldInfo.FieldType);
// Set the value
fldInfo.SetValue(this, val);
}
// Gets the value specified in the variant on the field
//
private void FieldGetter(String typeName, String fieldName, ref Object val)
{
// Extract the field info object
FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);
// Get the value
val = fldInfo.GetValue(this);
}
// Gets the field info object given the type name and field name.
//
private FieldInfo GetFieldInfo(String typeName, String fieldName)
{
Type t = GetType();
while(null != t)
{
if(t.FullName.Equals(typeName))
{
break;
}
t = t.BaseType;
}
if (null == t)
{
throw new RemotingException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"),
typeName));
}
FieldInfo fldInfo = t.GetField(fieldName, BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.IgnoreCase);
if(null == fldInfo)
{
throw new RemotingException(String.Format(
CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadField"),
fieldName, typeName));
}
return fldInfo;
}
}
// Internal methodtable used to instantiate the "canonical" methodtable for generic instantiations.
// The name "__Canon" will never been seen by users but it will appear a lot in debugger stack traces
// involving generics so it is kept deliberately short as to avoid being a nuisance.
[Serializable()]
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
internal class __Canon
{
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionBase.cs
- SystemIPInterfaceStatistics.cs
- TextWriterEngine.cs
- ComPlusSynchronizationContext.cs
- ReadOnlyTernaryTree.cs
- unsafenativemethodstextservices.cs
- ChtmlFormAdapter.cs
- QilScopedVisitor.cs
- CookielessData.cs
- DbConnectionInternal.cs
- KeyNotFoundException.cs
- TextBreakpoint.cs
- TimeSpan.cs
- CommonDialog.cs
- Normalization.cs
- PassportAuthenticationModule.cs
- SimpleType.cs
- IsolatedStorageFile.cs
- InertiaExpansionBehavior.cs
- PackWebRequest.cs
- FrameworkElement.cs
- HttpModuleActionCollection.cs
- ValidatorUtils.cs
- FontNameConverter.cs
- ConfigUtil.cs
- Trace.cs
- ErrorStyle.cs
- ObfuscationAttribute.cs
- ComponentDispatcherThread.cs
- XmlElementAttribute.cs
- ASCIIEncoding.cs
- SimpleHandlerFactory.cs
- QuotedPrintableStream.cs
- SynchronizedCollection.cs
- MappingModelBuildProvider.cs
- GlyphsSerializer.cs
- UrlAuthorizationModule.cs
- Encoding.cs
- AlgoModule.cs
- ConfigXmlDocument.cs
- SmtpNetworkElement.cs
- ChildTable.cs
- DeviceSpecificChoiceCollection.cs
- SqlCacheDependencyDatabaseCollection.cs
- MachinePropertyVariants.cs
- MimeObjectFactory.cs
- WebPartZoneCollection.cs
- ZipArchive.cs
- DataSourceNameHandler.cs
- SequentialOutput.cs
- PointValueSerializer.cs
- DeviceContext.cs
- COM2ExtendedUITypeEditor.cs
- ProxyWebPartConnectionCollection.cs
- RowBinding.cs
- EntityDataSourceEntityTypeFilterItem.cs
- XmlRawWriter.cs
- BinaryCommonClasses.cs
- ContextToken.cs
- MaterialCollection.cs
- IOException.cs
- ListInitExpression.cs
- FigureParagraph.cs
- Viewport2DVisual3D.cs
- XmlSchemaCompilationSettings.cs
- BoundField.cs
- ProgressBarAutomationPeer.cs
- PresentationAppDomainManager.cs
- NamespaceQuery.cs
- Rules.cs
- InstanceData.cs
- BuildResult.cs
- WebProxyScriptElement.cs
- KnownTypesProvider.cs
- ComplusEndpointConfigContainer.cs
- CardSpaceSelector.cs
- DesignTimeParseData.cs
- CqlLexerHelpers.cs
- CodeDirectoryCompiler.cs
- EntityCommandExecutionException.cs
- ElementInit.cs
- XmlReaderSettings.cs
- PrintDialog.cs
- Transform3DGroup.cs
- XmlText.cs
- ToolStripPanelRow.cs
- DefaultShape.cs
- HandlerBase.cs
- Literal.cs
- GridViewSortEventArgs.cs
- PageClientProxyGenerator.cs
- DynamicPropertyHolder.cs
- CustomWebEventKey.cs
- DbgUtil.cs
- NetPipeSectionData.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- PtsCache.cs
- WebPartMovingEventArgs.cs
- StyleSelector.cs
- PathSegmentCollection.cs