예제 #1
0
        internal void  buildFieldList(StorageImpl storage, System.Type cls, ArrayList list)
        {
            System.Type superclass = cls.BaseType;
            if (superclass != null && superclass != typeof(MarshalByRefObject))
            {
                buildFieldList(storage, superclass, list);
            }
            System.Reflection.FieldInfo[] flds = cls.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
            for (int i = 0; i < flds.Length; i++)
            {
                FieldInfo f = flds[i];
                if (!f.IsNotSerialized && !f.IsStatic)
                {
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.field     = f;
                    fd.fieldName = f.Name;
                    fd.className = cls.FullName;
                    FieldType type = getTypeCode(f.FieldType);
                    switch (type)
                    {
                    case FieldType.tpObject:
                    case FieldType.tpLink:
                    case FieldType.tpArrayOfObject:
                        hasReferences = true;
                        break;

                    case FieldType.tpValue:
                        fd.valueDesc   = storage.getClassDescriptor(f.FieldType);
                        hasReferences |= fd.valueDesc.hasReferences;
                        break;

                    case FieldType.tpArrayOfValue:
                        fd.valueDesc   = storage.getClassDescriptor(f.FieldType.GetElementType());
                        hasReferences |= fd.valueDesc.hasReferences;
                        break;
                    }
                    fd.type = type;
                    list.Add(fd);
                }
            }
        }
        internal void  buildFieldList(StorageImpl storage, Type cls, ArrayList list)
        {
#if WINRT_NET_FRAMEWORK
            Type superclass = cls.GetTypeInfo().BaseType;
#else
            Type superclass = cls.BaseType;
#endif
            if (superclass != null
#if !SILVERLIGHT
                && superclass != typeof(MarshalByRefObject)
#endif
                )
            {
                buildFieldList(storage, superclass, list);
            }
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
            bool isWrapper = typeof(PersistentWrapper).IsAssignableFrom(cls);
            bool hasTransparentAttribute = cls.GetCustomAttributes(typeof(TransparentPersistenceAttribute), true).Length != 0;
#else
            bool hasTransparentAttribute = false;
#endif
#if WINRT_NET_FRAMEWORK
            bool serializeProperties = cls.GetTypeInfo().GetCustomAttributes(typeof(SerializePropertiesAttribute), true).GetEnumerator().MoveNext();
#else
            bool serializeProperties = cls.GetCustomAttributes(typeof(SerializePropertiesAttribute), true).Length != 0;
#endif
            if (serializeProperties)
            {
#if WINRT_NET_FRAMEWORK
                PropertyInfo[] props = Enumerable.ToArray <PropertyInfo>(cls.GetRuntimeProperties());
#else
                PropertyInfo[] props = cls.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
#endif
                Array.Sort(props, 0, props.Length, fieldComparator);
                for (int i = 0; i < props.Length; i++)
                {
                    PropertyInfo prop = props[i];
#if WINRT_NET_FRAMEWORK
                    if (prop.GetCustomAttributes(typeof(NonSerializedAttribute), true).GetEnumerator().MoveNext() ||
                        prop.GetCustomAttributes(typeof(TransientAttribute), true).GetEnumerator().MoveNext())
#else
                    if (prop.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length != 0 ||
                        prop.GetCustomAttributes(typeof(TransientAttribute), true).Length != 0)
#endif
                    {
                        continue;
                    }
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.property  = prop;
                    fd.fieldName = prop.Name;
                    fd.className = getTypeName(cls);
                    Type      fieldType = prop.PropertyType;
                    FieldType type      = getTypeCode(fieldType);
                    switch (type)
                    {
#if USE_GENERICS
                    case FieldType.tpArrayOfOid:
                        fd.constructor = GetConstructor(fieldType, "ConstructArray");
                        hasReferences  = true;
                        break;

                    case FieldType.tpLink:
                        fd.constructor = GetConstructor(fieldType, "ConstructLink");
                        hasReferences  = true;
                        break;
#else
                    case FieldType.tpArrayOfOid:
                    case FieldType.tpLink:
#endif
                    case FieldType.tpArrayOfObject:
                    case FieldType.tpObject:
                        hasReferences = true;
                        if (hasTransparentAttribute && isPerstInternalType(fieldType))
                        {
                            fd.recursiveLoading = true;
                        }
                        break;

                    case FieldType.tpValue:
                    case FieldType.tpNullableValue:
                        fd.valueDesc   = storage.getClassDescriptor(fieldType);
                        hasReferences |= fd.valueDesc.hasReferences;
                        break;

                    case FieldType.tpArrayOfValue:
                        fd.valueDesc   = storage.getClassDescriptor(fieldType.GetElementType());
                        hasReferences |= fd.valueDesc.hasReferences;
                        break;
                    }
                    fd.type = type;
                    list.Add(fd);
                }
            }
            else
            {
#if WINRT_NET_FRAMEWORK
                FieldInfo[] flds = Enumerable.ToArray <FieldInfo>(cls.GetRuntimeFields());
#else
                FieldInfo[] flds = cls.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
#endif
                Array.Sort(flds, 0, flds.Length, fieldComparator);
                for (int i = 0; i < flds.Length; i++)
                {
                    FieldInfo f = flds[i];
#if WINRT_NET_FRAMEWORK
                    if (!f.IsStatic && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(f.FieldType.GetTypeInfo()))
#else
                    if (!f.IsNotSerialized && !f.IsStatic && !typeof(Delegate).IsAssignableFrom(f.FieldType))
#endif
                    {
#if WINRT_NET_FRAMEWORK
                        if (f.GetCustomAttributes(typeof(NonSerializedAttribute), true).GetEnumerator().MoveNext() ||
                            f.GetCustomAttributes(typeof(TransientAttribute), true).GetEnumerator().MoveNext())
#else
                        if (f.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length != 0 ||
                            f.GetCustomAttributes(typeof(TransientAttribute), true).Length != 0)
#endif
                        {
                            continue;
                        }
                        FieldDescriptor fd = new FieldDescriptor();
                        fd.field     = f;
                        fd.fieldName = f.Name;
                        fd.className = getTypeName(cls);
                        Type      fieldType = f.FieldType;
                        FieldType type      = getTypeCode(fieldType);
                        switch (type)
                        {
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
                        case FieldType.tpInt:
                            if (isWrapper && isObjectProperty(cls, f))
                            {
                                hasReferences = true;
                                type          = FieldType.tpOid;
                            }
                            break;
#endif
#if USE_GENERICS
                        case FieldType.tpArrayOfOid:
                            fd.constructor = GetConstructor(fieldType, "ConstructArray");
                            hasReferences  = true;
                            break;

                        case FieldType.tpLink:
                            fd.constructor = GetConstructor(fieldType, "ConstructLink");
                            hasReferences  = true;
                            break;
#else
                        case FieldType.tpArrayOfOid:
                        case FieldType.tpLink:
#endif
                        case FieldType.tpArrayOfObject:
                        case FieldType.tpObject:
                            hasReferences = true;
                            if (hasTransparentAttribute && isPerstInternalType(fieldType))
                            {
                                fd.recursiveLoading = true;
                            }
                            break;

                        case FieldType.tpValue:
                        case FieldType.tpNullableValue:
                            fd.valueDesc   = storage.getClassDescriptor(fieldType);
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;

                        case FieldType.tpArrayOfValue:
                            fd.valueDesc   = storage.getClassDescriptor(fieldType.GetElementType());
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;
                        }
                        fd.type = type;
                        list.Add(fd);
                    }
                }
            }
        }
        internal void  buildFieldList(StorageImpl storage, Type cls, ArrayList list)
        {
#if WINRT_NET_FRAMEWORK
           Type superclass = cls.GetTypeInfo().BaseType;
#else
           Type superclass = cls.BaseType;
#endif
            if (superclass != null
#if !SILVERLIGHT
                && superclass != typeof(MarshalByRefObject)
#endif
                )
            {
                buildFieldList(storage, superclass, list);
            }
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
            bool isWrapper = typeof(PersistentWrapper).IsAssignableFrom(cls);
            bool hasTransparentAttribute = cls.GetCustomAttributes(typeof(TransparentPersistenceAttribute), true).Length != 0;
#else
            bool hasTransparentAttribute = false;
#endif
#if WINRT_NET_FRAMEWORK
            bool serializeProperties = cls.GetTypeInfo().GetCustomAttributes(typeof(SerializePropertiesAttribute), true).GetEnumerator().MoveNext();
#else
            bool serializeProperties = cls.GetCustomAttributes(typeof(SerializePropertiesAttribute), true).Length != 0;
#endif
            if (serializeProperties)
            {
#if WINRT_NET_FRAMEWORK
                PropertyInfo[] props = Enumerable.ToArray<PropertyInfo>(cls.GetRuntimeProperties());
#else
                PropertyInfo[] props = cls.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
#endif
                Array.Sort(props, 0, props.Length, fieldComparator);
                for (int i = 0; i < props.Length; i++)
                {
                    PropertyInfo prop = props[i];
#if WINRT_NET_FRAMEWORK
                    if (prop.GetCustomAttributes(typeof(NonSerializedAttribute), true).GetEnumerator().MoveNext()
                        || prop.GetCustomAttributes(typeof(TransientAttribute), true).GetEnumerator().MoveNext())
#else
                        if (prop.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length != 0
                        || prop.GetCustomAttributes(typeof(TransientAttribute), true).Length != 0)
#endif
                    {
                        continue;
                    }
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.property = prop;
                    fd.fieldName = prop.Name;
                    fd.className = getTypeName(cls);
                    Type fieldType = prop.PropertyType;
                    FieldType type = getTypeCode(fieldType);
                    switch (type) 
                    {
#if USE_GENERICS
                        case FieldType.tpArrayOfOid:
                            fd.constructor = GetConstructor(fieldType, "ConstructArray");
                            hasReferences = true;
                            break;
                        case FieldType.tpLink:
                            fd.constructor = GetConstructor(fieldType, "ConstructLink");
                            hasReferences = true;
                            break;
#else
                        case FieldType.tpArrayOfOid:
                        case FieldType.tpLink:
#endif
                        case FieldType.tpArrayOfObject:
                        case FieldType.tpObject:
                            hasReferences = true;
                            if (hasTransparentAttribute && isPerstInternalType(fieldType))
                            {
                                fd.recursiveLoading = true; 
                            }
                            break;
                        case FieldType.tpValue:
                        case FieldType.tpNullableValue:
                            fd.valueDesc = storage.getClassDescriptor(fieldType);
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;
                        case FieldType.tpArrayOfValue:
                            fd.valueDesc = storage.getClassDescriptor(fieldType.GetElementType());
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;
                    }
                    fd.type = type;
                    list.Add(fd);
                }
            }   
            else  
            {            
#if WINRT_NET_FRAMEWORK
                FieldInfo[] flds = Enumerable.ToArray<FieldInfo>(cls.GetRuntimeFields());
#else
                FieldInfo[] flds = cls.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
#endif
                Array.Sort(flds, 0, flds.Length, fieldComparator);
                for (int i = 0; i < flds.Length; i++)
                {
                    FieldInfo f = flds[i];
#if WINRT_NET_FRAMEWORK
                    if (!f.IsStatic && !typeof(Delegate).GetTypeInfo().IsAssignableFrom(f.FieldType.GetTypeInfo()))
#else
                    if (!f.IsNotSerialized && !f.IsStatic && !typeof(Delegate).IsAssignableFrom(f.FieldType))
#endif
                    {
#if WINRT_NET_FRAMEWORK
                        if (f.GetCustomAttributes(typeof(NonSerializedAttribute), true).GetEnumerator().MoveNext()
                            || f.GetCustomAttributes(typeof(TransientAttribute), true).GetEnumerator().MoveNext())
#else
                            if (f.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length != 0
                            || f.GetCustomAttributes(typeof(TransientAttribute), true).Length != 0)
#endif
                        {
                            continue;
                        }
                        FieldDescriptor fd = new FieldDescriptor();
                        fd.field = f;
                        fd.fieldName = f.Name;
                        fd.className = getTypeName(cls);
                        Type fieldType = f.FieldType;
                        FieldType type = getTypeCode(fieldType);
                        switch (type) 
                        {
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
                            case FieldType.tpInt:
                                if (isWrapper && isObjectProperty(cls, f)) 
                                {
                                    hasReferences = true;
                                    type = FieldType.tpOid;
                                } 
                                break;
#endif
#if USE_GENERICS
                            case FieldType.tpArrayOfOid:
                                fd.constructor = GetConstructor(fieldType, "ConstructArray");
                                hasReferences = true;
                                break;
                            case FieldType.tpLink:
                                fd.constructor = GetConstructor(fieldType, "ConstructLink");
                                hasReferences = true;
                                break;
#else
                            case FieldType.tpArrayOfOid:
                            case FieldType.tpLink:
#endif
                            case FieldType.tpArrayOfObject:
                            case FieldType.tpObject:
                                hasReferences = true;
                                if (hasTransparentAttribute && isPerstInternalType(fieldType))
                                {
                                    fd.recursiveLoading = true; 
                                }
                                break;
                            case FieldType.tpValue:
                            case FieldType.tpNullableValue:
                                fd.valueDesc = storage.getClassDescriptor(fieldType);
                                hasReferences |= fd.valueDesc.hasReferences;
                                break;
                            case FieldType.tpArrayOfValue:
                                fd.valueDesc = storage.getClassDescriptor(fieldType.GetElementType());
                                hasReferences |= fd.valueDesc.hasReferences;
                                break;
                        }
                        fd.type = type;
                        list.Add(fd);
                    }
                }
            }
        }