本文整理汇总了C#中SpecialType类的典型用法代码示例。如果您正苦于以下问题:C# SpecialType类的具体用法?C# SpecialType怎么用?C# SpecialType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpecialType类属于命名空间,在下文中一共展示了SpecialType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
}
}
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:33,代码来源:NamedSymbolExtensions.cs
示例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;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:25,代码来源:CodeGenerationNamedTypeSymbol.cs
示例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);
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:SymbolDisplayVisitor_Constants.cs
示例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;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:11,代码来源:CodeGenerationTypeSymbol.cs
示例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;
}
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:53,代码来源:DiagnosticHelpers.cs
示例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;
}
}
开发者ID:MylesBell,项目名称:Unity,代码行数:14,代码来源:Specials.cs
示例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);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:CSharpFlagsEnumGenerator.cs
示例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;
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:23,代码来源:IntegerUtilities.cs
示例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));
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:21,代码来源:SymbolDisplayVisitor_Constants.cs
示例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;
}
}
开发者ID:vbfox,项目名称:NFluentConversion,代码行数:40,代码来源:CSharpTypeNaming.cs
示例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];
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:29,代码来源:MetadataOrSourceAssemblySymbol.cs
示例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;
}
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:24,代码来源:EnumValueUtilities.cs
示例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];
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:MissingCorLibrarySymbol.cs
示例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;
}
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:24,代码来源:CSharpTypeNameFormatter.cs
示例15: GetPrimitiveTypeName
public abstract string GetPrimitiveTypeName(SpecialType type);
开发者ID:daking2014,项目名称:roslyn,代码行数:1,代码来源:ObjectFormatter.cs
示例16: SpecialType
public NamedTypeSymbol SpecialType(SpecialType st)
{
NamedTypeSymbol specialType = Compilation.GetSpecialType(st);
Binder.ReportUseSiteDiagnostics(specialType, Diagnostics, Syntax);
return specialType;
}
开发者ID:afrog33k,项目名称:csnative,代码行数:6,代码来源:SyntheticBoundNodeFactory.cs
示例17: GetPredefinedKeywordKind
/// <summary>
/// Returns the predefined keyword kind for a given specialtype.
/// </summary>
/// <param name="specialType">The specialtype of this type.</param>
/// <returns>The keyword kind for a given special type, or SyntaxKind.None if the type name is not a predefined type.</returns>
public static SyntaxKind GetPredefinedKeywordKind(SpecialType specialType)
{
switch (specialType)
{
case SpecialType.System_Boolean:
return SyntaxKind.BoolKeyword;
case SpecialType.System_Byte:
return SyntaxKind.ByteKeyword;
case SpecialType.System_SByte:
return SyntaxKind.SByteKeyword;
case SpecialType.System_Int32:
return SyntaxKind.IntKeyword;
case SpecialType.System_UInt32:
return SyntaxKind.UIntKeyword;
case SpecialType.System_Int16:
return SyntaxKind.ShortKeyword;
case SpecialType.System_UInt16:
return SyntaxKind.UShortKeyword;
case SpecialType.System_Int64:
return SyntaxKind.LongKeyword;
case SpecialType.System_UInt64:
return SyntaxKind.ULongKeyword;
case SpecialType.System_Single:
return SyntaxKind.FloatKeyword;
case SpecialType.System_Double:
return SyntaxKind.DoubleKeyword;
case SpecialType.System_Decimal:
return SyntaxKind.DecimalKeyword;
case SpecialType.System_String:
return SyntaxKind.StringKeyword;
case SpecialType.System_Char:
return SyntaxKind.CharKeyword;
case SpecialType.System_Object:
return SyntaxKind.ObjectKeyword;
case SpecialType.System_Void:
return SyntaxKind.VoidKeyword;
default:
return SyntaxKind.None;
}
}
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:45,代码来源:ExpressionSyntaxExtensions.cs
示例18: DoUncheckedConversion
private static object DoUncheckedConversion(SpecialType destinationType, ConstantValue value)
{
// Note that we keep "single" floats as doubles internally to maintain higher precision. However,
// we do not do so in an entirely "lossless" manner. When *converting* to a float, we do lose
// the precision lost due to the conversion. But when doing arithmetic, we do the arithmetic on
// the double values.
//
// An example will help. Suppose we have:
//
// const float cf1 = 1.0f;
// const float cf2 = 1.0e-15f;
// const double cd3 = cf1 - cf2;
//
// We first take the double-precision values for 1.0 and 1.0e-15 and round them to floats,
// and then turn them back into doubles. Then when we do the subtraction, we do the subtraction
// in doubles, not in floats. Had we done the subtraction in floats, we'd get 1.0; but instead we
// do it in doubles and get 0.99999999999999.
//
// Similarly, if we have
//
// const int i4 = int.MaxValue; // 2147483647
// const float cf5 = int.MaxValue; // 2147483648.0
// const double cd6 = cf5; // 2147483648.0
//
// The int is converted to float and stored internally as the double 214783648, even though the
// fully precise int would fit into a double.
unchecked
{
switch (value.Discriminator)
{
case ConstantValueTypeDiscriminator.Byte:
byte byteValue = value.ByteValue;
switch (destinationType)
{
case SpecialType.System_Byte: return (byte)byteValue;
case SpecialType.System_Char: return (char)byteValue;
case SpecialType.System_UInt16: return (ushort)byteValue;
case SpecialType.System_UInt32: return (uint)byteValue;
case SpecialType.System_UInt64: return (ulong)byteValue;
case SpecialType.System_SByte: return (sbyte)byteValue;
case SpecialType.System_Int16: return (short)byteValue;
case SpecialType.System_Int32: return (int)byteValue;
case SpecialType.System_Int64: return (long)byteValue;
case SpecialType.System_Single:
case SpecialType.System_Double: return (double)byteValue;
case SpecialType.System_Decimal: return (decimal)byteValue;
}
break;
case ConstantValueTypeDiscriminator.Char:
char charValue = value.CharValue;
switch (destinationType)
{
case SpecialType.System_Byte: return (byte)charValue;
case SpecialType.System_Char: return (char)charValue;
case SpecialType.System_UInt16: return (ushort)charValue;
case SpecialType.System_UInt32: return (uint)charValue;
case SpecialType.System_UInt64: return (ulong)charValue;
case SpecialType.System_SByte: return (sbyte)charValue;
case SpecialType.System_Int16: return (short)charValue;
case SpecialType.System_Int32: return (int)charValue;
case SpecialType.System_Int64: return (long)charValue;
case SpecialType.System_Single:
case SpecialType.System_Double: return (double)charValue;
case SpecialType.System_Decimal: return (decimal)charValue;
}
break;
case ConstantValueTypeDiscriminator.UInt16:
ushort uint16Value = value.UInt16Value;
switch (destinationType)
{
case SpecialType.System_Byte: return (byte)uint16Value;
case SpecialType.System_Char: return (char)uint16Value;
case SpecialType.System_UInt16: return (ushort)uint16Value;
case SpecialType.System_UInt32: return (uint)uint16Value;
case SpecialType.System_UInt64: return (ulong)uint16Value;
case SpecialType.System_SByte: return (sbyte)uint16Value;
case SpecialType.System_Int16: return (short)uint16Value;
case SpecialType.System_Int32: return (int)uint16Value;
case SpecialType.System_Int64: return (long)uint16Value;
case SpecialType.System_Single:
case SpecialType.System_Double: return (double)uint16Value;
case SpecialType.System_Decimal: return (decimal)uint16Value;
}
break;
case ConstantValueTypeDiscriminator.UInt32:
uint uint32Value = value.UInt32Value;
switch (destinationType)
{
case SpecialType.System_Byte: return (byte)uint32Value;
case SpecialType.System_Char: return (char)uint32Value;
case SpecialType.System_UInt16: return (ushort)uint32Value;
case SpecialType.System_UInt32: return (uint)uint32Value;
case SpecialType.System_UInt64: return (ulong)uint32Value;
case SpecialType.System_SByte: return (sbyte)uint32Value;
case SpecialType.System_Int16: return (short)uint32Value;
case SpecialType.System_Int32: return (int)uint32Value;
case SpecialType.System_Int64: return (long)uint32Value;
case SpecialType.System_Single: return (double)(float)uint32Value;
case SpecialType.System_Double: return (double)uint32Value;
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:Binder_Conversions.cs
示例19: CheckConstantBounds
private static bool CheckConstantBounds(SpecialType destinationType, decimal value)
{
// Dev10 checks (minValue - 1) < value < (MaxValue + 1) + 1).
// See ExpressionBinder::isConstantInRange.
switch (destinationType)
{
case SpecialType.System_Byte: return (byte.MinValue - 1M) < value && value < (byte.MaxValue + 1M);
case SpecialType.System_Char: return (char.MinValue - 1M) < value && value < (char.MaxValue + 1M);
case SpecialType.System_UInt16: return (ushort.MinValue - 1M) < value && value < (ushort.MaxValue + 1M);
case SpecialType.System_UInt32: return (uint.MinValue - 1M) < value && value < (uint.MaxValue + 1M);
case SpecialType.System_UInt64: return (ulong.MinValue - 1M) < value && value < (ulong.MaxValue + 1M);
case SpecialType.System_SByte: return (sbyte.MinValue - 1M) < value && value < (sbyte.MaxValue + 1M);
case SpecialType.System_Int16: return (short.MinValue - 1M) < value && value < (short.MaxValue + 1M);
case SpecialType.System_Int32: return (int.MinValue - 1M) < value && value < (int.MaxValue + 1M);
case SpecialType.System_Int64: return (long.MinValue - 1M) < value && value < (long.MaxValue + 1M);
}
return true;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:Binder_Conversions.cs
示例20: GetSpecialType
/// <summary>
/// Get the symbol for the predefined type from the COR Library referenced by this compilation.
/// </summary>
internal new NamedTypeSymbol GetSpecialType(SpecialType specialType)
{
if (specialType <= SpecialType.None || specialType > SpecialType.Count)
{
throw new ArgumentOutOfRangeException("specialType");
}
var result = Assembly.GetSpecialType(specialType);
Debug.Assert(result.SpecialType == specialType);
return result;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:14,代码来源:CSharpCompilation.cs
注:本文中的SpecialType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论