Ejemplo n.º 1
0
        public Db4oField(IReflectField storedField)
        {
            internalName = storedField.GetName();
            name = AutomaticPropertyUtils.TryParseName(internalName);

            IReflectClass fieldType = storedField.GetFieldType();
            if(fieldType!=null)
                DataType = fieldType.ToString();
        }
Ejemplo n.º 2
0
 public virtual void Set(IReflectField field, object onObject, object value)
 {
     try
     {
         field.Set(onObject, value);
     }
     catch (Db4oException)
     {
     }
 }
Ejemplo n.º 3
0
		private IReflectField[] CreateDeclaredFieldsArray()
		{	
			FieldInfo[] fields = Sharpen.Runtime.GetDeclaredFields(_type);
			IReflectField[] reflectors = new IReflectField[fields.Length];
			for (int i = 0; i < reflectors.Length; i++)
			{
				reflectors[i] = CreateField(fields[i]);
			}
			return reflectors;
		}
Ejemplo n.º 4
0
 public virtual object Get(IReflectField field, object onObject)
 {
     try
     {
         return field.Get(onObject);
     }
     catch (Db4oException)
     {
         return null;
     }
 }
Ejemplo n.º 5
0
		private IReflectField[] CreateFields(string[] fieldNames, Type[] fieldTypes)
		{
			IReflectField[] fields = new IReflectField[fieldNames.Length + 1];
			for (int i = 0; i < fieldNames.Length; ++i)
			{
				fields[i] = new Db4objects.Db4o.Tests.Common.Reflect.Custom.CustomField(_repository
					, i, fieldNames[i], fieldTypes[i]);
			}
			fields[fields.Length - 1] = new CustomUidField(_repository);
			return fields;
		}
Ejemplo n.º 6
0
		internal FieldMetadata(ClassMetadata containingClass, IReflectField field, ClassMetadata
			 fieldType) : this(containingClass)
		{
			Init(field.GetName());
			_reflectField = field;
			_fieldType = fieldType;
			_fieldTypeID = fieldType.GetID();
			// TODO: beautify !!!  possibly pull up isPrimitive to ReflectField
			bool isPrimitive = field is GenericField ? ((GenericField)field).IsPrimitive() : 
				false;
			Configure(field.GetFieldType(), isPrimitive);
			CheckDb4oType();
			SetAvailable();
		}
		private FieldInfo[] MapFields(IReflectField[] fields, bool shouldStoreTransientFields
			)
		{
			if (!shouldStoreTransientFields)
			{
				fields = FilterTransientFields(fields);
			}
			FieldInfo[] fieldsMeta = new FieldInfo[fields.Length];
			for (int i = 0; i < fields.Length; ++i)
			{
				IReflectField field = fields[i];
				bool isArray = field.GetFieldType().IsArray();
				IReflectClass fieldClass = isArray ? field.GetFieldType().GetComponentType() : field
					.GetFieldType();
				bool isPrimitive = fieldClass.IsPrimitive();
				// TODO: need to handle NArray, currently it ignores NArray and alway sets NArray flag false.
				fieldsMeta[i] = new FieldInfo(field.GetName(), GetClassMeta(fieldClass), isPrimitive
					, isArray, false);
			}
			return fieldsMeta;
		}
Ejemplo n.º 8
0
    	private static FieldProperties FieldPropertiesFor(string className, IReflectField field)
    	{
    		FieldProperties fp = new FieldProperties(field.GetName(), field.GetFieldType().GetName());
    		FieldDetails fd = new FieldDetails(className, fp.Field);
    		fp.m_isPublic = fd.GetModifier();
    		fp.m_isIndexed = fd.IsIndexed();
    		
			return fp;
    	}
Ejemplo n.º 9
0
			public FieldOnObject(IReflectField field, object obj)
			{
				_field = field;
				_object = obj;
			}
