本文整理汇总了C#中System.Object.getClass方法的典型用法代码示例。如果您正苦于以下问题:C# Object.getClass方法的具体用法?C# Object.getClass怎么用?C# Object.getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Object
的用法示例。
在下文中一共展示了Object.getClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getInstance
/**
* Factory method that performs validation.
* <p>
* Creates a Factory that will return a clone of the same prototype object
* each time the factory is used. The prototype will be cloned using one of these
* techniques (in order):
* <ul>
* <li>public clone method
* <li>public copy constructor
* <li>serialization clone
* <ul>
*
* @param prototype the object to clone each time in the factory
* @return the <code>prototype</code> factory
* @throws IllegalArgumentException if the prototype is null
* @throws IllegalArgumentException if the prototype cannot be cloned
*/
public static Factory getInstance(Object prototype)
{
if (prototype == null)
{
return ConstantFactory.NULL_INSTANCE;
}
try
{
java.lang.reflect.Method method = prototype.getClass().getMethod("clone", (java.lang.Class[])null);
return new PrototypeCloneFactory(prototype, method);
}
catch (java.lang.NoSuchMethodException ex)
{
try
{
prototype.getClass().getConstructor(new java.lang.Class[] { prototype.getClass() });
return new InstantiateFactory(
prototype.getClass(),
new java.lang.Class[] { prototype.getClass() },
new Object[] { prototype });
}
catch (java.lang.NoSuchMethodException ex2)
{
if (prototype is java.io.Serializable)
{
return new PrototypeSerializationFactory((java.io.Serializable)prototype);
}
}
}
throw new java.lang.IllegalArgumentException("The prototype must be cloneable via a public clone method");
}
示例2: equals
public override bool equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
TypingUser other = (TypingUser) obj;
if (conversationUri == null) {
if (other.conversationUri != null) {
return false;
}
} else if (!conversationUri.equals(other.conversationUri)) {
return false;
}
if (userUri == null) {
if (other.userUri != null) {
return false;
}
} else if (!userUri.equals(other.userUri)) {
return false;
}
if (!exists.equals(other.exists)) {
return false;
}
return true;
}
示例3: equals
public override bool equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Contact other = (Contact) obj;
if (uri == null) {
if (other.uri != null) {
return false;
}
} else if (!uri.equals(other.uri)) {
return false;
}
if (!exists.equals(other.exists)) {
return false;
}
return true;
}
示例4: Equals
public override bool Equals(Object anotherState)
{
if (this == anotherState)
{
return true;
}
if ((anotherState == null)
|| (this.getClass() != anotherState.getClass()))
{
return false;
}
GameState another = (GameState)anotherState;
Set keySet1 = state.keySet();
Iterator i = keySet1.iterator();
Iterator j = another.state.keySet().iterator();
while (i.hasNext())
{
String key = (String)i.next();
bool keymatched = false;
bool valueMatched = false;
while (j.hasNext())
{
String key2 = (String)j.next();
if (key.Equals(key2))
{
keymatched = true;
if (state.get(key).Equals(another.state.get(key2)))
{
valueMatched = true;
}
break;
}
}
if (!((keymatched) && valueMatched))
{
return false;
}
}
return true;
}
示例5: getIterator
public Iterator<?> getIterator(Object obj, JexlInfo info) {
if (obj instanceof Iterator<?>) {
return ((Iterator <?>) obj);
}
if (obj.getClass().isArray())
{
return new ArrayIterator(obj);
}
if (obj instanceof Map<?, ?>) {
return ((Map <?, ?>) obj).values().iterator();
}
if (obj instanceof Enumeration<?>) {
return new EnumerationIterator<Object>((Enumeration<Object>)obj);
}
if (obj instanceof Iterable<?>) {
return ((Iterable <?>) obj).iterator();
}
try
{
// look for an iterator() method to support the JDK5 Iterable
// interface or any user tools/DTOs that want to work in
// foreach without implementing the Collection interface
AbstractExecutor.Method it = getMethodExecutor(obj, "iterator", null);
if (it != null && Iterator.class.isAssignableFrom(it.getReturnType())) {
示例6: equals
public override bool equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
User other = (User) obj;
if (avatarHash == null) {
if (other.avatarHash != null) {
return false;
}
} else if (!avatarHash.equals(other.avatarHash)) {
return false;
}
if (currentStatus == null) {
if (other.currentStatus != null) {
return false;
}
} else if (!currentStatus.equals(other.currentStatus)) {
return false;
}
if (dateOfBirth != (other.dateOfBirth)) {
return false;
}
if (displayName == null) {
if (other.displayName != null) {
return false;
}
} else if (!displayName.equals(other.displayName)) {
return false;
}
if (ecoid == null) {
if (other.ecoid != null) {
return false;
}
} else if (!ecoid.equals(other.ecoid)) {
return false;
}
if (emailAddress == null) {
if (other.emailAddress != null) {
return false;
}
} else if (!emailAddress.equals(other.emailAddress)) {
return false;
}
if (gender == null) {
if (other.gender != null) {
return false;
}
} else if (!gender.equals(other.gender)) {
return false;
}
if (installedApps == null) {
if (other.installedApps != null) {
return false;
}
} else if (!installedApps.equals(other.installedApps)) {
return false;
}
if (location == null) {
if (other.location != null) {
return false;
}
} else if (!location.equals(other.location)) {
return false;
}
if (maxVcardSize != (other.maxVcardSize)) {
return false;
}
if (nickname == null) {
if (other.nickname != null) {
return false;
}
} else if (!nickname.equals(other.nickname)) {
return false;
}
if (nowPlayingMessage == null) {
if (other.nowPlayingMessage != null) {
return false;
}
} else if (!nowPlayingMessage.equals(other.nowPlayingMessage)) {
return false;
}
if (personalMessage == null) {
if (other.personalMessage != null) {
return false;
}
} else if (!personalMessage.equals(other.personalMessage)) {
return false;
}
if (personalMessageTimestamp != (other.personalMessageTimestamp)) {
return false;
}
if (personalMessageTpaUri == null) {
if (other.personalMessageTpaUri != null) {
//.........这里部分代码省略.........
示例7: Write
/// <summary>
/// This <c>write</c> method is used to convert the provided
/// object to an XML element. This creates a child node from the
/// given <c>OutputNode</c> object. Once this child element
/// is created it is populated with the fields of the source object
/// in accordance with the XML schema class.
/// </summary>
/// <param name="source">
/// this is the object to be serialized to XML
/// </param>
/// <param name="expect">
/// this is the class that is expected to be written
/// </param>
/// <param name="name">
/// this is the name of the root annotation used
/// </param>
public void Write(OutputNode node, Object source, Class expect, String name) {
OutputNode child = node.getChild(name);
Type type = GetType(expect);
if(source != null) {
Class actual = source.getClass();
if(!context.SetOverride(type, source, child)) {
Converter convert = GetComposite(actual);
Decorator decorator = GetDecorator(actual);
decorator.decorate(child);
convert.Write(child, source);
}
}
child.commit();
}
示例8: size
/**
* Gets the size of the collection/iterator specified.
* <p>
* This method can handles objects as follows
* <ul>
* <li>Collection - the collection size
* <li>Map - the map size
* <li>Array - the array size
* <li>Iterator - the number of elements remaining in the iterator
* <li>Enumeration - the number of elements remaining in the enumeration
* </ul>
*
* @param object the object to get the size of
* @return the size of the specified collection
* @throws IllegalArgumentException thrown if object is not recognised or null
* @since Commons Collections 3.1
*/
public static int size(Object obj)
{
int total = 0;
if (obj is java.util.Map<Object, Object>)
{
total = ((java.util.Map<Object, Object>)obj).size();
}
else if (obj is java.util.Collection<Object>)
{
total = ((java.util.Collection<Object>)obj).size();
}
else if (obj is Object[])
{
total = ((Object[])obj).Length;
}
else if (obj is java.util.Iterator<Object>)
{
java.util.Iterator<Object> it = (java.util.Iterator<Object>)obj;
while (it.hasNext())
{
total++;
it.next();
}
}
else if (obj is java.util.Enumeration<Object>)
{
java.util.Enumeration<Object> it = (java.util.Enumeration<Object>)obj;
while (it.hasMoreElements())
{
total++;
it.nextElement();
}
}
else if (obj == null)
{
throw new java.lang.IllegalArgumentException("Unsupported object type: null");
}
else
{
try
{
total = java.lang.reflect.Array.getLength(obj);
}
catch (java.lang.IllegalArgumentException ex)
{
throw new java.lang.IllegalArgumentException("Unsupported object type: " + obj.getClass().getName());
}
}
return total;
}
示例9: get
//.........这里部分代码省略.........
* <p>
* The supported types, and associated semantics are:
* <ul>
* <li> Map -- the value returned is the <code>Map.Entry</code> in position
* <code>index</code> in the map's <code>entrySet</code> iterator,
* if there is such an entry.</li>
* <li> List -- this method is equivalent to the list's get method.</li>
* <li> Array -- the <code>index</code>-th array entry is returned,
* if there is such an entry; otherwise an <code>IndexOutOfBoundsException</code>
* is thrown.</li>
* <li> Collection -- the value returned is the <code>index</code>-th object
* returned by the collection's default iterator, if there is such an element.</li>
* <li> Iterator or Enumeration -- the value returned is the
* <code>index</code>-th object in the Iterator/Enumeration, if there
* is such an element. The Iterator/Enumeration is advanced to
* <code>index</code> (or to the end, if <code>index</code> exceeds the
* number of entries) as a side effect of this method.</li>
* </ul>
*
* @param object the object to get a value from
* @param index the index to get
* @return the object at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
* @throws IllegalArgumentException if the object type is invalid
*/
public static Object get(Object obj, int index)
{
if (index < 0)
{
throw new java.lang.IndexOutOfBoundsException("Index cannot be negative: " + index);
}
if (obj is java.util.Map<Object, Object>)
{
java.util.Map<Object, Object> map = (java.util.Map<Object, Object>)obj;
java.util.Iterator<Object> iterator = (java.util.Iterator<Object>)map.entrySet().iterator();
return get(iterator, index);
}
else if (obj is java.util.List<Object>)
{
return ((java.util.List<Object>)obj).get(index);
}
else if (obj is Object[])
{
return ((Object[])obj)[index];
}
else if (obj is java.util.Iterator<Object>)
{
java.util.Iterator<Object> it = (java.util.Iterator<Object>)obj;
while (it.hasNext())
{
index--;
if (index == -1)
{
return it.next();
}
else
{
it.next();
}
}
throw new java.lang.IndexOutOfBoundsException("Entry does not exist: " + index);
}
else if (obj is java.util.Collection<Object>)
{
java.util.Iterator<Object> iterator = ((java.util.Collection<Object>)obj).iterator();
return get(iterator, index);
}
else if (obj is java.util.Enumeration<Object>)
{
java.util.Enumeration<Object> it = (java.util.Enumeration<Object>)obj;
while (it.hasMoreElements())
{
index--;
if (index == -1)
{
return it.nextElement();
}
else
{
it.nextElement();
}
}
throw new java.lang.IndexOutOfBoundsException("Entry does not exist: " + index);
}
else if (obj == null)
{
throw new java.lang.IllegalArgumentException("Unsupported object type: null");
}
else
{
try
{
return java.lang.reflect.Array.get(obj, index);
}
catch (java.lang.IllegalArgumentException ex)
{
throw new java.lang.IllegalArgumentException("Unsupported object type: " + obj.getClass().getName());
}
}
}
示例10: getInvocationHandler
/**
* Returns the invocation handler of the specified proxy instance.
*
* @param proxy
* the proxy instance
* @return the invocation handler of the specified proxy instance
* @throws IllegalArgumentException
* if the supplied {@code proxy} is not a proxy object
*/
public static InvocationHandler getInvocationHandler(Object proxy)
{
//throws IllegalArgumentException {
if (isProxyClass(proxy.getClass())) {
return ((Proxy) proxy).h;
}
throw new IllegalArgumentException("not a proxy instance"); //$NON-NLS-1$
}
示例11: Write
/// <summary>
/// This <c>write</c> method is used to perform serialization of
/// the given source object. Serialization is performed by appending
/// elements and attributes from the source object to the provided XML
/// element object. How the objects contacts are serialized is
/// determined by the XML schema class that the source object is an
/// instance of. If a required contact is null an exception is thrown.
/// </summary>
/// <param name="source">
/// this is the source object to be serialized
/// </param>
/// <param name="node">
/// the XML element the object is to be serialized to
/// </param>
public void Write(OutputNode node, Object source) {
Class type = source.getClass();
Schema schema = context.GetSchema(type);
Caller caller = schema.GetCaller();
try {
if(schema.IsPrimitive()) {
primitive.Write(node, source);
} else {
caller.persist(source);
Write(node, source, schema);
}
} finally {
caller.complete(source);
}
}
示例12: Validate
/// <summary>
/// This method checks to see if there are any <c>Label</c>
/// objects remaining in the provided map that are required. This is
/// used when deserialization is performed to ensure the the XML
/// element deserialized contains sufficient details to satisfy the
/// XML schema class annotations. If there is a required label that
/// remains it is reported within the exception thrown.
/// </summary>
/// <param name="map">
/// this is the map to check for remaining labels
/// </param>
/// <param name="source">
/// this is the object that has been deserialized
/// </param>
public void Validate(InputNode node, LabelMap map, Object source) {
Position line = node.getPosition();
Class expect = type.Type;
if(source != null) {
expect = source.getClass();
}
for(Label label : map) {
if(label.isRequired() && revision.IsEqual()) {
throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line);
}
Object value = label.getEmpty(context);
if(value != null) {
criteria.Set(label, value);
}
}
}
示例13: Read
/// <summary>
/// This <c>read</c> method is used to perform deserialization
/// of the provided node object using a delegate converter. This is
/// typically another <c>Composite</c> converter, or if the
/// node is an attribute a <c>Primitive</c> converter. When
/// the delegate converter has completed the deserialized value is
/// assigned to the contact.
/// </summary>
/// <param name="node">
/// this is the node that contains the contact value
/// </param>
/// <param name="source">
/// the type of the object that is being deserialized
/// </param>
/// <param name="label">
/// this is the label used to create the converter
/// </param>
public Object Read(InputNode node, Object source, Label label) {
Object object = ReadObject(node, source, label);
if(object == null) {
Position line = node.getPosition();
Class expect = type.Type;
if(source != null) {
expect = source.getClass();
}
if(label.isRequired() && revision.IsEqual()) {
throw new ValueRequiredException("Empty value for %s in %s at %s", label, expect, line);
}
} else {
if(object != label.getEmpty(context)) {
criteria.Set(label, object);
}
}
return object;
}
示例14: ReadElement
/// <summary>
/// This <c>readElement</c> method is used for deserialization
/// of the provided node object using a delegate converter. This is
/// typically another <c>Composite</c> converter, or if the
/// node is an attribute a <c>Primitive</c> converter. When
/// the delegate converter has completed the deserialized value is
/// assigned to the contact.
/// </summary>
/// <param name="node">
/// this is the node that contains the contact value
/// </param>
/// <param name="source">
/// the type of the object that is being deserialized
/// </param>
/// <param name="map">
/// this is the map that contains the label objects
/// </param>
public void ReadElement(InputNode node, Object source, LabelMap map) {
String name = node.GetName();
Label label = map.take(name);
if(label == null) {
label = criteria.Get(name);
}
if(label == null) {
Position line = node.getPosition();
Class type = source.getClass();
if(map.IsStrict(context) && revision.IsEqual()) {
throw new ElementException("Element '%s' does not have a match in %s at %s", name, type, line);
} else {
node.skip();
}
} else {
Read(node, source, label);
}
}
示例15: WriteText
/// <summary>
/// This write method is used to write the text contact from the
/// provided source object to the XML element. This takes the text
/// value from the source object and writes it to the single contact
/// marked with the <c>Text</c> annotation. If the value is
/// null and the contact value is required an exception is thrown.
/// </summary>
/// <param name="source">
/// this is the source object to be serialized
/// </param>
/// <param name="node">
/// this is the XML element to write text value to
/// </param>
/// <param name="schema">
/// this is used to track the referenced elements
/// </param>
public void WriteText(OutputNode node, Object source, Schema schema) {
Label label = schema.getText();
if(label != null) {
Contact contact = label.getContact();
Object value = contact.Get(source);
Class type = source.getClass();
if(value == null) {
value = label.getEmpty(context);
}
if(value == null && label.isRequired()) {
throw new TextException("Value for %s is null for %s", label, type);
}
WriteText(node, value, label);
}
}