本文整理汇总了C#中KnownTypeCode类的典型用法代码示例。如果您正苦于以下问题:C# KnownTypeCode类的具体用法?C# KnownTypeCode怎么用?C# KnownTypeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KnownTypeCode类属于命名空间,在下文中一共展示了KnownTypeCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStructTypeKind
global::EnvDTE.vsCMTypeRef GetStructTypeKind(KnownTypeCode knownTypeCode)
{
switch (knownTypeCode) {
case KnownTypeCode.Boolean:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefBool;
case KnownTypeCode.Char:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefChar;
case KnownTypeCode.SByte:
case KnownTypeCode.Byte:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefByte;
case KnownTypeCode.Int16:
case KnownTypeCode.UInt16:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefShort;
case KnownTypeCode.Int32:
case KnownTypeCode.UInt32:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefInt;
case KnownTypeCode.Int64:
case KnownTypeCode.UInt64:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefLong;
case KnownTypeCode.Single:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefFloat;
case KnownTypeCode.Double:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefDouble;
case KnownTypeCode.Decimal:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefDecimal;
case KnownTypeCode.Void:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefVoid;
case KnownTypeCode.IntPtr:
case KnownTypeCode.UIntPtr:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefPointer;
default:
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefOther;
}
}
示例2: FindType
public IType FindType(KnownTypeCode typeCode)
{
IType type = LazyInit.VolatileRead(ref knownTypes[(int)typeCode]);
if (type != null) {
return type;
}
return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode));
}
示例3: FindType
public IType FindType(KnownTypeCode typeCode)
{
IType type = knownTypes[(int)typeCode];
if (type != null) {
LazyInit.ReadBarrier();
return type;
}
return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode));
}
示例4: SearchType
IType SearchType(KnownTypeCode typeCode)
{
KnownTypeReference typeRef = KnownTypeReference.Get(typeCode);
if (typeRef == null)
return SpecialType.UnknownType;
foreach (IAssembly asm in compilation.Assemblies) {
var typeDef = asm.GetTypeDefinition(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount);
if (typeDef != null)
return typeDef;
}
return new UnknownType(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount);
}
示例5: ResolveKnownBaseType
/// <summary>
/// Finds IList<T> or IEnumerable<T> base type.
/// </summary>
/// <param name="fullNamePrefix">Type code to search for (IList<T> or IEnumerable<T>)</param></param>
/// <param name="implementation">Found implementation.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
private static bool ResolveKnownBaseType(this IType type, KnownTypeCode knownTypeCode, out ParameterizedType implementation, out IType itemType)
{
if (type == null) throw new ArgumentNullException("type");
implementation = null;
itemType = null;
ParameterizedType impl =
type.GetAllBaseTypes().OfType<ParameterizedType>().
Where(t => t.IsKnownType(knownTypeCode) && t.TypeParameterCount == 1)
.FirstOrDefault();
if (impl != null) {
implementation = impl;
itemType = impl.GetTypeArgument(0);
return true;
}
return false;
}
示例6: KnownTypeReference
private KnownTypeReference(KnownTypeCode knownTypeCode, string namespaceName, string name, int typeParameterCount = 0, KnownTypeCode baseType = KnownTypeCode.Object)
{
this.knownTypeCode = knownTypeCode;
this.namespaceName = namespaceName;
this.name = name;
this.typeParameterCount = typeParameterCount;
this.baseType = baseType;
}
示例7: Get
/// <summary>
/// Gets the known type reference for the specified type code.
/// Returns null for KnownTypeCode.None.
/// </summary>
public static KnownTypeReference Get(KnownTypeCode typeCode)
{
return knownTypeReferences[(int)typeCode];
}
示例8: ConvertType
protected AstType ConvertType(KnownTypeCode knownTypeCode)
{
IType type = refactoringContext.Compilation.FindType(knownTypeCode);
if (type != null)
return ConvertType(type);
// Backup solution
return new SimpleType(KnownTypeReference.GetCSharpNameByTypeCode(knownTypeCode));
}
示例9: ReadElemValue
object ReadElemValue(KnownTypeCode typeCode)
{
switch (typeCode) {
case KnownTypeCode.Boolean:
return ReadByte() != 0;
case KnownTypeCode.Char:
return (char)ReadUInt16();
case KnownTypeCode.SByte:
return ReadSByte();
case KnownTypeCode.Byte:
return ReadByte();
case KnownTypeCode.Int16:
return ReadInt16();
case KnownTypeCode.UInt16:
return ReadUInt16();
case KnownTypeCode.Int32:
return ReadInt32();
case KnownTypeCode.UInt32:
return ReadUInt32();
case KnownTypeCode.Int64:
return ReadInt64();
case KnownTypeCode.UInt64:
return ReadUInt64();
case KnownTypeCode.Single:
return ReadSingle();
case KnownTypeCode.Double:
return ReadDouble();
case KnownTypeCode.String:
return ReadSerString();
default:
throw new NotSupportedException();
}
}
示例10: SetValue
public static unsafe void SetValue(this ICorDebugGenericValue corGenVal, KnownTypeCode type, object value)
{
if (value == null)
throw new ArgumentNullException("value");
byte[] val = new byte[(int)corGenVal.GetSize()];
fixed(byte* pValue = val) {
switch(type) {
case KnownTypeCode.Boolean: *((System.Boolean*)pValue) = (System.Boolean)value; break;
case KnownTypeCode.Char: *((System.Char*) pValue) = (System.Char) value; break;
case KnownTypeCode.SByte: *((System.SByte*) pValue) = (System.SByte) value; break;
case KnownTypeCode.Byte: *((System.Byte*) pValue) = (System.Byte) value; break;
case KnownTypeCode.Int16: *((System.Int16*) pValue) = (System.Int16) value; break;
case KnownTypeCode.UInt16: *((System.UInt16*) pValue) = (System.UInt16) value; break;
case KnownTypeCode.Int32: *((System.Int32*) pValue) = (System.Int32) value; break;
case KnownTypeCode.UInt32: *((System.UInt32*) pValue) = (System.UInt32) value; break;
case KnownTypeCode.Int64: *((System.Int64*) pValue) = (System.Int64) value; break;
case KnownTypeCode.UInt64: *((System.UInt64*) pValue) = (System.UInt64) value; break;
case KnownTypeCode.Single: *((System.Single*) pValue) = (System.Single) value; break;
case KnownTypeCode.Double: *((System.Double*) pValue) = (System.Double) value; break;
case KnownTypeCode.IntPtr: *((System.IntPtr*) pValue) = (System.IntPtr) value; break;
case KnownTypeCode.UIntPtr: *((System.UIntPtr*)pValue) = (System.UIntPtr)value; break;
default: throw new NotSupportedException();
}
corGenVal.SetValue(new IntPtr(pValue));
}
}
示例11: GetValue
public static unsafe object GetValue(this ICorDebugGenericValue corGenVal, KnownTypeCode type)
{
object retValue;
byte[] value = new byte[(int)corGenVal.GetSize()];
fixed(byte* pValue = value) {
corGenVal.GetValue(new IntPtr(pValue));
switch (type) {
case KnownTypeCode.Boolean: retValue = *((System.Boolean*)pValue); break;
case KnownTypeCode.Char: retValue = *((System.Char*) pValue); break;
case KnownTypeCode.SByte: retValue = *((System.SByte*) pValue); break;
case KnownTypeCode.Byte: retValue = *((System.Byte*) pValue); break;
case KnownTypeCode.Int16: retValue = *((System.Int16*) pValue); break;
case KnownTypeCode.UInt16: retValue = *((System.UInt16*) pValue); break;
case KnownTypeCode.Int32: retValue = *((System.Int32*) pValue); break;
case KnownTypeCode.UInt32: retValue = *((System.UInt32*) pValue); break;
case KnownTypeCode.Int64: retValue = *((System.Int64*) pValue); break;
case KnownTypeCode.UInt64: retValue = *((System.UInt64*) pValue); break;
case KnownTypeCode.Single: retValue = *((System.Single*) pValue); break;
case KnownTypeCode.Double: retValue = *((System.Double*) pValue); break;
case KnownTypeCode.IntPtr: retValue = *((System.IntPtr*) pValue); break;
case KnownTypeCode.UIntPtr: retValue = *((System.UIntPtr*)pValue); break;
default: throw new NotSupportedException();
}
}
return retValue;
}
示例12: IsKnownType
/// <summary>
/// Gets whether the type is the specified known type.
/// For generic known types, this returns true any parameterization of the type (and also for the definition itself).
/// </summary>
public static bool IsKnownType(this IType type, KnownTypeCode knownType)
{
var def = type.GetDefinition();
return def != null && def.KnownTypeCode == knownType;
}
示例13: GetCSharpNameByTypeCode
/// <summary>
/// Gets the C# primitive type name from the known type code.
/// Returns null if there is no primitive name for the specified type.
/// </summary>
public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode)
{
switch (knownTypeCode) {
case KnownTypeCode.Object:
return "object";
case KnownTypeCode.Boolean:
return "bool";
case KnownTypeCode.Char:
return "char";
case KnownTypeCode.SByte:
return "sbyte";
case KnownTypeCode.Byte:
return "byte";
case KnownTypeCode.Int16:
return "short";
case KnownTypeCode.UInt16:
return "ushort";
case KnownTypeCode.Int32:
return "int";
case KnownTypeCode.UInt32:
return "uint";
case KnownTypeCode.Int64:
return "long";
case KnownTypeCode.UInt64:
return "ulong";
case KnownTypeCode.Single:
return "float";
case KnownTypeCode.Double:
return "double";
case KnownTypeCode.Decimal:
return "decimal";
case KnownTypeCode.String:
return "string";
case KnownTypeCode.Void:
return "void";
default:
return null;
}
}
示例14: IsIntegerTypeCode
private static bool IsIntegerTypeCode(KnownTypeCode code)
{
switch (code) {
case KnownTypeCode.Char:
case KnownTypeCode.SByte:
case KnownTypeCode.Byte:
case KnownTypeCode.Int16:
case KnownTypeCode.UInt16:
case KnownTypeCode.Int32:
case KnownTypeCode.UInt32:
case KnownTypeCode.Int64:
case KnownTypeCode.UInt64: {
return true;
}
}
return false;
}
示例15: IsFloatingPointTypeCode
private static bool IsFloatingPointTypeCode(KnownTypeCode code)
{
return code == KnownTypeCode.Single || code == KnownTypeCode.Double;
}