Пример #1
0
        public BinarySurrogate(IBinarySerializedTypeProvider typeProvider, ISurrogateConverter surrogateSerializer)
        {
            this.surrogatedTypes = typeProvider.GetBinarySerializableTypes();
            this.surrogateSerializer = surrogateSerializer;

            var notSeriazableTypes = surrogatedTypes.Where(t => !t.IsInterface && !t.GetCustomAttributes(typeof(SerializableAttribute), false).Any()).Select(t=>t.Name);
            if (notSeriazableTypes.Any())
            {
                throw new ArgumentException(string.Format("Type must be attibuted with Serializable attribute! Non-attibutes classes: {0}.", string.Join(",", notSeriazableTypes)));
            }
        }
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="typeProvider">Must implement IBinarySerializedTypeProvider</param>
        public UseBinarySurrogateBehaviorAttribute(Type typeProvider, Type surrogateConverter)
        {
            if (typeProvider == null)
            {
                throw new ArgumentNullException("typeProvider");
            }

            if (surrogateConverter == null)
            {
                throw new ArgumentNullException("surrogateConverter");
            }

            this.typeProvider = Activator.CreateInstance(typeProvider) as IBinarySerializedTypeProvider;
            if (this.typeProvider == null)
            {
                throw new ArgumentException("typeProvider implement IBinarySerializedTypeProvider");
            }

            this.surrogateConverter = Activator.CreateInstance(typeProvider) as ISurrogateConverter;
            if (this.surrogateConverter == null)
            {
                throw new ArgumentException("typeProvider implement ISurrogateConverter");
            }
        }