Exemple #1
0
 public Object Invoke(String fieldName, Type enhancedType)
 {
     ITypeInfoItem[] members = new ITypeInfoItem[fields.Length];
     for (int a = fields.Length; a-- > 0;)
     {
         FieldInfo[] field = ReflectUtil.GetDeclaredFieldInHierarchy(enhancedType, fields[a].Name);
         members[a] = new FieldInfoItemASM(field[0]);
     }
     return(members);
 }
Exemple #2
0
        public void test_ValueHolderContainer_Embedded()
        {
            Material obj = EntityFactory.CreateEntity <Material>();

            // Test EmbMat.EmbMatType
            Assert.IsInstanceOfType(obj.EmbMat, typeof(IEmbeddedType));
            obj.EmbMat.Name = "Name2";
            Assert.AssertEquals("Name2", obj.EmbMat.Name);

            Assert.AssertEquals(0, ReflectUtil.GetDeclaredFieldInHierarchy(obj.GetType(), ValueHolderIEC.GetInitializedFieldName("EmbMat.EmbMatType")).Length);
            Assert.AssertEquals(1, ReflectUtil.GetDeclaredFieldInHierarchy(obj.EmbMat.GetType(), ValueHolderIEC.GetInitializedFieldName("EmbMatType")).Length);

            IObjRefContainer vhc = (IObjRefContainer)obj;

            IEntityMetaData metaData        = vhc.Get__EntityMetaData();
            int             embMatTypeIndex = metaData.GetIndexByRelationName("EmbMat.EmbMatType");

            Assert.AssertFalse(vhc.Is__Initialized(embMatTypeIndex));

            IObjRef[] emptyRefs = ObjRef.EMPTY_ARRAY;
            ((IObjRefContainer)obj).Set__ObjRefs(embMatTypeIndex, emptyRefs);
            IObjRef[] objRefs = vhc.Get__ObjRefs(embMatTypeIndex);
            Assert.AssertSame(emptyRefs, objRefs);

            Assert.AssertNull(obj.EmbMat.EmbMatType);
            Assert.AssertTrue(vhc.Is__Initialized(embMatTypeIndex));

            // Test EmbMat.EmbMat2.EmbMatType2
            Assert.IsInstanceOfType(obj.EmbMat.EmbMat2, typeof(IEmbeddedType));
            obj.EmbMat.EmbMat2.Name2 = "Name3";
            Assert.AssertEquals("Name3", obj.EmbMat.EmbMat2.Name2);

            Assert.AssertNull(obj.GetType().GetField(ValueHolderIEC.GetInitializedFieldName("EmbMat.EmbMat2.EmbMatType2")));
            Assert.AssertNull(obj.EmbMat.GetType().GetField(ValueHolderIEC.GetInitializedFieldName("EmbMat2.EmbMatType2")));
            Assert.AssertNotNull(obj.EmbMat.EmbMat2.GetType().GetField(ValueHolderIEC.GetInitializedFieldName("EmbMatType2")));

            embMatTypeIndex = metaData.GetIndexByRelationName("EmbMat.EmbMat2.EmbMatType2");

            Assert.AssertFalse(vhc.Is__Initialized(embMatTypeIndex));

            ((IObjRefContainer)obj).Set__ObjRefs(embMatTypeIndex, emptyRefs);
            objRefs = ((IObjRefContainer)obj).Get__ObjRefs(embMatTypeIndex);
            Assert.AssertSame(emptyRefs, objRefs);

            Assert.AssertNull(obj.EmbMat.EmbMat2.EmbMatType2);
            Assert.AssertTrue(vhc.Is__Initialized(embMatTypeIndex));

            // Test EmbMat3.EmbMatType
            Assert.IsInstanceOfType(obj.EmbMat3, typeof(IEmbeddedType));
        }
        public FieldInstance GetAlreadyImplementedField(String fieldName)
        {
            FieldInstance field = implementedFields.Get(fieldName);

            if (field != null)
            {
                return(field);
            }
            FieldInfo[] declaredFieldInHierarchy = ReflectUtil.GetDeclaredFieldInHierarchy(CurrentType, fieldName);
            if (declaredFieldInHierarchy != null && declaredFieldInHierarchy.Length > 0)
            {
                field = new FieldInstance(declaredFieldInHierarchy[0]);
            }
            return(field);
        }
Exemple #4
0
        public static IPropertyInfo[] BuildPropertyPath(Type entityType, String memberName, IPropertyInfoProvider propertyInfoProvider)
        {
            String[] memberPath = EmbeddedMember.Split(memberName);
            Type     currType   = entityType;

            IPropertyInfo[] propertyPath = new IPropertyInfo[memberPath.Length];
            for (int a = 0, size = propertyPath.Length; a < size; a++)
            {
                IPropertyInfo property = propertyInfoProvider.GetProperty(currType, memberPath[a]);
                if (property == null)
                {
                    FieldInfo[] fields = ReflectUtil.GetDeclaredFieldInHierarchy(currType, memberPath[a]);
                    if (fields.Length == 0)
                    {
                        throw new Exception("Path illegal: " + memberName);
                    }
                    property = new FieldPropertyInfo(currType, memberPath[a], fields[a]);
                }
                propertyPath[a] = property;
                currType        = property.PropertyType;
            }
            return(propertyPath);
        }
 public void PostProcessCreatedType(Type newType)
 {
     foreach (Entry <String, IValueResolveDelegate> entry in initializeStaticFields)
     {
         FieldInfo[] fields = ReflectUtil.GetDeclaredFieldInHierarchy(newType, entry.Key);
         if (fields.Length == 0)
         {
             throw new Exception("Field not found: '" + newType.FullName + "." + entry.Key);
         }
         Object value = entry.Value.Invoke(entry.Key, newType);
         foreach (FieldInfo field in fields)
         {
             try
             {
                 field.SetValue(null, value);
             }
             catch (Exception e)
             {
                 throw RuntimeExceptionUtil.Mask(e, "Error occured while setting field: " + field);
             }
         }
     }
     initializeStaticFields.Clear();
 }