Exemple #1
0
        private static void SetValueToObject(ORMappingItem item, object graph, object data, object row, DataToObjectDeligations dod)
        {
            if (string.IsNullOrEmpty(item.SubClassPropertyName))
            {
                SetMemberValueToObject(item.MemberInfo, graph, data);
            }
            else
            {
                if (graph != null)
                {
                    MemberInfo mi = TypePropertiesWithNonPublicCacheQueue.Instance.GetPropertyInfoDirectly(graph.GetType(), item.PropertyName);

                    if (mi == null)
                    {
                        mi = graph.GetType().GetField(item.PropertyName,
                                                      BindingFlags.Instance | BindingFlags.Public);
                    }

                    if (mi != null)
                    {
                        object subGraph = GetMemberValueFromObject(mi, graph);

                        if (subGraph == null)
                        {
                            bool useDefaultObject = true;

                            if (dod != null)
                            {
                                MappingEventArgs args = new MappingEventArgs();

                                args.DataFieldName = item.DataFieldName;
                                args.PropertyName  = item.PropertyName;
                                args.Graph         = graph;

                                subGraph = dod.OnCreateSubObjectDelegate(row, args, ref useDefaultObject);
                            }

                            if (useDefaultObject)
                            {
                                if (string.IsNullOrEmpty(item.SubClassTypeDescription) == false)
                                {
                                    subGraph = TypeCreator.CreateInstance(item.SubClassTypeDescription);
                                }
                                else
                                {
                                    subGraph = Activator.CreateInstance(GetRealType(mi), true);
                                }
                            }

                            SetMemberValueToObject(item.MemberInfo, subGraph, data);
                            SetMemberValueToObject(mi, graph, subGraph);
                        }
                        else
                        {
                            SetMemberValueToObject(item.MemberInfo, subGraph, data);
                        }
                    }
                }
            }
        }
Exemple #2
0
        internal object OnCreateSubObjectDelegate(object dataSource, MappingEventArgs args, ref bool useDefaultObject)
        {
            object result = null;

            if (CreateSubObject != null)
            {
                result = CreateSubObject(dataSource, args, ref useDefaultObject);
            }

            return(result);
        }