Beispiel #1
0
        private T FindExactMatch <T>(AssemblyData g, IDictionary <Type, T> dictionary, Type type)
        {
            T result;

            if (type == null)
            {
                return(default(T));
            }

            if (dictionary.TryGetValue(type, out result))
            {
                return(result);
            }

            if (type.IsGenericType && dictionary.TryGetValue(type.GetGenericTypeDefinition(), out result))
            {
                GenericTypes = type.GetGenericArguments().Select(t => g.GetPropertyType(t)).ToArray();
                return(result);
            }

            if (type.IsArray && dictionary.TryGetValue(typeof(Array), out result))
            {
                GenericTypes = new [] { g.GetPropertyType(type.GetElementType()) };
                return(result);
            }

            return(default(T));
        }
Beispiel #2
0
        public PropertyData(AssemblyData g, MemberInfo member)
        {
            this.Member = member;
            this.Name   = member.Name;

            if (HasNotBinarySerializableAttribute(member))
            {
                return;
            }

            var forceSerialize = HasBinarySerializableAttribute(member);

            var field = member as FieldInfo;

            if (field != null)
            {
                if (forceSerialize || (field.IsPublic && CanSerialize(field.FieldType)))
                {
                    this.Type           = g.GetPropertyType(field.FieldType);
                    this.IsSerializable = this.Type.Read != null && this.Type.Write != null;
                }
            }

            var property = member as PropertyInfo;

            if (property != null)
            {
                if (property.GetIndexParameters().Length > 0 || !CanSerialize(property.PropertyType))
                {
                    return;
                }

                var get = property.GetGetMethod(true);
                if (get == null)
                {
                    return;
                }

                if (forceSerialize || get.IsPublic)
                {
                    this.Type           = g.GetPropertyType(property.PropertyType);
                    this.IsSerializable = this.Type.Read != null && this.Type.Write != null;
                    if (this.IsSerializable)
                    {
                        var set = property.GetSetMethod(true);
                        if (set == null)
                        {
                            this.IsSerializable = this.Type.Read.ReadIntoExistingInstance;
                        }
                        else if (!set.IsPublic)
                        {
                            this.IsSerializable = this.Type.Read.ReadIntoExistingInstance || forceSerialize;
                        }
                    }
                }
            }
        }