Example #1
0
        static bool IsTypeReferenceable(Type type)
        {
            Type itemType;

            try
            {
                return(type.IsSerializable ||
                       type.IsDefined(Globals.TypeOfDataContractAttribute, false) ||
                       (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) && !type.IsGenericTypeDefinition) ||
                       CollectionDataContract.IsCollection(type, out itemType) ||
                       ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
            }
            catch (Exception ex)
            {
                // An exception can be thrown in the designer when a project has a runtime binding redirection for a referenced assembly or a reference dependent assembly.
                // Type.IsDefined is known to throw System.IO.FileLoadException.
                // ClassDataContract.IsNonAttributedTypeValidForSerialization is known to throw System.IO.FileNotFoundException.
                // We guard against all non-critical exceptions.
                if (Fx.IsFatal(ex))
                {
                    throw;
                }
            }

            return(false);
        }
Example #2
0
        static bool IsTypeReferenceable(Type type)
        {
            Type itemType;

            return(type.IsSerializable ||
                   type.IsDefined(Globals.TypeOfDataContractAttribute, false) ||
                   (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) && !type.IsGenericTypeDefinition) ||
                   CollectionDataContract.IsCollection(type, out itemType) ||
                   ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
        }
        private static bool IsTypeReferenceable(Type type)
        {
            Type type2;

            if (((!type.IsSerializable && !type.IsDefined(Globals.TypeOfDataContractAttribute, false)) && (!Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) || type.IsGenericTypeDefinition)) && !CollectionDataContract.IsCollection(type, out type2))
            {
                return(ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
            }
            return(true);
        }
Example #4
0
        static bool IsTypeReferenceable(Type type)
        {
            Type itemType;

            try
            {
                return(type.IsSerializable ||
                       type.IsDefined(Globals.TypeOfDataContractAttribute, false) ||
                       (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) && !type.IsGenericTypeDefinition) ||
                       CollectionDataContract.IsCollection(type, out itemType) ||
                       ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
            }
            catch (System.IO.FileLoadException)
            { // this can happen in Type.IsDefined when trying to load a referenced library that is not available at design time.
            }

            return(false);
        }