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


C# ITypeSymbol.ToString方法代码示例

本文整理汇总了C#中ITypeSymbol.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeSymbol.ToString方法的具体用法?C# ITypeSymbol.ToString怎么用?C# ITypeSymbol.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITypeSymbol的用法示例。


在下文中一共展示了ITypeSymbol.ToString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractTypeNameFromSymbol

        private static string ExtractTypeNameFromSymbol(ITypeSymbol typeSymbol)
        {
            var name = typeSymbol.ToString();
            if (name == "int?") { return "System.Int32"; }
            if (name == "bool?") { return "System.Boolean"; }
            if (name == "System.DateTime?") { return "System.DateTime"; }

            return typeSymbol.ContainingNamespace + "." + typeSymbol.Name;
        }
开发者ID:lukeautry,项目名称:DotNetWebSDK,代码行数:9,代码来源:TypeResolver.cs

示例2: DeterminesIfValueType

        public bool DeterminesIfValueType(ITypeSymbol typeSymbol)
        {
            var parameterType = typeSymbol.ToString();
            if (!typeSymbol.IsValueType &&
                (parameterType.Equals("system.string", StringComparison.OrdinalIgnoreCase) || parameterType.Equals("string", StringComparison.OrdinalIgnoreCase)))
            {
                return true;
            }

            return typeSymbol.IsValueType;
        }
开发者ID:romerod,项目名称:FactoryGenerator,代码行数:11,代码来源:ParameterSymbolBuilderService.cs

