本文整理汇总了C#中PrimitiveTypeCode类的典型用法代码示例。如果您正苦于以下问题:C# PrimitiveTypeCode类的具体用法?C# PrimitiveTypeCode怎么用?C# PrimitiveTypeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrimitiveTypeCode类属于命名空间,在下文中一共展示了PrimitiveTypeCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateReference
/// <summary>
/// Creates a type reference to a namespace type from the given assembly, where the last element of the names
/// array is the name of the type and the other elements are the names of the namespaces.
/// </summary>
/// <param name="assemblyReference">A reference to the assembly that contains the type for which a reference is desired.</param>
/// <param name="isValueType">True if the referenced type is known to be a value type.</param>
/// <param name="genericParameterCount">The number of generic parameters, if any, that the type has must. Must be zero or more.</param>
/// <param name="typeCode">A code that identifies what kind of type is being referenced.</param>
/// <param name="names">The last entry of this array is the name of the type, the others are the names of the containing namespaces.</param>
public INamespaceTypeReference CreateReference(IAssemblyReference assemblyReference, bool isValueType, ushort genericParameterCount, PrimitiveTypeCode typeCode, params string[] names)
{
IUnitNamespaceReference ns = new RootUnitNamespaceReference(assemblyReference);
for (int i = 0, n = names.Length-1; i < n; i++)
ns = new NestedUnitNamespaceReference(ns, this.host.NameTable.GetNameFor(names[i]));
return new NamespaceTypeReference(this.host, ns, this.host.NameTable.GetNameFor(names[names.Length-1]), genericParameterCount, false, isValueType, typeCode);
}
示例2: JsonPrimitiveContract
/// <summary>
/// Initializes a new instance of the <see cref="JsonPrimitiveContract"/> class.
/// </summary>
/// <param name="underlyingType">The underlying type for the contract.</param>
public JsonPrimitiveContract(Type underlyingType)
: base(underlyingType)
{
ContractType = JsonContractType.Primitive;
// get the underlying enum value
Type t;
if (ReflectionUtils.IsNullableType(underlyingType))
t = Nullable.GetUnderlyingType(underlyingType).IsEnum() ? ReflectionUtils.MakeGenericType(typeof(Nullable<>), Enum.GetUnderlyingType(Nullable.GetUnderlyingType(underlyingType))) : underlyingType;
else
t = underlyingType.IsEnum() ? Enum.GetUnderlyingType(underlyingType) : underlyingType;
PrimitiveTypeCode typeCode;
TypeCodeMap.TryGetValue(t, out typeCode);
TypeCode = typeCode;
}
示例3: DefineLocalConstant
private void DefineLocalConstant(string name, object value, PrimitiveTypeCode typeCode, uint constantSignatureToken)
{
if (value == null)
{
// ISymUnmanagedWriter2.DefineConstant2 throws an ArgumentException
// if you pass in null - Dev10 appears to use 0 instead.
// (See EMITTER::VariantFromConstVal)
value = 0;
typeCode = PrimitiveTypeCode.Int32;
}
if (typeCode == PrimitiveTypeCode.String)
{
DefineLocalStringConstant(name, (string)value, constantSignatureToken);
}
else if (value is DateTime)
{
// Marshal.GetNativeVariantForObject would create a variant with type VT_DATE and value equal to the
// number of days since 1899/12/30. However, ConstantValue::VariantFromConstant in the native VB
// compiler actually created a variant with type VT_DATE and value equal to the tick count.
// http://blogs.msdn.com/b/ericlippert/archive/2003/09/16/eric-s-complete-guide-to-vt-date.aspx
var dt = (DateTime)value;
_symWriter.DefineConstant2(name, new VariantStructure(dt), constantSignatureToken);
if (_callLogger.LogOperation(OP.DefineConstant2))
{
_callLogger.LogArgument(name);
_callLogger.LogArgument(constantSignatureToken);
_callLogger.LogArgument(dt.ToBinary());
}
}
else
{
try
{
DefineLocalConstantImpl(name, value, constantSignatureToken);
if (_callLogger.LogOperation(OP.DefineConstant2))
{
_callLogger.LogArgument(name);
_callLogger.LogArgument(constantSignatureToken);
_callLogger.LogArgument(value);
}
}
catch (Exception ex)
{
throw new PdbWritingException(ex);
}
}
}
示例4: WriteValue
internal static void WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, object value)
{
switch (typeCode)
{
case PrimitiveTypeCode.Char:
writer.WriteValue((char)value);
break;
case PrimitiveTypeCode.CharNullable:
writer.WriteValue((value == null) ? (char?)null : (char)value);
break;
case PrimitiveTypeCode.Boolean:
writer.WriteValue((bool)value);
break;
case PrimitiveTypeCode.BooleanNullable:
writer.WriteValue((value == null) ? (bool?)null : (bool)value);
break;
case PrimitiveTypeCode.SByte:
writer.WriteValue((sbyte)value);
break;
case PrimitiveTypeCode.SByteNullable:
writer.WriteValue((value == null) ? (sbyte?)null : (sbyte)value);
break;
case PrimitiveTypeCode.Int16:
writer.WriteValue((short)value);
break;
case PrimitiveTypeCode.Int16Nullable:
writer.WriteValue((value == null) ? (short?)null : (short)value);
break;
case PrimitiveTypeCode.UInt16:
writer.WriteValue((ushort)value);
break;
case PrimitiveTypeCode.UInt16Nullable:
writer.WriteValue((value == null) ? (ushort?)null : (ushort)value);
break;
case PrimitiveTypeCode.Int32:
writer.WriteValue((int)value);
break;
case PrimitiveTypeCode.Int32Nullable:
writer.WriteValue((value == null) ? (int?)null : (int)value);
break;
case PrimitiveTypeCode.Byte:
writer.WriteValue((byte)value);
break;
case PrimitiveTypeCode.ByteNullable:
writer.WriteValue((value == null) ? (byte?)null : (byte)value);
break;
case PrimitiveTypeCode.UInt32:
writer.WriteValue((uint)value);
break;
case PrimitiveTypeCode.UInt32Nullable:
writer.WriteValue((value == null) ? (uint?)null : (uint)value);
break;
case PrimitiveTypeCode.Int64:
writer.WriteValue((long)value);
break;
case PrimitiveTypeCode.Int64Nullable:
writer.WriteValue((value == null) ? (long?)null : (long)value);
break;
case PrimitiveTypeCode.UInt64:
writer.WriteValue((ulong)value);
break;
case PrimitiveTypeCode.UInt64Nullable:
writer.WriteValue((value == null) ? (ulong?)null : (ulong)value);
break;
case PrimitiveTypeCode.Single:
writer.WriteValue((float)value);
break;
case PrimitiveTypeCode.SingleNullable:
writer.WriteValue((value == null) ? (float?)null : (float)value);
break;
case PrimitiveTypeCode.Double:
writer.WriteValue((double)value);
break;
case PrimitiveTypeCode.DoubleNullable:
writer.WriteValue((value == null) ? (double?)null : (double)value);
break;
case PrimitiveTypeCode.DateTime:
writer.WriteValue((DateTime)value);
break;
case PrimitiveTypeCode.DateTimeNullable:
writer.WriteValue((value == null) ? (DateTime?)null : (DateTime)value);
break;
#if !NET20
case PrimitiveTypeCode.DateTimeOffset:
writer.WriteValue((DateTimeOffset)value);
break;
case PrimitiveTypeCode.DateTimeOffsetNullable:
writer.WriteValue((value == null) ? (DateTimeOffset?)null : (DateTimeOffset)value);
break;
#endif
case PrimitiveTypeCode.Decimal:
writer.WriteValue((decimal)value);
break;
case PrimitiveTypeCode.DecimalNullable:
writer.WriteValue((value == null) ? (decimal?)null : (decimal)value);
break;
case PrimitiveTypeCode.Guid:
writer.WriteValue((Guid)value);
break;
case PrimitiveTypeCode.GuidNullable:
//.........这里部分代码省略.........
示例5: ReadValue
private static object ReadValue(PrimitiveTypeCode primitiveTypeCode, BinaryReader reader)
{
switch (primitiveTypeCode) {
case PrimitiveTypeCode.Boolean: return reader.ReadBoolean();
case PrimitiveTypeCode.Char: return reader.ReadChar();
case PrimitiveTypeCode.Float32: return reader.ReadSingle();
case PrimitiveTypeCode.Float64: return reader.ReadDouble();
case PrimitiveTypeCode.Int16: return reader.ReadInt16();
case PrimitiveTypeCode.Int32: return reader.ReadInt32();
case PrimitiveTypeCode.Int64: return reader.ReadInt64();
case PrimitiveTypeCode.Int8: return reader.ReadSByte();
case PrimitiveTypeCode.UInt16: return reader.ReadUInt16();
case PrimitiveTypeCode.UInt32: return reader.ReadUInt32();
case PrimitiveTypeCode.UInt64: return reader.ReadUInt64();
case PrimitiveTypeCode.UInt8: return reader.ReadByte();
default:
Debug.Assert(false);
break;
}
return null;
}
示例6: DefineLocalConstant
public void DefineLocalConstant(string name, object value, PrimitiveTypeCode typeCode, uint constantSignatureToken)
{
if (value == null)
{
// ISymUnmanagedWriter2.DefineConstant2 throws an ArgumentException
// if you pass in null - Dev10 appears to use 0 instead.
// (See EMITTER::VariantFromConstVal)
value = 0;
typeCode = PrimitiveTypeCode.Int32;
}
if (typeCode == PrimitiveTypeCode.String)
{
DefineLocalStringConstant(name, (string)value, constantSignatureToken);
}
else
{
try
{
this.symWriter.DefineConstant2(name, value, constantSignatureToken);
}
catch (Exception ex)
{
throw new PdbWritingException(ex);
}
}
}
示例7: WriteValue
internal static void WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, object value)
{
switch (typeCode)
{
case PrimitiveTypeCode.Char:
writer.WriteValue((char)value);
break;
case PrimitiveTypeCode.CharNullable:
writer.WriteValue((value == null) ? (char?)null : (char)value);
break;
case PrimitiveTypeCode.Boolean:
writer.WriteValue((bool)value);
break;
case PrimitiveTypeCode.BooleanNullable:
writer.WriteValue((value == null) ? (bool?)null : (bool)value);
break;
case PrimitiveTypeCode.SByte:
writer.WriteValue((sbyte)value);
break;
case PrimitiveTypeCode.SByteNullable:
writer.WriteValue((value == null) ? (sbyte?)null : (sbyte)value);
break;
case PrimitiveTypeCode.Int16:
writer.WriteValue((short)value);
break;
case PrimitiveTypeCode.Int16Nullable:
writer.WriteValue((value == null) ? (short?)null : (short)value);
break;
case PrimitiveTypeCode.UInt16:
writer.WriteValue((ushort)value);
break;
case PrimitiveTypeCode.UInt16Nullable:
writer.WriteValue((value == null) ? (ushort?)null : (ushort)value);
break;
case PrimitiveTypeCode.Int32:
writer.WriteValue((int)value);
break;
case PrimitiveTypeCode.Int32Nullable:
writer.WriteValue((value == null) ? (int?)null : (int)value);
break;
case PrimitiveTypeCode.Byte:
writer.WriteValue((byte)value);
break;
case PrimitiveTypeCode.ByteNullable:
writer.WriteValue((value == null) ? (byte?)null : (byte)value);
break;
case PrimitiveTypeCode.UInt32:
writer.WriteValue((uint)value);
break;
case PrimitiveTypeCode.UInt32Nullable:
writer.WriteValue((value == null) ? (uint?)null : (uint)value);
break;
case PrimitiveTypeCode.Int64:
writer.WriteValue((long)value);
break;
case PrimitiveTypeCode.Int64Nullable:
writer.WriteValue((value == null) ? (long?)null : (long)value);
break;
case PrimitiveTypeCode.UInt64:
writer.WriteValue((ulong)value);
break;
case PrimitiveTypeCode.UInt64Nullable:
writer.WriteValue((value == null) ? (ulong?)null : (ulong)value);
break;
case PrimitiveTypeCode.Single:
writer.WriteValue((float)value);
break;
case PrimitiveTypeCode.SingleNullable:
writer.WriteValue((value == null) ? (float?)null : (float)value);
break;
case PrimitiveTypeCode.Double:
writer.WriteValue((double)value);
break;
case PrimitiveTypeCode.DoubleNullable:
writer.WriteValue((value == null) ? (double?)null : (double)value);
break;
case PrimitiveTypeCode.DateTime:
writer.WriteValue((DateTime)value);
break;
case PrimitiveTypeCode.DateTimeNullable:
writer.WriteValue((value == null) ? (DateTime?)null : (DateTime)value);
break;
case PrimitiveTypeCode.DateTimeOffset:
writer.WriteValue((DateTimeOffset)value);
break;
case PrimitiveTypeCode.DateTimeOffsetNullable:
writer.WriteValue((value == null) ? (DateTimeOffset?)null : (DateTimeOffset)value);
break;
case PrimitiveTypeCode.Decimal:
writer.WriteValue((decimal)value);
break;
case PrimitiveTypeCode.DecimalNullable:
writer.WriteValue((value == null) ? (decimal?)null : (decimal)value);
break;
case PrimitiveTypeCode.Guid:
writer.WriteValue((Guid)value);
break;
case PrimitiveTypeCode.GuidNullable:
writer.WriteValue((value == null) ? (Guid?)null : (Guid)value);
break;
//.........这里部分代码省略.........
示例8: ReadValue
private static object ReadValue(PrimitiveTypeCode primitiveTypeCode, BinaryReader reader) {
Contract.Requires(reader != null);
switch (primitiveTypeCode) {
case PrimitiveTypeCode.Boolean: return reader.ReadBoolean();
case PrimitiveTypeCode.Char: return (char)reader.ReadUInt16();
case PrimitiveTypeCode.Float32: return reader.ReadSingle();
case PrimitiveTypeCode.Float64: return reader.ReadDouble();
case PrimitiveTypeCode.Int16: return reader.ReadInt16();
case PrimitiveTypeCode.Int32: return reader.ReadInt32();
case PrimitiveTypeCode.Int64: return reader.ReadInt64();
case PrimitiveTypeCode.Int8: return reader.ReadSByte();
case PrimitiveTypeCode.UInt16: return reader.ReadUInt16();
case PrimitiveTypeCode.UInt32: return reader.ReadUInt32();
case PrimitiveTypeCode.UInt64: return reader.ReadUInt64();
case PrimitiveTypeCode.UInt8: return reader.ReadByte();
default:
Contract.Assume(false);
break;
}
return null;
}
示例9: WriteValue
internal static void WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, object value)
{
switch (typeCode)
{
case PrimitiveTypeCode.Char:
writer.WriteValue((char)value);
break;
case PrimitiveTypeCode.CharNullable:
writer.WriteValue((char?)value);
break;
case PrimitiveTypeCode.Boolean:
writer.WriteValue((bool)value);
break;
case PrimitiveTypeCode.BooleanNullable:
writer.WriteValue((bool?)value);
break;
case PrimitiveTypeCode.SByte:
writer.WriteValue((sbyte)value);
break;
case PrimitiveTypeCode.SByteNullable:
writer.WriteValue((sbyte?)value);
break;
case PrimitiveTypeCode.Int16:
writer.WriteValue((short)value);
break;
case PrimitiveTypeCode.Int16Nullable:
writer.WriteValue((short?)value);
break;
case PrimitiveTypeCode.UInt16:
writer.WriteValue((ushort)value);
break;
case PrimitiveTypeCode.UInt16Nullable:
writer.WriteValue((ushort?)value);
break;
case PrimitiveTypeCode.Int32:
writer.WriteValue((int)value);
break;
case PrimitiveTypeCode.Int32Nullable:
writer.WriteValue((int?)value);
break;
case PrimitiveTypeCode.Byte:
writer.WriteValue((byte)value);
break;
case PrimitiveTypeCode.ByteNullable:
writer.WriteValue((byte?)value);
break;
case PrimitiveTypeCode.UInt32:
writer.WriteValue((uint)value);
break;
case PrimitiveTypeCode.UInt32Nullable:
writer.WriteValue((uint?)value);
break;
case PrimitiveTypeCode.Int64:
writer.WriteValue((long)value);
break;
case PrimitiveTypeCode.Int64Nullable:
writer.WriteValue((long?)value);
break;
case PrimitiveTypeCode.UInt64:
writer.WriteValue((ulong)value);
break;
case PrimitiveTypeCode.UInt64Nullable:
writer.WriteValue((ulong?)value);
break;
case PrimitiveTypeCode.Single:
writer.WriteValue((float)value);
break;
case PrimitiveTypeCode.SingleNullable:
writer.WriteValue((float?)value);
break;
case PrimitiveTypeCode.Double:
writer.WriteValue((double)value);
break;
case PrimitiveTypeCode.DoubleNullable:
writer.WriteValue((double?)value);
break;
case PrimitiveTypeCode.DateTime:
writer.WriteValue((DateTime)value);
break;
case PrimitiveTypeCode.DateTimeNullable:
writer.WriteValue((DateTime?)value);
break;
case PrimitiveTypeCode.Decimal:
writer.WriteValue((decimal)value);
break;
case PrimitiveTypeCode.DecimalNullable:
writer.WriteValue((decimal?)value);
break;
case PrimitiveTypeCode.Guid:
writer.WriteValue((Guid)value);
break;
case PrimitiveTypeCode.GuidNullable:
writer.WriteValue((Guid?)value);
break;
case PrimitiveTypeCode.TimeSpan:
writer.WriteValue((TimeSpan)value);
break;
case PrimitiveTypeCode.TimeSpanNullable:
writer.WriteValue((TimeSpan?)value);
break;
//.........这里部分代码省略.........
示例10: EmitParametersOfFunctionPointer
private void EmitParametersOfFunctionPointer(bool first, IEnumerable<IParameterTypeInformation> parameters, PrimitiveTypeCode typeCode) {
Contract.Requires(parameters != null);
foreach (var par in parameters) {
Contract.Assume(par != null);
var parType = par.Type.ResolvedType;
if (first) first = false;
else this.sourceEmitter.EmitString(", ");
if (par.IsByReference || (parType.IsValueType && !IsScalarInC(parType)))
this.sourceEmitter.EmitString("uintptr_t ");
else
this.EmitTypeReference(parType, storageLocation: true);
}
if (typeCode != PrimitiveTypeCode.Void) {
if (first) first = false;
else this.sourceEmitter.EmitString(", ");
this.sourceEmitter.EmitString("uintptr_t");
}
this.sourceEmitter.EmitString(")");
}
示例11: PrimitiveType
/// <summary>
/// Writes primitive type code.
/// </summary>
/// <param name="type">Any primitive type code except for <see cref="PrimitiveTypeCode.TypedReference"/> and <see cref="PrimitiveTypeCode.Void"/>.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not valid in this context.</exception>
public void PrimitiveType(PrimitiveTypeCode type)
{
switch (type)
{
case PrimitiveTypeCode.Boolean:
case PrimitiveTypeCode.Byte:
case PrimitiveTypeCode.SByte:
case PrimitiveTypeCode.Char:
case PrimitiveTypeCode.Int16:
case PrimitiveTypeCode.UInt16:
case PrimitiveTypeCode.Int32:
case PrimitiveTypeCode.UInt32:
case PrimitiveTypeCode.Int64:
case PrimitiveTypeCode.UInt64:
case PrimitiveTypeCode.Single:
case PrimitiveTypeCode.Double:
case PrimitiveTypeCode.IntPtr:
case PrimitiveTypeCode.UIntPtr:
case PrimitiveTypeCode.String:
case PrimitiveTypeCode.Object:
Builder.WriteByte((byte)type);
return;
case PrimitiveTypeCode.TypedReference:
case PrimitiveTypeCode.Void:
default:
Throw.ArgumentOutOfRange(nameof(type));
return;
}
}
示例12: GetTypeFor
public INamespaceTypeReference GetTypeFor(PrimitiveTypeCode typeCode)
{
switch (typeCode) {
case PrimitiveTypeCode.Float32: return this.SystemFloat32;
case PrimitiveTypeCode.Float64: return this.SystemFloat64;
case PrimitiveTypeCode.Int16: return this.SystemInt16;
case PrimitiveTypeCode.Int32: return this.SystemInt32;
case PrimitiveTypeCode.Int64: return this.SystemInt64;
case PrimitiveTypeCode.Int8: return this.SystemInt8;
case PrimitiveTypeCode.IntPtr: return this.SystemIntPtr;
case PrimitiveTypeCode.UInt16: return this.SystemUInt16;
case PrimitiveTypeCode.UInt32: return this.SystemUInt32;
case PrimitiveTypeCode.UInt64: return this.SystemUInt64;
case PrimitiveTypeCode.UInt8: return this.SystemUInt8;
case PrimitiveTypeCode.UIntPtr: return this.SystemUIntPtr;
case PrimitiveTypeCode.Void: return this.SystemVoid;
default:
//^ assume false; //TODO: make Boogie aware of distinction between bit maps and enums
return Dummy.NamespaceTypeReference;
}
}
示例13: WritePrimitiveType
internal static void WritePrimitiveType(BlobBuilder builder, PrimitiveTypeCode type)
{
switch (type)
{
case PrimitiveTypeCode.Boolean:
case PrimitiveTypeCode.Byte:
case PrimitiveTypeCode.SByte:
case PrimitiveTypeCode.Char:
case PrimitiveTypeCode.Int16:
case PrimitiveTypeCode.UInt16:
case PrimitiveTypeCode.Int32:
case PrimitiveTypeCode.UInt32:
case PrimitiveTypeCode.Int64:
case PrimitiveTypeCode.UInt64:
case PrimitiveTypeCode.Single:
case PrimitiveTypeCode.Double:
case PrimitiveTypeCode.IntPtr:
case PrimitiveTypeCode.UIntPtr:
case PrimitiveTypeCode.String:
case PrimitiveTypeCode.Object:
builder.WriteByte((byte)type);
return;
// TODO: should we allow these?
case PrimitiveTypeCode.TypedReference:
case PrimitiveTypeCode.Void:
default:
Throw.ArgumentOutOfRange(nameof(type));
return;
}
}
示例14: NamespaceTypeReference
/// <summary>
/// Allocates a type definition that is a member of a namespace definition.
/// </summary>
/// <param name="host">Provides a standard abstraction over the applications that host components that provide or consume objects from the metadata model.</param>
/// <param name="containingUnitNamespace">The namespace that contains the referenced type.</param>
/// <param name="name">The name of the referenced type.</param>
/// <param name="genericParameterCount">The number of generic parameters. Zero if the type is not generic.</param>
/// <param name="isEnum">True if the type is an enumeration (it extends System.Enum and is sealed). Corresponds to C# enum.</param>
/// <param name="isValueType">True if the referenced type is a value type.</param>
/// <param name="typeCode">A value indicating if the type is a primitive type or not.</param>
public NamespaceTypeReference(IMetadataHost host, IUnitNamespaceReference containingUnitNamespace, IName name, ushort genericParameterCount, bool isEnum, bool isValueType, PrimitiveTypeCode typeCode)
: base(host, isEnum, isValueType)
{
Contract.Requires(host != null);
Contract.Requires(containingUnitNamespace != null);
Contract.Requires(name != null);
this.containingUnitNamespace = containingUnitNamespace;
this.name = name;
this.genericParameterCount = genericParameterCount;
this.typeCode = typeCode;
}
示例15: GetTypeFor
public INamespaceTypeReference GetTypeFor(PrimitiveTypeCode typeCode) {
return Dummy.NamespaceTypeReference;
}