コード例 #1
0
        public void SetObjectOwner(object oObj, object oParent)
        {
            EntityTypeInfo oEntityTypeInfo =
                GetEntityTypeInfo(oObj.GetType());

            ReflectionUtil.SetFieldValue(oObj, oEntityTypeInfo.OwnerParent, oParent);
        }
コード例 #2
0
 public TisEntityTypeInfoExternal(
     EntityTypeInfo oTypeInfo,
     ITisEntityReflection oReflectionExternal)
 {
     m_oTypeInfo           = oTypeInfo;
     m_oReflectionExternal = oReflectionExternal;
 }
コード例 #3
0
        // Avoids reallocation of returned children ArrayList
        private void GetChildren(
            object oObj,
            ChildrenListFilter pfChildrenListFilter,
            object oChildrenListFilterCriteria,
            ObjectFilter pfObjectFilter,
            object oObjectFilterCriteria,
            EntityRelation enRelation,
            bool bRecursive,
            ICollection <object> oOutChildren)
        {
            // Get TypeInfo of specified object
            EntityTypeInfo oEntityTypeInfo =
                GetEntityTypeInfo(oObj);

            // Get the ChildrenLists according to EntityRelation filter
            EntityChildrenListInfo[] ChildrenLists = GetChildrenListsInfo(
                oEntityTypeInfo,
                enRelation);

            // Iterate ChildrenLists
            foreach (EntityChildrenListInfo oChildrenList in ChildrenLists)
            {
                // Obtain list object
                INamedObjectList oContainer = oChildrenList.GetValue(oObj) as INamedObjectList;

                if (oContainer != null)
                {
                    // Check if container passes filter
                    bool bContainerPassedFilter = (pfChildrenListFilter == null) ||
                                                  pfChildrenListFilter(oChildrenList, oChildrenListFilterCriteria);

                    object oEl;
                    for (int i = 0; i < oContainer.Count; i++)
                    {
                        oEl = oContainer[oContainer.NameByIndex(i)];

                        if (bContainerPassedFilter &&
                            (pfObjectFilter == null || pfObjectFilter(oEl, oObjectFilterCriteria)))
                        {
                            // If elements filter passed
                            oOutChildren.Add(oEl);
                        }

                        if (bRecursive)
                        {
                            // Recursive call for each children
                            GetChildren(
                                oEl,
                                pfChildrenListFilter,
                                oChildrenListFilterCriteria,
                                pfObjectFilter,
                                oObjectFilterCriteria,
                                enRelation,
                                bRecursive,
                                oOutChildren);
                        }
                    }
                }
            }
        }
コード例 #4
0
        public object GetObjectOwner(object oObj)
        {
            EntityTypeInfo oEntityTypeInfo =
                GetEntityTypeInfo(oObj.GetType());

            return(ReflectionUtil.GetFieldValue(oObj, oEntityTypeInfo.OwnerParent));
        }
コード例 #5
0
        internal EntityChildrenListInfo[] GetChildrenListsInfo(
            EntityTypeInfo oEntityTypeInfo,
            EntityRelation enRelation)
        {
            EntityChildrenListInfo[] ChildrenLists = null;

            switch (enRelation)
            {
            case EntityRelation.Link:
                ChildrenLists = oEntityTypeInfo.LinkedChildren;
                break;

            case EntityRelation.Owner:
                ChildrenLists = oEntityTypeInfo.OwnedChildren;
                break;

            case EntityRelation.All:
                ChildrenLists = oEntityTypeInfo.AllChildren;
                break;

            default:
                throw new TisException("Unknown EntityRelation [{0}]", enRelation);
            }

            return(ChildrenLists);
        }
コード例 #6
0
        private FieldInfo GetUniqueParentLinkField(object oVal)
        {
            // Get TypeInfo of the value
            EntityTypeInfo oTypeInfo =
                Reflection.GetEntityTypeInfo(oVal);

            // Get a field that is a unique link to us
            FieldInfo oField =
                oTypeInfo.GetUniqueParentLinkField(this.GetType());

            return(oField);
        }
