`

c# - determine if a type/object is serialzable

    博客分类:
  • C#
c# 
阅读更多

In WCF, primitives type are serialzable, and some commonly used types are also serialzable, but some types are not serialzable , and when this types to be used in wcf as the data contract for message, then you might get into trouble.

there are ways to determine if a type is serializable or an instance is serializable. To check if a type (on the type object itself)

typeof(T).IsSerializable

 

or you can check on the instance 

private static bool IsSerializable(T obj)
{
    return ((obj is ISerializable) || (Attribute.IsDefined(typeof (T), typeof (SerializableAttribute))));
}

 

But be caereful that IsSerializable does not take into account the all types in the graph of objects being serialized for the serialable attribute.

You might want to check on that the reference page - how to check if an object is serializable in C#

References:

how to check if an object is serializable in C#

分享到:
评论

相关推荐

    LAMP搭建的方法与注意事项

    如果出现"Could not reliably determine the server's fully qualified domain name"错误,编辑`/usr/local/apache/conf/httpd.conf`,将ServerName设置为127.0.0.1:80,并重启Apache。 接下来是MySQL的安装。MySQL...

    linux下安装apache

    重启 Apache 后,可能会弹出警告:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.64. Set the 'ServerName' directive globally to suppress this ...

    delphi 7 gif控件

    // The result is best if each sub frame contains a whole image. // // If the sub frame is transparent the background is not automatically // // restored, you must do so yourself if you want that. // /...

    MIL-STD-202 H / G 测试标准

    including basic environmental tests to determine resistance to deleterious effects of natural elements and conditions surrounding military operations, and physical and electrical tests. For the ...

    qtcreator4.4.1.zip

    IS_GCC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB -I../../../src -I../../../src -I../../libs -I/opt/qt-creator-opensource-src-4.4.1/tools -I../../...

    Determine if a Directory Exists

    "Determine if a Directory Exists"这个主题就涉及到了如何检查计算机系统中是否存在特定的目录。这是一个基础但至关重要的功能,因为它广泛应用于文件管理、数据备份、安装程序验证等多个场景。 在Windows操作系统...

    JSEclipse_1.5.5.zip

    The JSEclipse_1.5.5.zip package ... It is used by the Eclipse IDE to determine the JSEclipse package location. - Install.txt - the file includes the JSEclipse installation notes - Readme.txt - this file

    apache+tomcat+memcached 全配置

    - 在启动 Apache 时可能会遇到提示 “Could not reliably determine the server's fully qualified domain name”,这通常是因为没有正确设置 `ServerName`。 - 在 Apache 的配置文件中添加以下内容: ```apache ...

    EDA实例源程序代码.pdf

    architecture a of jbm is begin f1 <= a and b; f2 <= a or b; f <= not a; f3 <= a nand b; f4 <= a nor b; f5 (a xor b); end a; ``` 这段代码使用了`and`、`or`、`not`、`nand`、`nor`、`xor`等关键字来...

    启用 Go 应用程序进行自我更新.zip

    u github.com/sanbornm/go-selfupdate/...var updater = &selfupdate.Updater{ CurrentVersion: version, // the current version of your app used to determine if an update is necessary // these endpoints can...

    MS-DOS 5.0

    If you have a partition that is incompatible with MS-DOS 5.0, you must delete it from your hard disk. Incompatible partitions are listed as "Non-DOS" partitions in FDISK. See the procedure for ...

    Determine if a File Exists

    "Determine if a File Exists" 这个主题涵盖了文件系统操作的核心概念,它在各种应用中都有广泛的应用,比如数据验证、文件处理流程或者用户交互。下面将详细阐述如何在不同的编程语言和环境下检查文件是否存在。 1...

    ftplib-4.0

    FtpSysType() - Determine remote system type FtpSize() - Determine size of remote file FtpSizeLong() - Determine size of remote file FtpModDate() - Determine modification time of file FtpSetCallback() ...

    baxter_common:百特研究机器人的ROS消息和机器人描述文件

    baxter_common URDF,网格和自定义消息,描述了Rethink Robotics的Baxter Research Robot代码和票证文献资料 问题 会费baxter_common存储库概述.|+-- baxter_common/ baxter_common metapackage|+-- baxter_...

    Given-a-string-containing-just-the-characters-and-determine-if-the-inpu

    这个题目名为"Given-a-string-containing-just-the-characters-and-determine-if-the-input",实际上是在询问我们如何编写一个函数或程序来检查一个字符串是否只包含特定的一组字符。 首先,让我们明确一下问题的...

    wxh linux9_0+apache+php+mysql安装与配置

    - 如果出现 `httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName` 提示,则需修改配置文件中的 ServerName。 - 复制 `httpd.conf` 文件为备份 `cp httpd.conf...

    MIL-STD-883J w/CHANGE 4

    suitable for use within Military and Aerospace electronic systems including basic environmental tests to determine resistance to deleterious effects of natural elements and conditions surrounding ...

    LAN8720A数据手册

    The LAN8720A/LAN8720Ai is a low-power 10BASE-T/100BASE-TX physical layer (PHY) transceiver with variable I/O voltage that is compliant with the IEEE 802.3-2005 standards. The LAN8720A/LAN8720Ai ...

    搭建IC设计环境问题集锦

    - 报错示例:`WARNING file /home/hjg/CDS.log Can't determine host name. Locking is not allowed with host name 'localhost'` - 解决方法: - 修改主机名为配置文件中设定的名称,例如,如果配置文件中的主机...

    ethereal网络抓包工具

    Ethereal is a GUI network protocol analyzer. It lets you interactively browse packet data from a live network or from a previously saved capture file. See: http://www.ethereal.com for new versions, ...

Global site tag (gtag.js) - Google Analytics