当前位置: 首页>>代码示例>>C#>>正文


C# SpecialType类代码示例

本文整理汇总了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");
                }
            }
        }
开发者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


注:本文中的SpecialType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。