本文整理汇总了C#中SpecialType类的典型用法代码示例。如果您正苦于以下问题:C# SpecialType类的具体用法?C# SpecialType怎么用?C# SpecialType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpecialType类属于命名空间,在下文中一共展示了SpecialType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertEnumUnderlyingTypeToUInt64
internal static ulong ConvertEnumUnderlyingTypeToUInt64(object value, SpecialType specialType)
{
Contract.Requires(value != null);
Contract.Requires(value.GetType().GetTypeInfo().IsPrimitive);
unchecked
{
switch (specialType)
{
case SpecialType.System_SByte:
return (ulong)(sbyte)value;
case SpecialType.System_Int16:
return (ulong)(short)value;
case SpecialType.System_Int32:
return (ulong)(int)value;
case SpecialType.System_Int64:
return (ulong)(long)value;
case SpecialType.System_Byte:
return (byte)value;
case SpecialType.System_UInt16:
return (ushort)value;
case SpecialType.System_UInt32:
return (uint)value;
case SpecialType.System_UInt64:
return (ulong)value;
default:
// not using ExceptionUtilities.UnexpectedValue() because this is used by the Services layer
// which doesn't have those utilities.
throw new InvalidOperationException($"{specialType} is not a valid underlying type for an enum");
}
}
}
示例2: CodeGenerationNamedTypeSymbol
public CodeGenerationNamedTypeSymbol(
INamedTypeSymbol containingType,
IList<AttributeData> attributes,
Accessibility declaredAccessibility,
DeclarationModifiers modifiers,
TypeKind typeKind,
string name,
IList<ITypeParameterSymbol> typeParameters,
INamedTypeSymbol baseType,
IList<INamedTypeSymbol> interfaces,
SpecialType specialType,
IList<ISymbol> members,
IList<CodeGenerationAbstractNamedTypeSymbol> typeMembers,
INamedTypeSymbol enumUnderlyingType)
: base(containingType, attributes, declaredAccessibility, modifiers, name, specialType, typeMembers)
{
_typeKind = typeKind;
_typeParameters = typeParameters ?? SpecializedCollections.EmptyList<ITypeParameterSymbol>();
_baseType = baseType;
_interfaces = interfaces ?? SpecializedCollections.EmptyList<INamedTypeSymbol>();
_members = members ?? SpecializedCollections.EmptyList<ISymbol>();
_enumUnderlyingType = enumUnderlyingType;
this.OriginalDefinition = this;
}
示例3: AddExplicitlyCastedLiteralValue
protected override void AddExplicitlyCastedLiteralValue(INamedTypeSymbol namedType, SpecialType type, object value)
{
AddPunctuation(SyntaxKind.OpenParenToken);
namedType.Accept(this.NotFirstVisitor);
AddPunctuation(SyntaxKind.CloseParenToken);
AddLiteralValue(type, value);
}
示例4: CodeGenerationTypeSymbol
protected CodeGenerationTypeSymbol(
INamedTypeSymbol containingType,
IList<AttributeData> attributes,
Accessibility declaredAccessibility,
DeclarationModifiers modifiers,
string name,
SpecialType specialType)
: base(containingType, attributes, declaredAccessibility, modifiers, name)
{
this.SpecialType = specialType;
}
示例5: TryConvertToUInt64
public static bool TryConvertToUInt64(object value, SpecialType specialType, out ulong convertedValue)
{
bool success = false;
convertedValue = 0;
if (value != null)
{
switch (specialType)
{
case SpecialType.System_Int16:
convertedValue = unchecked((ulong)((short)value));
success = true;
break;
case SpecialType.System_Int32:
convertedValue = unchecked((ulong)((int)value));
success = true;
break;
case SpecialType.System_Int64:
convertedValue = unchecked((ulong)((long)value));
success = true;
break;
case SpecialType.System_UInt16:
convertedValue = (ushort)value;
success = true;
break;
case SpecialType.System_UInt32:
convertedValue = (uint)value;
success = true;
break;
case SpecialType.System_UInt64:
convertedValue = (ulong)value;
success = true;
break;
case SpecialType.System_Byte:
convertedValue = (byte)value;
success = true;
break;
case SpecialType.System_SByte:
convertedValue = unchecked((ulong)((sbyte)value));
success = true;
break;
case SpecialType.System_Char:
convertedValue = (char)value;
success = true;
break;
case SpecialType.System_Boolean:
convertedValue = (ulong)((bool)value == true ? 1 : 0);
success = true;
break;
}
}
return success;
}
示例6: EmitSpecial
public void EmitSpecial(SpecialType specialType)
{
switch(specialType){
case SpecialType.one:
specialOne.UseSpecial();
break;
case SpecialType.two:
specialTwo.UseSpecial();
break;
default:
specialThree.UseSpecial();
break;
}
}
示例7: CreateExplicitlyCastedLiteralValue
protected override SyntaxNode CreateExplicitlyCastedLiteralValue(
INamedTypeSymbol enumType,
SpecialType underlyingSpecialType,
object constantValue)
{
var expression = ExpressionGenerator.GenerateNonEnumValueExpression(
enumType.EnumUnderlyingType, constantValue, canUseFieldReference: true);
var constantValueULong = EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(constantValue, underlyingSpecialType);
if (constantValueULong == 0)
{
// 0 is always convertible to an enum type without needing a cast.
return expression;
}
var factory = new CSharpSyntaxGenerator();
return factory.CastExpression(enumType, expression);
}
示例8: Convert
/// <summary>
/// Helper as VB's CType doesn't work without arithmetic overflow.
/// </summary>
public static long Convert(long v, SpecialType type)
{
switch (type)
{
case SpecialType.System_SByte:
return unchecked((sbyte)v);
case SpecialType.System_Byte:
return unchecked((byte)v);
case SpecialType.System_Int16:
return unchecked((short)v);
case SpecialType.System_UInt16:
return unchecked((ushort)v);
case SpecialType.System_Int32:
return unchecked((int)v);
case SpecialType.System_UInt32:
return unchecked((uint)v);
default:
return v;
}
}
示例9: AddLiteralValue
protected override void AddLiteralValue(SpecialType type, object value)
{
Debug.Assert(value.GetType().GetTypeInfo().IsPrimitive || value is string || value is decimal);
var valueString = SymbolDisplay.FormatPrimitive(value, quoteStrings: true, useHexadecimalNumbers: false);
Debug.Assert(valueString != null);
var kind = SymbolDisplayPartKind.NumericLiteral;
switch (type)
{
case SpecialType.System_Boolean:
kind = SymbolDisplayPartKind.Keyword;
break;
case SpecialType.System_String:
case SpecialType.System_Char:
kind = SymbolDisplayPartKind.StringLiteral;
break;
}
this.builder.Add(CreatePart(kind, null, valueString));
}
示例10: SpecialTypeToString
public static string SpecialTypeToString(SpecialType specialType)
{
switch (specialType)
{
case SpecialType.System_Boolean:
return "bool";
case SpecialType.System_Byte:
return "byte";
case SpecialType.System_SByte:
return "sbyte";
case SpecialType.System_Int16:
return "short";
case SpecialType.System_UInt16:
return "ushort";
case SpecialType.System_Int32:
return "int";
case SpecialType.System_UInt32:
return "uint";
case SpecialType.System_Int64:
return "long";
case SpecialType.System_UInt64:
return "ulong";
case SpecialType.System_Double:
return "double";
case SpecialType.System_Single:
return "float";
case SpecialType.System_Decimal:
return "decimal";
case SpecialType.System_String:
return "string";
case SpecialType.System_Char:
return "char";
case SpecialType.System_Void:
return "void";
case SpecialType.System_Object:
return "object";
default:
return null;
}
}
示例11: GetDeclaredSpecialType
/// <summary>
/// Lookup declaration for predefined CorLib type in this Assembly.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
/// <remarks></remarks>
internal override NamedTypeSymbol GetDeclaredSpecialType(SpecialType type)
{
#if DEBUG
foreach (var module in this.Modules)
{
Debug.Assert(module.GetReferencedAssemblies().Length == 0);
}
#endif
if (_lazySpecialTypes == null || (object)_lazySpecialTypes[(int)type] == null)
{
MetadataTypeName emittedName = MetadataTypeName.FromFullName(type.GetMetadataName(), useCLSCompliantNameArityEncoding: true);
ModuleSymbol module = this.Modules[0];
NamedTypeSymbol result = module.LookupTopLevelMetadataType(ref emittedName);
if (result.Kind != SymbolKind.ErrorType && result.DeclaredAccessibility != Accessibility.Public)
{
result = new MissingMetadataTypeSymbol.TopLevel(module, ref emittedName, type);
}
RegisterDeclaredSpecialType(result);
}
return _lazySpecialTypes[(int)type];
}
示例12: CreateOne
private static object CreateOne(SpecialType specialType)
{
switch (specialType)
{
case SpecialType.System_SByte:
return (sbyte)1;
case SpecialType.System_Byte:
return (byte)1;
case SpecialType.System_Int16:
return (short)1;
case SpecialType.System_UInt16:
return (ushort)1;
case SpecialType.System_Int32:
return (int)1;
case SpecialType.System_UInt32:
return (uint)1;
case SpecialType.System_Int64:
return (long)1;
case SpecialType.System_UInt64:
return (ulong)1;
default:
return 1;
}
}
示例13: GetDeclaredSpecialType
/// <summary>
/// Lookup declaration for predefined CorLib type in this Assembly. Only should be
/// called if it is know that this is the Cor Library (mscorlib).
/// </summary>
/// <param name="type"></param>
internal override NamedTypeSymbol GetDeclaredSpecialType(SpecialType type)
{
#if DEBUG
foreach (var module in this.Modules)
{
Debug.Assert(module.GetReferencedAssemblies().Length == 0);
}
#endif
if (_lazySpecialTypes == null)
{
Interlocked.CompareExchange(ref _lazySpecialTypes,
new NamedTypeSymbol[(int)SpecialType.Count + 1], null);
}
if ((object)_lazySpecialTypes[(int)type] == null)
{
MetadataTypeName emittedFullName = MetadataTypeName.FromFullName(SpecialTypes.GetMetadataName(type), useCLSCompliantNameArityEncoding: true);
NamedTypeSymbol corType = new MissingMetadataTypeSymbol.TopLevel(this.moduleSymbol, ref emittedFullName, type);
Interlocked.CompareExchange(ref _lazySpecialTypes[(int)type], corType, null);
}
return _lazySpecialTypes[(int)type];
}
示例14: GetPrimitiveTypeName
protected override string GetPrimitiveTypeName(SpecialType type)
{
switch (type)
{
case SpecialType.System_Boolean: return "bool";
case SpecialType.System_Byte: return "byte";
case SpecialType.System_Char: return "char";
case SpecialType.System_Decimal: return "decimal";
case SpecialType.System_Double: return "double";
case SpecialType.System_Int16: return "short";
case SpecialType.System_Int32: return "int";
case SpecialType.System_Int64: return "long";
case SpecialType.System_SByte: return "sbyte";
case SpecialType.System_Single: return "float";
case SpecialType.System_String: return "string";
case SpecialType.System_UInt16: return "ushort";
case SpecialType.System_UInt32: return "uint";
case SpecialType.System_UInt64: return "ulong";
case SpecialType.System_Object: return "object";
default:
return null;
}
}
示例15: GetPrimitiveTypeName
public abstract string GetPrimitiveTypeName(SpecialType type);