示例3: GetFormatCompletionForType

		IEnumerable<CompletionData> GetFormatCompletionForType(CompletionEngine engine, ITypeSymbol type)
		{
			if (type == null) {
				return GenerateNumberFormatitems (engine, false)
					.Concat (GenerateDateTimeFormatitems (engine))
					.Concat (GenerateTimeSpanFormatitems (engine))
					.Concat (GenerateEnumFormatitems (engine))
					.Concat (GenerateGuidFormatitems (engine));
			}

			switch (type.ToString()) {
				case "long":
				case "System.Int64":
				case "ulong":
				case "System.UInt64":
				case "int":
				case "System.Int32":
				case "uint":
				case "System.UInt32":
				case "short":
				case "System.Int16":
				case "ushort":
				case "System.UInt16":
				case "byte":
				case "System.Byte":
				case "sbyte":
				case "System.SByte":
				return GenerateNumberFormatitems(engine, false);
				case "float":
				case "System.Single":
				case "double":
				case "System.Double":
				case "decimal":
				case "System.Decimal":
				return GenerateNumberFormatitems(engine, true);
				case "System.Enum":
				return GenerateEnumFormatitems(engine);
				case "System.DateTime":
				return GenerateDateTimeFormatitems(engine);
				case "System.TimeSpan":
				return GenerateTimeSpanFormatitems(engine);
				case "System.Guid":
				return GenerateGuidFormatitems(engine);
			}
			return CompletionResult.Empty;
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:46,代码来源:FormatItemContextHandler.cs

示例4: TryGetTypeReference


//.........这里部分代码省略.........
        ITypeReference eleType;
        if (!TryGetTypeReference(semanticType.ElementType(), out eleType))
          goto ReturnFalse;
        if (semanticType.ElementType().TypeKind == TypeKind.Array) {
          Contract.Assume(((IArrayTypeSymbol)semanticType).Rank > 0);
          cciType = new Microsoft.Cci.MutableCodeModel.MatrixTypeReference() {
            ElementType = eleType,
            InternFactory = this.Host.InternFactory,
            Rank = (uint)((IArrayTypeSymbol)semanticType).Rank
          };
          goto ReturnTrue;
        } else {
          cciType = new Microsoft.Cci.MutableCodeModel.VectorTypeReference() {
            ElementType = eleType,
            InternFactory = this.Host.InternFactory,
          };
          goto ReturnTrue;
        }
      }
      #endregion
      #region If type parameter
      if (semanticType.TypeKind == TypeKind.TypeParameter) {
        if (semanticType.DefiningMember() != null) {
          cciType = new Microsoft.Cci.MutableCodeModel.GenericMethodParameterReference() {
            Index = (ushort)(!semanticType.DefiningMember().TypeParameters().IsDefault ? semanticType.DefiningMember().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
            InternFactory = this.Host.InternFactory,
            Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
          };
          goto ReturnTrue;
        } else if (semanticType.DefiningType() != null) {
          ITypeReference cciDefiningType;
          if (!TryGetTypeReference(semanticType.DefiningType(), out cciDefiningType))
            goto ReturnFalse;
          cciType = new Microsoft.Cci.MutableCodeModel.GenericTypeParameterReference() {
            DefiningType = cciDefiningType,
            Index = (ushort)(!semanticType.DefiningType().TypeParameters().IsDefaultOrEmpty ? semanticType.DefiningType().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
            InternFactory = this.Host.InternFactory,
            Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
          };
          goto ReturnTrue;
        }
      }
      #endregion
      #region If namespace type
      if (semanticType.ContainingType == null)
      {
        IUnitNamespaceReference cciNamespace;
        var namespaceName = semanticType.ContainingNamespace;
        if (namespaceName == null || !TryGetNamespaceReference(namespaceName, cciAssembly, out cciNamespace))
        {
          cciNamespace = new Microsoft.Cci.MutableCodeModel.RootUnitNamespaceReference() { Unit = cciAssembly };
        }
        if (semanticType.ContainingType == null)
        {
          if (semanticType.Name == null || semanticType.Name == null) goto ReturnFalse;
          cciType = new Microsoft.Cci.MutableCodeModel.NamespaceTypeReference()
          {
            ContainingUnitNamespace = cciNamespace,
            GenericParameterCount = (ushort) (semanticType.TypeParameters().IsDefault ? 0 : semanticType.TypeParameters().Length),
            InternFactory = Host.InternFactory,
            IsValueType = semanticType.IsValueType,
            IsEnum = semanticType.TypeKind == TypeKind.Enum,
            Name = Host.NameTable.GetNameFor(semanticType.Name),
            TypeCode = CSharpToCCIHelper.GetPrimitiveTypeCode(semanticType),
          };
          goto ReturnTrue;
        }
      }
      #endregion
      #region If nested type
      if (semanticType.ContainingType != null) {
        ITypeReference containingType;
        if (!TryGetTypeReference(semanticType.ContainingType, cciAssembly, out containingType))
          goto ReturnFalse;
        if (semanticType.Name == null || semanticType.Name == null) goto ReturnFalse;
        cciType = new Microsoft.Cci.MutableCodeModel.NestedTypeReference()
        {
          ContainingType = containingType,
          GenericParameterCount = (ushort)(semanticType.TypeParameters().IsDefault ? 0 : semanticType.TypeParameters().Length),
          InternFactory = this.Host.InternFactory,
          MangleName = true,
          Name = Host.NameTable.GetNameFor(semanticType.Name)
        };
        goto ReturnTrue;
      }
      #endregion
      #region ReturnTrue:
    ReturnTrue:
      if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
        _semanticTypesToCCITypes[semanticType] = cciType;
      return true;
      #endregion
      #region ReturnFalse:
    ReturnFalse:
      ContractsPackageAccessor.Current.Logger.WriteToLog("Failed to build type reference for: " + (semanticType.Name != null ? semanticType.Name : semanticType.ToString()));
      if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
        _semanticTypesToCCITypes[semanticType] = Dummy.TypeReference;
      return false;
      #endregion
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:ContractsProvider.cs

示例5: VerifyType

        internal static void VerifyType(ContextReporter context, Location reportLocation, ITypeSymbol type, HashSet<ITypeSymbol> alreadyAnalyzed)
        {
            if (type.TypeKind == TypeKind.Array)
            {
                var array = type as IArrayTypeSymbol;
                VerifyType(context, reportLocation, array.ElementType, alreadyAnalyzed);
                return;
            }

            var namedTypeSymbol = (type as INamedTypeSymbol);
            if (namedTypeSymbol != null && namedTypeSymbol.IsGenericType)
            {
                foreach (var item in namedTypeSymbol.TypeArguments)
                {
                    VerifyType(context, reportLocation, item, alreadyAnalyzed);
                }
                return;
            }

            if (type.TypeKind == TypeKind.Class || type.TypeKind == TypeKind.Struct)
            {
                if (type.Locations[0].Kind == LocationKind.MetadataFile)
                {
                    return;
                }

                if (!alreadyAnalyzed.Add(type)) return;

                var typeLocation = type.Locations[0];
                var members = type.GetMembers().Where(x => x is IFieldSymbol || x is IPropertySymbol)
                    .Where(x=> x.CanBeReferencedByName)
                    .ToArray();
                if (members.Length != 0)
                {
                    var hasDiagnostic = false;
                    foreach (var member in members)
                    {
                        if (!hasDiagnostic)
                        {
                            hasDiagnostic = VerifyMember(context, reportLocation, member, typeLocation);
                        }

                        VerifyType(context, reportLocation, (member as IFieldSymbol)?.Type ?? (member as IPropertySymbol)?.Type ?? null, alreadyAnalyzed);
                    }

                    if (!hasDiagnostic)
                    {
                        var dataContract = type.GetAttributes().FirstOrDefault(y => y.AttributeClass.ToString() == "System.Runtime.Serialization.DataContractAttribute");
                        if (dataContract == null)
                        {
                            context.ReportDiagnostic(Diagnostic.Create(SerializeTypeMustBeDataContract, reportLocation, new[] { typeLocation }, type.ToString()));
                        }
                    }
                }
            }
        }
开发者ID:neuecc,项目名称:PhotonWire,代码行数:56,代码来源:SerializeTypeMustBeDataContractAnalyzer.cs

示例6: FilterOverrides

		protected static ISet<ISymbol> FilterOverrides(ISet<ISymbol> members, ITypeSymbol returnType)
		{
			var filteredMembers = new HashSet<ISymbol>(
				from m in members
				where m.GetReturnType ().ToString () ==  returnType.ToString ()
				select m);

			// Don't filter by return type if we would then have nothing to show.
			// This way, the user gets completion even if they speculatively typed the wrong return type
			if (filteredMembers.Count > 0)
			{
				members = filteredMembers;
			}

			return members;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:16,代码来源:OverrideContextHandler.cs

示例7: GetCollectionTypeName

        private static string GetCollectionTypeName(ITypeSymbol typeSymbol, IEnumerable<string> knownClassNames)
        {
            var namedTypeSymbol = typeSymbol as INamedTypeSymbol;
            string collectionTypeName;

            var typeArgument = namedTypeSymbol?.TypeArguments.FirstOrDefault();
            if (typeArgument == null)
            {
                // Arrays don't have type arguments, but we can pull it out manually
                var name = typeSymbol.ToString();
                collectionTypeName = name.EndsWith("[]") ? name.Substring(0, name.Length - 2) : Constants.AnyType;
            }
            else
            {
                collectionTypeName = GetType(typeArgument, knownClassNames);
            }

            return $"Array<{collectionTypeName}>";
        }
开发者ID:lukeautry,项目名称:DotNetWebSDK,代码行数:19,代码来源:TypeResolver.cs

示例8: GetSimpleTypeName

        private static string GetSimpleTypeName(
            IReadOnlyDictionary<string, ITypeSymbol> substitutions,
            IReadOnlyDictionary<string, ITypeSymbol> sutSubstitutions,
            ITypeSymbol typeSymbol)
        {
            ITypeSymbol substitution;
            ITypeSymbol sutSubstitution;

            return (substitutions.TryGetValue(typeSymbol.ToString(), out substitution)
                ? substitution
                : sutSubstitutions.TryGetValue(typeSymbol.ToString(), out sutSubstitution)
                    ? sutSubstitution
                    : typeSymbol).GetSimpleTypeName();
        }
开发者ID:ycherkes,项目名称:MockIt,代码行数:14,代码来源:ChangesMaker.cs

示例9: IsTypeAllowedToBeSend

        /// <summary>
        /// Returns true if the given type is allowed to be send
        /// through and event to another machine.
        /// </summary>
        /// <param name="type">Type</param>
        /// <returns>Boolean</returns>
        internal bool IsTypeAllowedToBeSend(ITypeSymbol type)
        {
            var typeName = type.ToString();
            if (typeName.Equals("bool") || typeName.Equals("byte") ||
                typeName.Equals("sbyte") || typeName.Equals("char") ||
                typeName.Equals("decimal") || typeName.Equals("double") ||
                typeName.Equals("float") || typeName.Equals("int") ||
                typeName.Equals("uint") || typeName.Equals("long") ||
                typeName.Equals("ulong") || typeName.Equals("short") ||
                typeName.Equals("ushort") || typeName.Equals("string") ||
                typeName.Equals("Microsoft.PSharp.Machine"))
            {
                return true;
            }

            return false;
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:23,代码来源:AnalysisContext.cs

示例10: IsMachineType

        /// <summary>
        /// Returns true if the given type symbol is a machine.
        /// Returns false if it is not.
        /// </summary>
        /// <param name="identifier">Identifier</param>
        /// <param name="model">SemanticModel</param>
        /// <returns>Boolean</returns>
        internal bool IsMachineType(ITypeSymbol typeSymbol, SemanticModel model)
        {
            if (typeSymbol != null && typeSymbol.ToString().Equals("Microsoft.PSharp.Machine"))
            {
                return true;
            }
            else
            {
                var definition = SymbolFinder.FindSourceDefinitionAsync(typeSymbol, this.Solution).Result;
                if (definition != null)
                {
                    var machineNode = definition.DeclaringSyntaxReferences.First().GetSyntax();
                    if (machineNode is ClassDeclarationSyntax)
                    {
                        NamespaceDeclarationSyntax machineNamespace = null;
                        this.TryGetNamespaceDeclarationOfSyntaxNode(
                            machineNode, out machineNamespace);
                        string machineName = machineNamespace.Name + "." + (machineNode
                            as ClassDeclarationSyntax).Identifier.ValueText;
                        foreach (var knownMachine in this.Machines)
                        {
                            NamespaceDeclarationSyntax knownMachineNamespace = null;
                            this.TryGetNamespaceDeclarationOfSyntaxNode(
                                knownMachine, out knownMachineNamespace);
                            string knownMachineName = knownMachineNamespace.Name + "." +
                                knownMachine.Identifier.ValueText;
                            if (machineName.Equals(knownMachineName))
                            {
                                return true;
                            }
                        }

                        return false;
                    }
                    else if (machineNode is VariableDeclaratorSyntax)
                    {
                        if (machineNode.FirstAncestorOrSelf<FieldDeclarationSyntax>() == null)
                        {
                            IdentifierNameSyntax machine = null;
                            if ((machineNode as VariableDeclaratorSyntax).Initializer == null)
                            {
                                machine = machineNode.Parent.DescendantNodesAndSelf().
                                    OfType<IdentifierNameSyntax>().First();
                            }
                            else
                            {
                                machine = (machineNode as VariableDeclaratorSyntax).Initializer.Value.
                                    DescendantNodesAndSelf().OfType<IdentifierNameSyntax>().First();
                            }

                            var s = model.GetSymbolInfo(machine).Symbol;
                            return s.ToString().Equals("Microsoft.PSharp.MachineState.Machine");
                        }
                    }
                }

                return false;
            }
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:66,代码来源:AnalysisContext.cs

示例11: IsWeakIdentity

		private bool IsWeakIdentity(ITypeSymbol typeSymbol)
		{
			return typeSymbol != null && (WeakIdentities.Contains(typeSymbol.ToString()) || IsWeakIdentity(typeSymbol.BaseType));
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:4,代码来源:LockingOnWeakIdentityObjectRule.cs

示例12: GetTsType

        public static string GetTsType(ITypeSymbol typeSymbol, IDictionary<string, string> mappings)
        {
            if (mappings == null)
                mappings = defaultMappings;

            if (typeSymbol is ITypeParameterSymbol)
                return typeSymbol.ToString();
            var typeWithNs = typeSymbol.ContainingNamespace + "." + typeSymbol.MetadataName;
            if (typeSymbol is IArrayTypeSymbol)
            {
                var art = (IArrayTypeSymbol)typeSymbol;
                typeWithNs = "System.Array`" + art.Rank.ToString();
                if (mappings.ContainsKey(typeWithNs))
                {
                    return mappings[typeWithNs].Replace("@@[email protected]@", GetTsType(art.ElementType, mappings));
                }
                else
                {
                    return GetTsType(art.ElementType, mappings) + string.Concat(Enumerable.Repeat("[]", art.Rank));
                }
            }
            if (typeSymbol is INamedTypeSymbol)
            {
                var nts = (INamedTypeSymbol)typeSymbol;
                if (nts.TypeArguments.Length > 0)
                {
                    string[] types = nts.TypeArguments.Select(s => GetTsType(s, mappings)).ToArray();
                    string toReturn;
                    if (mappings.ContainsKey(typeWithNs))
                    {
                        toReturn = mappings[typeWithNs];
                    }
                    else
                    {
                        toReturn = typeSymbol.ContainingNamespace + "." + typeSymbol.Name + "@@[email protected]@";
                    }

                    for (int i = 0; i < types.Length; i++)
                    {
                        toReturn = toReturn.Replace("@@T" + i.ToString() + "@@", types[i]);
                    }
                    if (toReturn.Contains("@@[email protected]@"))
                    {
                        var typeArgs = "<";
                        for (int i = 0; i < types.Length; i++)
                        {
                            if (i != 0)
                                typeArgs += ",";
                            typeArgs += types[i];
                        }
                        typeArgs += ">";
                        toReturn = toReturn.Replace("@@[email protected]@", typeArgs);
                    }
                    return toReturn;
                }
            }
            if (mappings.ContainsKey(typeWithNs))
            {
                return mappings[typeWithNs];
            }
            if (!typeSymbol.OriginalDefinition.Locations.Any(s => s.IsInSource))
                return "any";

            return typeWithNs;
        }
开发者ID:aersamkull,项目名称:TsCodeGen,代码行数:65,代码来源:TypeMapping.cs

示例13: GenericTypeName

        public static string GenericTypeName(ITypeSymbol typeSymbol)
        {
            if (typeSymbol == null)
                return null;

            var array = typeSymbol as IArrayTypeSymbol;
            if (array != null)
                return GenericTypeName(array.ElementType) + "[]";

            var named = typeSymbol as INamedTypeSymbol;

            if (named != null && named.IsGenericType && !named.IsUnboundGenericType)
                return GenericTypeName(named.ConstructUnboundGenericType());
            if (named != null && named.SpecialType != SpecialType.None)
            {
                return named.ContainingNamespace.FullNameWithDot() + named.Name;
                //this forces C# shortcuts like "int" to never be used, and instead returns System.Int32 etc.
            }
            return typeSymbol.ToString();
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:20,代码来源:TypeProcessor.cs

示例14: ConvertTypeUncached

        private static string ConvertTypeUncached(ITypeSymbol typeSymbol)
        {
            if (typeSymbol.IsAnonymousType)
                return WriteAnonymousObjectCreationExpression.TypeName(typeSymbol.As<INamedTypeSymbol>());

            var array = typeSymbol as IArrayTypeSymbol;

            if (array != null)
            {
                var typeString = TryConvertType(array.ElementType, false);
//                if (localize)
//                {
//                    var name =
//                        Context.Instance.UsingDeclarations.FirstOrDefault(
//                            k => typeString.StartsWith(k.Name.ToFullString() + ".Namespace.", StringComparison.Ordinal));
//
//                    if (name != null)
//                        typeString = typeString.RemoveFromStartOfString(name.Name.ToFullString() + ".Namespace.");
//                }
                return "Array_T!(" + typeString + ")";
            }

            if (typeSymbol.TypeKind == TypeKind.PointerType)
            {
                var pointer = typeSymbol as IPointerTypeSymbol;
                return ConvertType(pointer.PointedAtType) + "*";
            }

            var typeInfoStr = typeSymbol.ToString();

            var named = typeSymbol as INamedTypeSymbol;

            if (typeSymbol.TypeKind == TypeKind.TypeParameter)
                return  WriteIdentifierName.TransformIdentifier(typeSymbol.Name,typeSymbol);

           
            if (named != null && (named.ContainingNamespace.ToString() == "System" && named.Name == "Exception"))
                return "System.Namespace.NException";

            //TODO: Add explicit support for Nullable
            if (named != null && (named.Name == "Nullable" && named.ContainingNamespace.ToString() == "System"))
            {
                //Nullable types
                if (named.TypeArguments.Any())
                {
                    
                    string convertedType="";

                    if (named.TypeArguments.FirstOrDefault() is IErrorTypeSymbol)
                    {
                        //unbound generic 
                        convertedType = "__UNBOUND";
                    }
                    else
                    {
                        convertedType = TryConvertType(named.TypeArguments.FirstOrDefault(), false);
                    }

                   
                    return "Nullable__G!(" + convertedType + ")";
                }
            }

            var typeStr = GenericTypeName(typeSymbol);

            if (named != null && named.IsGenericType)
            {
                if(!named.IsUnboundGenericType && TypeArguments(named).Any())
                
                return GetFullGenericName(named);
                else
                {
                    return GetFullGenericName(named.OriginalDefinition);
                }
            }


            switch (typeStr)
            {
                case "System.Namespace.Void":
                    return "void";

                case "System.Namespace.Boolean":
                    return "bool";

                case "System.Object":
                case "System.Namespace.Object":
                    return "NObject";

                case "System.Namespace.UInt64":
                    return "ulong";

                case "System.Namespace.Double":
                    return "double";

                case "System.Namespace.Single":
                    return "float";

                case "System.Namespace.String":
                    return "String";
//.........这里部分代码省略.........
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:101,代码来源:TypeProcessor.cs


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