Ejemplo n.º 10
0
 protected virtual void UpdateExistingStaticField(Transaction trans, StaticField existingField
     , IReflectField reflectField)
 {
     var stream = trans.Container();
     var newValue = StaticReflectFieldValue(reflectField);
     if (existingField.value != null && newValue != null && existingField.value.GetType
         () == newValue.GetType())
     {
         var id = stream.GetID(trans, existingField.value);
         if (id > 0)
         {
             if (existingField.value != newValue)
             {
                 // This is the clue:
                 // Bind the current static member to it's old database identity,
                 // so constants and enums will work with '=='
                 stream.Bind(trans, newValue, id);
                 // This may produce unwanted side effects if the static field object
                 // was modified in the current session. TODO:Add documentation case.
                 stream.Refresh(trans, newValue, int.MaxValue);
                 existingField.value = newValue;
             }
             return;
         }
     }
     if (newValue == null)
     {
         try
         {
             _fieldAccessor.Set(reflectField, null, existingField.value);
         }
         catch (Exception)
         {
         }
         // fail silently
         // TODO: why?
         return;
     }
     existingField.value = newValue;
 }
Ejemplo n.º 11
0
		private static bool TrySetField(IReflectField field, object onObject, object value
			)
		{
			try
			{
				field.Set(onObject, value);
			}
			catch
			{
				return false;
			}
			return true;
		}
Ejemplo n.º 12
0
		public IType ResolveFieldType(IReflectField field)
		{
			IReflectClass type = field.GetFieldType();
			return type != null ? ResolveType(type) : null;
		}
Ejemplo n.º 13
0
 private object StaticReflectFieldValue(IReflectField reflectField)
 {
     return _fieldAccessor.Get(reflectField, null);
 }
Ejemplo n.º 14
0
		public virtual void Set(IReflectField field, object onObject, object value)
		{
			field.Set(onObject, value);
		}
Ejemplo n.º 15
0
 private IReflectField[] CreateFields(string[] fieldNames, Type[] fieldTypes)
 {
     var fields = new IReflectField[fieldNames.Length + 1];
     for (var i = 0; i < fieldNames.Length; ++i)
     {
         fields[i] = new CustomField(_repository
             , i, fieldNames[i], fieldTypes[i]);
     }
     fields[fields.Length - 1] = new CustomUidField(_repository);
     return fields;
 }
Ejemplo n.º 16
0
		private void RenderSubObject(TreeGridNode parentNode, object parentObj, IReflectField field)
		{
			try
			{
				TreeGridNode objectNode = new TreeGridNode();
				parentNode.Nodes.Add(objectNode);
				object value = field.Get(parentObj);
				if (value != null)
				{
					container.Ext().Activate(value, 1);
				}
				objectNode.Tag = value;

				IType fieldType = ResolveFieldType(field);
				objectNode.Cells[0].Value = AppendIDTo(field.GetName(), GetLocalID(value), fieldType);

				objectNode.Cells[1].Value = value != null ? value.ToString() : BusinessConstants.DB4OBJECTS_NULL;

				SetFieldType(objectNode, fieldType);


				if (parentNode.Tag is DictionaryEntry && field.GetName() == BusinessConstants.DB4OBJECTS_KEY)
					objectNode.Cells[1].ReadOnly = true;
				else if (parentNode.Tag is DictionaryEntry && field.GetName() == BusinessConstants.DB4OBJECTS_VALUE)
					objectNode.Cells[1].ReadOnly = checkReadonlyStatus();
				else if (field.Get(parentObj) == null)
					objectNode.Cells[1].ReadOnly = true;
				else
					objectNode.Cells[1].ReadOnly = true;

				objectNode.ImageIndex = 0; //class
				if (value != null)
				{
					//container = Db4oClient.Client;
					//container.Ext().Activate(value, 2);

					TreeGridNode treenodeDummyChildNode = new TreeGridNode();
					objectNode.Nodes.Add(treenodeDummyChildNode);
					treenodeDummyChildNode.Cells[0].Value = BusinessConstants.DB4OBJECTS_DUMMY;
				}

			}
			catch (Exception oEx)
			{
				LoggingHelper.HandleException(oEx);
			}
		}
Ejemplo n.º 17
0
		private IReflectField[] FilterTransientFields(IReflectField[] fields)
		{
			IList filteredFields = new ArrayList();
			for (int fieldIndex = 0; fieldIndex < fields.Length; ++fieldIndex)
			{
				IReflectField field = fields[fieldIndex];
				if (!field.IsTransient())
				{
					filteredFields.Add(field);
				}
			}
			return ((IReflectField[])Sharpen.Collections.ToArray(filteredFields, new IReflectField
				[filteredFields.Count]));
		}
			private bool IsActivating(IReflectField field)
			{
				IReflectClass fieldType = field.GetFieldType();
				return fieldType != null && !fieldType.IsPrimitive();
			}
			private bool HasNoActivatingFields(IReflectField[] fields)
			{
				for (int i = 0; i < fields.Length; i++)
				{
					if (this.IsActivating(fields[i]))
					{
						return false;
					}
				}
				return true;
			}
