private bool IsNumeric(System.Reflection.FieldInfo field) { System.Type clazz = field.GetType(); bool b = clazz == typeof(int) || clazz == typeof(long); if (b) { return(b); } b = clazz == typeof(long) || clazz == typeof(int); if (b) { return(b); } b = clazz == typeof(float) || clazz == typeof(double); if (b) { return(b); } b = clazz == typeof(System.Decimal) || clazz == typeof(System.Decimal); if (b) { return(b); } b = clazz == typeof(short) || clazz == typeof(byte); return(b); }
public FieldInfo(System.Reflection.FieldInfo fi) { name = fi.Name; // get acces modifires modificators = GetModificators(fi.GetType()); if (fi.IsLiteral && !fi.IsInitOnly) { modificators += "const "; } if (fi.IsInitOnly) { modificators += "readonly "; } if (fi.IsStatic) { modificators += "static "; } // check for generic types and get type if (fi.FieldType.IsGenericType) { type += fi.FieldType.Name + "<" + GetGeneric(fi.FieldType.GenericTypeArguments) + ">"; } else { type += fi.FieldType.Name; } }
public virtual bool AcceptField(System.Reflection.FieldInfo field) { if (field.GetType().Equals(typeof(Net.Vpc.Upa.Config.FieldDesc))) { return(true); } return(!Net.Vpc.Upa.Impl.Util.PlatformUtils.IsStatic(field) && !Net.Vpc.Upa.Impl.Util.PlatformUtils.IsTransient(field) && repo.GetFieldDecoration(field, typeof(System.NonSerializedAttribute)) == null); }
internal EntityBeanFieldAttribute(Net.Vpc.Upa.Impl.Util.EntityBeanType entityBeanAdapter, System.Reflection.FieldInfo field, System.Type cls) : base(entityBeanAdapter, (field).Name, field.GetType()) { this.field = field; //field.SetAccessible(true); }
/// <summary> /// Build a meta representation of an object /// <pre> /// warning: When an object has two fields with the same name (a private field with the same name in a parent class, the deeper field (of the parent) is ignored!) /// </pre> /// </summary> /// <param name="o"></param> /// <param name="ci"></param> /// <param name="recursive"></param> /// <returns>The ObjectInfo</returns> protected virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetObjectInfoInternal (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo nnoi, object o, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci, bool recursive, System.Collections.Generic.IDictionary <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo > alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback callback) { object value = null; if (o == null) { return(NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo.GetInstance()); } System.Type clazz = o.GetType(); NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType .GetFromClass(clazz); string className = OdbClassUtil.GetFullName(clazz); if (type.IsNative()) { return(GetNativeObjectInfoInternal(type, o, recursive, alreadyReadObjects, callback)); } // sometimes the clazz.getName() may not match the ci.getClassName() // It happens when the attribute is an interface or superclass of the // real attribute class // In this case, ci must be updated to the real class info if (ci != null && !clazz.FullName.Equals(ci.GetFullClassName())) { ci = GetClassInfo(className); nnoi = null; } NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo mainAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )nnoi; bool isRootObject = false; if (alreadyReadObjects == null) { alreadyReadObjects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo >(); isRootObject = true; } if (o != null) { NonNativeObjectInfo cachedNnoi = null; alreadyReadObjects.TryGetValue(o, out cachedNnoi); if (cachedNnoi != null) { ObjectReference or = new ObjectReference(cachedNnoi); return(or); } if (callback != null) { callback.ObjectFound(o); } } if (mainAoi == null) { mainAoi = BuildNnoi(o, ci, null, null, null, alreadyReadObjects); } alreadyReadObjects[o] = mainAoi; NeoDatis.Tool.Wrappers.List.IOdbList <System.Reflection.FieldInfo> fields = classIntrospector.GetAllFields(className); NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null; int attributeId = -1; // For all fields for (int i = 0; i < fields.Count; i++) { System.Reflection.FieldInfo field = fields[i]; try { value = field.GetValue(o); attributeId = ci.GetAttributeId(field.Name); if (attributeId == -1) { throw new ODBRuntimeException(NeoDatisError.ObjectIntrospectorNoFieldWithName.AddParameter(ci.GetFullClassName()).AddParameter(field.Name)); } ODBType valueType = null; if (value == null) { // If value is null, take the type from the field type // declared in the class valueType = ODBType.GetFromClass(field.FieldType); } else { // Else take the real attribute type! valueType = ODBType.GetFromClass(value.GetType()); } // for native fields if (valueType.IsNative()) { aoi = GetNativeObjectInfoInternal(valueType, value, recursive, alreadyReadObjects, callback); mainAoi.SetAttributeValue(attributeId, aoi); } else { //callback.objectFound(value); // Non Native Objects if (value == null) { ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(field.GetType())); aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo(clai); mainAoi.SetAttributeValue(attributeId, aoi); } else { ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(value.GetType())); if (recursive) { aoi = GetObjectInfoInternal(null, value, clai, recursive, alreadyReadObjects, callback ); mainAoi.SetAttributeValue(attributeId, aoi); } else { // When it is not recursive, simply add the object // values.add(value); throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError .AddParameter("Should not enter here - ObjectIntrospector - 'simply add the object'" )); } } } } catch (System.ArgumentException e) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError .AddParameter("in getObjectInfoInternal"), e); } catch (System.MemberAccessException e) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError .AddParameter("getObjectInfoInternal"), e); } } if (isRootObject) { alreadyReadObjects.Clear(); alreadyReadObjects = null; } return(mainAoi); }
public virtual int CompareField(int fieldIndex, object o1, object o2) { //Field field2 = getField(o2); object oo1 = null; object oo2 = null; System.Type type = null; try { if (o1 is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo && o2 is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi1 = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )o1; NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi2 = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )o2; oo1 = nnoi1.GetValueOf(fieldNames[fieldIndex]); oo2 = nnoi2.GetValueOf(fieldNames[fieldIndex]); type = oo1.GetType(); } else { System.Reflection.FieldInfo field1 = GetField(fieldIndex, o1); oo1 = field1.GetValue(o1); oo2 = field1.GetValue(o2); type = field1.GetType(); } // if(isNumeric(field1) && isNumeric(field2)){ if (type == typeof(int)) { return(way * CompareTo((int)oo1, (int)oo2)); } if (type == typeof(long)) { return(way * CompareTo((long)oo1, (long)oo2)); } if (type == typeof(short)) { return(way * CompareTo((short)oo1, (short)oo2)); } if (type == typeof(double)) { return(way * CompareTo((double)oo1, (double)oo2)); } if (type == typeof(float)) { return(way * CompareTo((float)oo1, (float)oo2)); } if (type == typeof(byte)) { return(way * CompareTo((byte)oo1, (byte)oo2)); } if (type == typeof(int)) { return(way * CompareTo((int)oo1, (int)oo2)); } if (type == typeof(long)) { return(way * CompareToLong((long)oo1, (long)oo2)); } if (type == typeof(System.DateTime)) { return(way * CompareTo((System.DateTime)oo1, (System.DateTime)oo2)); } return(way * CompareTo(oo1, oo2)); } catch (System.Exception e) { throw new System.Exception(e.Message); } }