コード例 #7
0
        private static bool ObjectFilter_WithObsoleteMember(
            object oObj,
            object oCriteria)
        {
            EntityReflectionServices oThis = new EntityReflectionServices();

            EntityTypeInfo oEntityTypeInfo = oThis.GetEntityTypeInfo(oObj);

            FieldInfo[] ObsoleteMembers = oEntityTypeInfo.ObsoleteMembers;

            return(ObsoleteMembers.Length > 0);
        }
コード例 #8
0
            public EntityTypeInfo Get(Type oType)
            {
                EntityTypeInfo oVal = null;

                if (!m_oTypeToInfoTable.TryGetValue(oType, out oVal))
                {
                    oVal = new EntityTypeInfo(oType);

                    m_oTypeToInfoTable[oType] = oVal;
                }

                return(oVal);
            }
コード例 #9
0
        public FieldInfo[] GetEntityTypeObsoleteMembers(Type oType)
        {
            EntityTypeInfo oEntityTypeInfo = GetEntityTypeInfo(oType);

            if (oEntityTypeInfo != null)
            {
                return(oEntityTypeInfo.ObsoleteMembers);
            }
            else
            {
                return(new FieldInfo[0]);
            }
        }
コード例 #10
0
        private void SetObjectOwnerParent(object oObj, object oParent)
        {
            EntityTypeInfo oChildTypeInfo =
                Reflection.GetEntityTypeInfo(oObj);

            FieldInfo oOwnerParentField = oChildTypeInfo.OwnerParent;

            if (oOwnerParentField != null)
            {
                object oTarget = oObj;

                // Set child "OwnerParent" field

                ReflectionUtil.SetFieldValue(oTarget, oOwnerParentField, oParent);
            }
        }
コード例 #11
0
        public EntityParameterInfo GetEntityParameterInfo(
            Type oType,
            string sParamName)
        {
            EntityTypeInfo oEntityTypeInfo = GetEntityTypeInfo(oType);

            EntityParameterInfo oParamData =
                oEntityTypeInfo.GetEntityParameterInfo(sParamName);

            if (oParamData == null)
            {
                throw new TisException(
                          "Parameter [{0}] not exists in type [{1}]",
                          sParamName,
                          oType);
            }

            return(oParamData);
        }
コード例 #12
0
        public object CreateChild(
            object oObj,
            Type oChildType,
            string sChildName)
        {
            EntityTypeInfo oTypeInfo = GetEntityTypeInfo(oObj);

            EntityChildrenListInfo[] OwnedChildrenInfo = oTypeInfo.OwnedChildren;

            INamedObjectOwnerList oChildList = null;

            // Find the ChildList of specified type - must be one
            // and only one
            foreach (EntityChildrenListInfo oChildInfo in OwnedChildrenInfo)
            {
                if (oChildInfo.ChildType == oChildType)
                {
                    if (oChildList != null)
                    {
                        throw new TisException(
                                  "More than 1 child list contains entities of type [{0}] " +
                                  "under entity of type [{1}]. " +
                                  "The child can't be created", oChildType, oObj.GetType());
                    }

                    oChildList = oChildInfo.GetValue(oObj) as INamedObjectOwnerList;
                }
            }

            if (oChildList == null)
            {
                throw new TisException(
                          "The child of type [{0}] can't be created under node of type [{1}]",
                          oChildType,
                          oObj.GetType());
            }

            // Create a child
            return(oChildList.CreateNew(sChildName));
        }
コード例 #13
0
        public ICollection GetParents(object oObj, bool bMandatoryOnly)
        {
            EntityTypeInfo oEntityTypeInfo =
                GetEntityTypeInfo(oObj.GetType());

            ArrayList oParents = new ArrayList();

            foreach (EntityParentInfo oParentInfo in oEntityTypeInfo.AllDirectParents)
            {
                if (bMandatoryOnly && !oParentInfo.Mandatory)
                {
                    continue;
                }

                object oParent = ReflectionUtil.GetFieldValue(oObj, oParentInfo.Parent);

                if (oParent != null)
                {
                    oParents.Add(oParent);
                }
            }

            return(oParents);
        }