System.Runtime.Serialization.Formatters.Binary.BinaryCommon.IsPrimitive C# (CSharp) Method

IsPrimitive() public static method

public static IsPrimitive ( Type type ) : bool
type System.Type
return bool
		public static bool IsPrimitive (Type type)
		{
			return (type.IsPrimitive && type != typeof (IntPtr)) || 
				type == typeof (DateTime) || 
				type == typeof (TimeSpan) || 
				type == typeof (Decimal);
		}

Usage Example

示例#1
0
        private void WriteArray(BinaryWriter writer, long id, Array array)
        {
            // There are 4 ways of serializing arrays:
            // The element GenericArray (7) can be used for all arrays.
            // The element ArrayOfPrimitiveType (15) can be used for single-dimensional
            // arrays of primitive types
            // The element ArrayOfObject (16) can be used for single-dimensional Object arrays
            // The element ArrayOfString (17) can be used for single-dimensional string arrays

            Type elementType = array.GetType().GetElementType();

            if (elementType == typeof(object) && array.Rank == 1)
            {
                WriteObjectArray(writer, id, array);
            }
            else if (elementType == typeof(string) && array.Rank == 1)
            {
                WriteStringArray(writer, id, array);
            }
            else if (BinaryCommon.IsPrimitive(elementType) && array.Rank == 1)
            {
                WritePrimitiveTypeArray(writer, id, array);
            }
            else
            {
                WriteGenericArray(writer, id, array);
            }
        }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.BinaryCommon::IsPrimitive