Beispiel #1
0
 public static TypeSymbolInfo[] GetTypeArguments(TypeSymbol typeSymbol)
 {
     var namedTypeSymbol = typeSymbol as INamedTypeSymbol;
     return namedTypeSymbol == null
         ? new TypeSymbolInfo[0]
         : namedTypeSymbol.TypeArguments.OfType<TypeSymbol>().Select(i => new TypeSymbolInfo(i)).ToArray();
 }
Beispiel #2
0
 private static string GetBasicTypeNameInternal(TypeSymbol type, Func<TypeSymbol, TypeSymbol> transformType)
 {
     if (transformType != null)
         type = transformType(type);
     var namedTypeSymbol = type as INamedTypeSymbol;
     if (namedTypeSymbol == null || ! namedTypeSymbol.TypeArguments.Any())
         return type.Name;
     return string.Concat(type.Name, "<",
         namedTypeSymbol.TypeArguments.OfType<TypeSymbol>()
             .Select(ta => GetBasicTypeNameInternal(ta, transformType))
             .Aggregate((t1, t2) => string.Concat(t1, ",", t2)), ">");
 }
Beispiel #3
0
 public static IEnumerable<TypeSymbolInfo> GetAllInterfaces(TypeSymbol typeSymbol)
 {
     return typeSymbol.AllInterfaces.OfType<TypeSymbol>().Select(i => new TypeSymbolInfo(i));
 }
Beispiel #4
0
 public static string GetBasicTypeName(TypeSymbol type, Func<TypeSymbol, TypeSymbol> transformType = null)
 {
     return GetBasicTypeNameInternal(type, transformType);
 }
Beispiel #5
0
 public TypeSymbolInfo(TypeSymbol typeSymbol)
 {
     _typeSymbol = typeSymbol;
     Name = typeSymbol.Name;
     FullName = typeSymbol.ToString();
     ContainingNamespace = typeSymbol.ContainingNamespace == null
         ? null
         : typeSymbol.ContainingNamespace.ToString();
     AllInterfaces = GetAllInterfaces(typeSymbol);
     TypeArguments = GetTypeArguments(typeSymbol);
 }
Beispiel #6
0
 public static TypeSymbolInfo Get(TypeSymbol typeSymbol)
 {
     return new TypeSymbolInfo(typeSymbol);
 }
        private VariableDeclarationSyntax CreateVariableDeclaration(VariableDeclaratorSyntax vbDeclarator, bool preferExplicitType,
                                                                    bool requireExplicitTypeForAll, ITypeSymbol vbInitializerType, ITypeSymbol declaredSymbolType,
                                                                    EqualsValueClauseSyntax equalsValueClauseSyntax, IMethodSymbol initSymbol, CSSyntax.VariableDeclaratorSyntax v)
        {
            var requireExplicitType = requireExplicitTypeForAll ||
                                      vbInitializerType != null && !Equals(declaredSymbolType, vbInitializerType);
            bool useVar     = equalsValueClauseSyntax != null && !preferExplicitType && !requireExplicitType;
            var  typeSyntax = initSymbol == null || !initSymbol.IsAnonymousFunction()
                ? GetTypeSyntax(declaredSymbolType, useVar)
                : GetFuncTypeSyntax(initSymbol);

            return(SyntaxFactory.VariableDeclaration(typeSyntax, SyntaxFactory.SingletonSeparatedList(v)));
        }
 IParameterHintingData IParameterHintingDataFactory.CreateDelegateDataProvider(Microsoft.CodeAnalysis.ITypeSymbol delegateType)
 {
     return(new DelegateParameterHintingData(delegateType));
 }
        internal bool IsOrleansShallowCopyable(ITypeSymbol type, HashSet <ITypeSymbol> examining)
        {
            switch (type.SpecialType)
            {
            case SpecialType.System_Boolean:
            case SpecialType.System_Char:
            case SpecialType.System_SByte:
            case SpecialType.System_Byte:
            case SpecialType.System_Int16:
            case SpecialType.System_UInt16:
            case SpecialType.System_Int32:
            case SpecialType.System_UInt32:
            case SpecialType.System_Int64:
            case SpecialType.System_UInt64:
            case SpecialType.System_Decimal:
            case SpecialType.System_Single:
            case SpecialType.System_Double:
            case SpecialType.System_String:
            case SpecialType.System_DateTime:
                return(true);
            }

            if (SymbolEqualityComparer.Default.Equals(wellKnownTypes.TimeSpan, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.IPAddress, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.IPEndPoint, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.SiloAddress, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.GrainId, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.ActivationId, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.ActivationAddress, type) ||
                wellKnownTypes.CorrelationId is WellKnownTypes.Some correlationIdType && SymbolEqualityComparer.Default.Equals(correlationIdType.Value, type) ||
                SymbolEqualityComparer.Default.Equals(wellKnownTypes.CancellationToken, type))
            {
                return(true);
            }

            if (ShallowCopyableTypes.TryGetValue(type, out var result))
            {
                return(result);
            }

            if (type.HasAttribute(wellKnownTypes.ImmutableAttribute))
            {
                return(ShallowCopyableTypes[type] = true);
            }

            if (type.HasBaseType(wellKnownTypes.Exception))
            {
                return(ShallowCopyableTypes[type] = true);
            }

            if (!(type is INamedTypeSymbol namedType))
            {
                return(ShallowCopyableTypes[type] = false);
            }

            if (namedType.IsGenericType && SymbolEqualityComparer.Default.Equals(wellKnownTypes.Immutable_1, namedType.ConstructedFrom))
            {
                return(ShallowCopyableTypes[type] = true);
            }

            if (type.TypeKind == TypeKind.Struct && !namedType.IsGenericType && !namedType.IsUnboundGenericType)
            {
                return(ShallowCopyableTypes[type] = IsValueTypeFieldsShallowCopyable(type, examining));
            }

            return(ShallowCopyableTypes[type] = false);
        }
        internal bool IsOrleansShallowCopyable(ITypeSymbol type)
        {
            var root = new HashSet <ITypeSymbol>();

            return(IsOrleansShallowCopyable(type, root));
        }
Beispiel #11
0
 public static ExpressionSyntax Literal(object o, string textForUser = null, ITypeSymbol convertedType = null) => LiteralConversions.GetLiteralExpression(o, textForUser, convertedType);