Ejemplo n.º 20
0
 private IReflectField[] CreateDeclaredFieldsArray()
 {
     var fields = Runtime.GetDeclaredFields(_type);
     var reflectors = new IReflectField[fields.Length];
     for (var i = 0; i < reflectors.Length; i++)
     {
         reflectors[i] = CreateField(fields[i]);
     }
     return reflectors;
 }
Ejemplo n.º 21
0
		private void RenderArray(TreeGridNode rootNode, object currObj, IReflectField field)
		{
			container = Db4oClient.Client;
			object obj = field.Get(currObj);



			if (obj != null)
			{
				container.Ext().Activate(obj, 2);
				int length = container.Ext().Reflector().Array().GetLength(obj);
				CreateCollectionNode(field, obj, ref rootNode, length.ToString());
			}
			else
			{
				CreateCollectionNode(field, obj, ref rootNode, "0");
			}
		}
Ejemplo n.º 22
0
		private void RenderCollection(TreeGridNode rootNode, object currObj, IReflectField field)
		{
			container = Db4oClient.Client;
			object value = field.Get(currObj);


			if (value != null)
			{
				container.Ext().Activate(value, 2);
				ICollection coll = (ICollection)value;

				CreateCollectionNode(field, value, ref rootNode, coll.Count.ToString());
			}
			else
			{
				CreateCollectionNode(field, value, ref rootNode, "0");
			}
		}
			public _ICodeBlock_18(IReflectField field)
			{
				this.field = field;
			}
Ejemplo n.º 24
0
 protected virtual StaticField ToStaticField(IReflectField reflectField)
 {
     return new StaticField(reflectField.GetName(), StaticReflectFieldValue(reflectField
         ));
 }
Ejemplo n.º 25
0
		public static void SetObject(IReflectField rfield, object containingObject, IType fieldType, string newValue)
        {
            try
            {
				rfield.Set(containingObject, fieldType.Cast(newValue));
            }
            catch (Exception oEx)
            {
                Db4oClient.Client.Rollback();
                LoggingHelper.HandleException(oEx);
            }
        }
Ejemplo n.º 26
0
		public void CreateCollectionNode(IReflectField field, object ownerObject, ref TreeGridNode rootNode, string count)
		{
			try
			{
				TreeGridNode collNode = new TreeGridNode();

				rootNode.Nodes.Add(collNode);
				collNode.Cells[1].ReadOnly = true;
				collNode.Cells[0].Value = field.GetName() + " ( " + count + " items )";
				SetFieldType(collNode, ResolveFieldType(field));
				if (ownerObject != null)
				{
					collNode.Cells[1].Value = ownerObject.ToString();
					collNode.Tag = ownerObject;
				}
				else
				{
					collNode.Cells[1].Value = BusinessConstants.DB4OBJECTS_NULL;
				}
				collNode.ImageIndex = 1; //Collection
				if (Convert.ToInt32(count) > 0)
				{
					TreeGridNode treenodeDummyChildNode = new TreeGridNode();
					collNode.Nodes.Add(treenodeDummyChildNode);
					treenodeDummyChildNode.Cells[0].Value = BusinessConstants.DB4OBJECTS_DUMMY;
				}
			}
			catch (Exception oEx)
			{
				LoggingHelper.HandleException(oEx);
			}
		}
Ejemplo n.º 27
0
		public virtual object Get(IReflectField field, object onObject)
		{
			return field.Get(onObject);
		}
Ejemplo n.º 28
0
 internal virtual bool StoreField(IReflectField field)
 {
     if (field.IsStatic())
     {
         return false;
     }
     if (IsTransient(field))
     {
         if (!ShouldStoreTransientFields())
         {
             return false;
         }
     }
     return Platform4.CanSetAccessible() || field.IsPublic();
 }
Ejemplo n.º 29
0
 public virtual void InitFields(IReflectClass clazz, IReflectField[] fields)
 {
     ((GenericClass) clazz).InitFields((GenericField[]) fields);
 }
Ejemplo n.º 30
0
 private bool IsTransient(IReflectField field)
 {
     return field.IsTransient() || Platform4.IsTransient(field.GetFieldType());
 }