internal static ITypeReference Substitute(ITypeReference type, TypeVisitor substitution, ITypeResolveContext context) { if (substitution == null) return type; if (context != null) return type.Resolve(context).AcceptVisitor(substitution); else return SubstitutionTypeReference.Create(type, substitution); }
public override ResolveResult Resolve(CSharpResolver resolver) { object val = value; if (val is ITypeReference) { val = ((ITypeReference)val).Resolve(resolver.Context); } return(new ConstantResolveResult(type.Resolve(resolver.Context), val)); }
public TypeInfo Type(ITypeReference typeReference) { if (typeReference == null) { return(null); } var typeDeclaration = typeReference.Resolve(); return(Type(typeDeclaration)); }
/// <summary> /// Resolves a type reference in the compilation's main type resolve context. /// Some type references require a more specific type resolve context and will not resolve using this method. /// </summary> /// <returns> /// Returns the resolved type. /// In case of an error, returns <see cref="SpecialType.UnknownType"/>. /// Never returns null. /// </returns> public static IType Resolve(this ITypeReference reference, ICompilation compilation) { if (reference == null) { throw new ArgumentNullException("reference"); } if (compilation == null) { throw new ArgumentNullException("compilation"); } return(reference.Resolve(compilation.TypeResolveContext)); }
public static bool IsValueType(ITypeReference value) { ITypeDeclaration typeDeclaration = value?.Resolve(); if (typeDeclaration == null) { return(false); } ITypeReference baseType = typeDeclaration.BaseType; return(baseType != null && (baseType.Name == "ValueType" || baseType.Name == "Enum") && baseType.Namespace == "System"); }
private void ComputeModule(IModule module) { int abstracts = 0; int eCoupling = 0; int aCoupling = 0; foreach (IType type in module.Types) { if (!this.IsAbortPending()) { this.OnProgress(new ComputationProgressEventArgs(currentCount++, this.stepCount)); ITypeReference typeReference = type as ITypeReference; if (typeReference != null) { ITypeDeclaration typeDeclaration = typeReference.Resolve(); if (typeDeclaration != null) { if (typeDeclaration.Abstract || typeDeclaration.Interface) { abstracts++; } if (IsEfferent(module, typeDeclaration)) { eCoupling++; } if (IsAfferent(module, typeDeclaration)) { aCoupling++; } } } } } double abstractness = abstracts / (double)module.Types.Count; double instability = 0; if (eCoupling + aCoupling > 0) { instability = eCoupling / (double)(eCoupling + aCoupling); } double distance = Math.Abs((abstractness + instability - 1) / 2.0); string location = Environment.ExpandEnvironmentVariables(module.Location); int fileSize = (File.Exists(location)) ? (int)new FileInfo(location).Length : 0; this.AddRow(module, fileSize, module.Types.Count, abstracts, eCoupling, aCoupling, abstractness, instability, distance); }
public IMember Resolve(ITypeResolveContext context) { IType declaringType = declaringTypeReference.Resolve(context); foreach (var member in declaringType.GetMembers(CanMatch, GetMemberOptions.IgnoreInheritedMembers)) { if (IdStringProvider.GetIdString(member) == memberIdString) { return(member); } } return(null); }
public IMember Resolve(ITypeResolveContext context) { IType type = typeReference.Resolve(context); IEnumerable <IMember> members; if (entityType == EntityType.Method) { members = type.GetMethods( m => m.Name == name && m.EntityType == EntityType.Method && m.TypeParameters.Count == typeParameterCount && !m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); } else { members = type.GetMembers( m => m.Name == name && m.EntityType == entityType && !m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); } var resolvedParameterTypes = parameterTypes.Resolve(context); foreach (IMember member in members) { IParameterizedMember parameterizedMember = member as IParameterizedMember; if (parameterizedMember == null) { if (parameterTypes.Count == 0) { return(member); } } else if (parameterTypes.Count == parameterizedMember.Parameters.Count) { bool signatureMatches = true; for (int i = 0; i < parameterTypes.Count; i++) { IType type1 = DummyTypeParameter.NormalizeAllTypeParameters(resolvedParameterTypes[i]); IType type2 = DummyTypeParameter.NormalizeAllTypeParameters(parameterizedMember.Parameters[i].Type); if (!type1.Equals(type2)) { signatureMatches = false; break; } } if (signatureMatches) { return(member); } } } return(null); }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult rr; if (targetType != null) { rr = new TypeResolveResult(targetType.Resolve(resolver.Context)); } else { rr = targetExpression.Resolve(resolver); } return(resolver.ResolveMemberAccess(rr, memberName, ConstantIdentifierReference.ResolveTypes(resolver, typeArguments))); }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult rr; if (targetType != null) { rr = new TypeResolveResult(targetType.Resolve(resolver.CurrentTypeResolveContext)); } else { rr = targetExpression.Resolve(resolver); } return(resolver.ResolveMemberAccess(rr, memberName, typeArguments.Resolve(resolver.CurrentTypeResolveContext))); }
public static bool IsVisible(IType value, IVisibilityConfiguration visibility) { ITypeReference typeReference = value as ITypeReference; if (typeReference != null) { ITypeReference declaringType = typeReference.Owner as ITypeReference; if (declaringType != null) { if (!Helper.IsVisible(declaringType, visibility)) { return(false); } } ITypeDeclaration typeDeclaration = typeReference.Resolve(); if (typeDeclaration == null) { return(true); } switch (typeDeclaration.Visibility) { case TypeVisibility.Public: case TypeVisibility.NestedPublic: return(visibility.Public); case TypeVisibility.Private: case TypeVisibility.NestedPrivate: return(visibility.Private); case TypeVisibility.NestedFamilyOrAssembly: return(visibility.FamilyOrAssembly); case TypeVisibility.NestedFamily: return(visibility.Family); case TypeVisibility.NestedFamilyAndAssembly: return(visibility.FamilyAndAssembly); case TypeVisibility.NestedAssembly: return(visibility.Assembly); default: throw new NotImplementedException(); } } throw new NotSupportedException(); }
public IType Resolve(ITypeResolveContext context) { // If both types exist, C# considers that to be an ambiguity, but we are less strict. IType type = withoutSuffix.Resolve(context); if (type == SharedTypes.UnknownType) { return(withSuffix.Resolve(context)); } else { return(type); } }
public bool IsValueType(ITypeReference value) { if (value != null) { ITypeDeclaration declaration = value.Resolve(); if (declaration == null) { return(false); } ITypeReference baseType = declaration.BaseType; return(((baseType != null) && ((baseType.Name == "ValueType") || (baseType.Name == "Enum"))) && (baseType.Namespace == "System")); } return(false); }
public IMember Resolve(ITypeResolveContext context) { IType declaringType = typeReference.Resolve(context); IMember interfaceMember = interfaceMemberReference.Resolve(context.WithCurrentTypeDefinition(declaringType.GetDefinition())); if (interfaceMember == null) { return(null); } var members = declaringType.GetMembers( m => m.EntityType == interfaceMember.EntityType && m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); return(members.FirstOrDefault(m => m.ImplementedInterfaceMembers.Count == 1 && interfaceMember.Equals(m.ImplementedInterfaceMembers[0]))); }
public override ResolveResult Resolve(CSharpResolver resolver) { var type = targetType.Resolve(resolver.CurrentTypeResolveContext); var resolveResult = expression.Resolve(resolver); if (allowNullableConstants && NullableType.IsNullable(type)) { resolveResult = resolver.ResolveCast(NullableType.GetUnderlyingType(type), resolveResult); if (resolveResult.IsCompileTimeConstant) { return(new ConstantResolveResult(type, resolveResult.ConstantValue)); } } return(resolver.ResolveCast(type, resolveResult)); }
IType ReadType() { string typeName = ReadSerString(); ITypeReference typeReference = ReflectionHelper.ParseReflectionName(typeName); IType typeInCurrentAssembly = typeReference.Resolve(new SimpleTypeResolveContext(currentResolvedAssembly)); if (typeInCurrentAssembly.Kind != TypeKind.Unknown) { return(typeInCurrentAssembly); } // look for the type in mscorlib ITypeDefinition systemObject = currentResolvedAssembly.Compilation.FindType(KnownTypeCode.Object).GetDefinition(); if (systemObject != null) { return(typeReference.Resolve(new SimpleTypeResolveContext(systemObject.ParentAssembly))); } else { // couldn't find corlib - return the unknown IType for the current assembly return(typeInCurrentAssembly); } }
public IMember Resolve(ITypeResolveContext context) { IMember interfaceMember = interfaceMemberReference.Resolve(context); if (interfaceMember == null) { return(null); } IType type = typeReference.Resolve(context); var members = type.GetMembers( m => m.EntityType == interfaceMember.EntityType && m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); return(members.FirstOrDefault(m => m.InterfaceImplementations.Count == 1 && interfaceMember.Equals(m.InterfaceImplementations[0]))); }
internal static ITypeReference Substitute(ITypeReference type, TypeVisitor substitution, ITypeResolveContext context) { if (substitution == null) { return(type); } if (context != null) { return(type.Resolve(context).AcceptVisitor(substitution)); } else { return(SubstitutionTypeReference.Create(type, substitution)); } }
public IType Resolve(ITypeResolveContext context) { if (declaringTypeRef.Resolve(context) is ITypeDefinition declaringType) { int tpc = declaringType.TypeParameterCount; foreach (IType type in declaringType.NestedTypes) { if (type.Name == name && type.TypeParameterCount == tpc + additionalTypeParameterCount) { return(type); } } } return(new UnknownType(null, name, additionalTypeParameterCount)); }
public override void Complete(CompletionContext context) { var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None); var delegateType = delegateTypeReference.Resolve(refactoringContext.Compilation); var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single(); var builder = refactoringContext.CreateTypeSystemAstBuilder(); var throwStatement = new ThrowStatement(); var decl = new MethodDeclaration { ReturnType = refactoringContext.CreateShortType(invokeSignature.ReturnType), Name = handlerName, Body = new BlockStatement { throwStatement } }; decl.Parameters.AddRange(invokeSignature.Parameters.Select(builder.ConvertParameter)); if (isStatic) { decl.Modifiers |= Modifiers.Static; } throwStatement.Expression = new ObjectCreateExpression(refactoringContext.CreateShortType("System", "NotImplementedException")); // begin insertion using (context.Editor.Document.OpenUndoGroup()) { context.Editor.Document.Replace(context.StartOffset, context.Length, handlerName + ";"); context.EndOffset = context.StartOffset + handlerName.Length; var loc = context.Editor.Document.GetLocation(context.StartOffset + handlerName.Length / 2 + 1); var parseInfo = SD.ParserService.Parse(context.Editor.FileName, context.Editor.Document) as CSharpFullParseInformation; if (parseInfo == null) { return; } using (var script = refactoringContext.StartScript()) { var node = parseInfo.SyntaxTree.GetNodeAt(loc, n => n is Identifier || n is IdentifierExpression); if (node == null) { return; } script.InsertWithCursor(this.DisplayText, Script.InsertPosition.Before, decl) .ContinueScript(() => script.Link(decl.NameToken, node).ContinueScript(() => script.Select(throwStatement))); } } }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult[] elements = new ResolveResult[arrayElements.Count]; for (int i = 0; i < elements.Length; i++) { elements[i] = arrayElements[i].Resolve(resolver); } if (elementType != null) { return(resolver.ResolveArrayCreation(elementType.Resolve(resolver.CurrentTypeResolveContext), 1, null, elements)); } else { return(resolver.ResolveArrayCreation(null, 1, null, elements)); } }
public IMember Resolve(ITypeResolveContext context) { var declaringType = declaringTypeReference.Resolve(context); var memberDefinition = memberDefinitionReference.Resolve(context); IType[] typeArguments = null; if (typeArgumentReferences != null) { typeArguments = new IType[typeArgumentReferences.Count]; for (int i = 0; i < typeArguments.Length; i++) { typeArguments[i] = typeArgumentReferences[i].Resolve(context); } } return(CreateSpecializedMember(declaringType, memberDefinition, typeArguments)); }
public IType Resolve(ITypeResolveContext context) { ITypeDefinition declaringType = declaringTypeRef.Resolve(context) as ITypeDefinition; if (declaringType != null) { int tpc = declaringType.TypeParameterCount; foreach (IType type in declaringType.NestedTypes) { if (type.Name == name && type.TypeParameterCount == tpc + additionalTypeParameterCount) { return(type); } } } return(SharedTypes.UnknownType); }
public static bool IsEnumeration(ITypeReference value) { if (value != null) { ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return(false); } // TODO ITypeReference baseType = typeDeclaration.BaseType; return((baseType != null) && (baseType.Name == "Enum") && (baseType.Namespace == "System")); } return(false); }
public IMethod ResolveConstructor(ITypeResolveContext context) { IType[] parameterTypes = null; if (constructorParameterTypes != null && constructorParameterTypes.Length > 0) { parameterTypes = new IType[constructorParameterTypes.Length]; for (int i = 0; i < parameterTypes.Length; i++) { parameterTypes[i] = constructorParameterTypes[i].Resolve(context); } } IMethod bestMatch = null; foreach (IMethod ctor in attributeType.Resolve(context).GetConstructors(context)) { if (ctor.IsStatic) { continue; } if (parameterTypes == null) { if (ctor.Parameters.Count == 0) { return(ctor); } } else if (ctor.Parameters.Count == parameterTypes.Length) { bestMatch = ctor; bool ok = true; for (int i = 0; i < parameterTypes.Length; i++) { if (ctor.Parameters[i].Type != parameterTypes[i]) { ok = false; break; } } if (ok) { return(ctor); } } } return(bestMatch); }
public bool IsDelegate(ITypeReference value) { if (value != null) { if ((value.Name == "MulticastDelegate") && (value.Namespace == "System")) { return(false); } ITypeDeclaration declaration = value.Resolve(); if (declaration == null) { return(false); } ITypeReference baseType = declaration.BaseType; return((((baseType != null) && (baseType.Namespace == "System")) && ((baseType.Name == "MulticastDelegate") || (baseType.Name == "Delegate"))) && (baseType.Namespace == "System")); } return(false); }
public static bool IsTestMethod(IMethod method) { if (method == null || method.SymbolKind != SymbolKind.Method) { return(false); } var testAttribute = testAttributeRef.Resolve(method.Compilation); var testCaseAttribute = testCaseAttributeRef.Resolve(method.Compilation); foreach (var attr in method.Attributes) { if (attr.AttributeType.Equals(testAttribute) || attr.AttributeType.Equals(testCaseAttribute)) { return(true); } } return(false); }
public IType Resolve(ITypeResolveContext context) { // If both types exist, C# considers that to be an ambiguity, but we are less strict. IType type = withoutSuffix.Resolve(context); var attrType = context.GetTypeDefinition(typeof(System.Attribute)); if (attrType == null) { return(SharedTypes.UnknownType); } if (type.GetDefinition() == null || !type.GetDefinition().IsDerivedFrom(attrType, context)) { type = withSuffix.Resolve(context); } return(type); }
public static bool IsVisible(IType value, IVisibilityConfiguration visibility) { ITypeReference reference = value as ITypeReference; if (reference == null) { throw new NotSupportedException(); } ITypeReference owner = reference.Owner as ITypeReference; if ((owner != null) && !IsVisible(owner, visibility)) { return(false); } ITypeDeclaration declaration = reference.Resolve(); if (declaration == null) { return(true); } switch (declaration.Visibility) { case TypeVisibility.Private: case TypeVisibility.NestedPrivate: return(visibility.Private); case TypeVisibility.Public: case TypeVisibility.NestedPublic: return(visibility.Public); case TypeVisibility.NestedFamily: return(visibility.Family); case TypeVisibility.NestedAssembly: return(visibility.Assembly); case TypeVisibility.NestedFamilyAndAssembly: return(visibility.FamilyAndAssembly); case TypeVisibility.NestedFamilyOrAssembly: return(visibility.FamilyOrAssembly); } throw new NotImplementedException(); }
public static bool IsDelegate(ITypeReference value) { if (value == null) { return(false); } if (value.Name == "MulticastDelegate" && value.Namespace == "System") { return(false); } ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return(false); } ITypeReference baseType = typeDeclaration.BaseType; return(baseType != null && baseType.Namespace == "System" && (baseType.Name == "MulticastDelegate" || baseType.Name == "Delegate") && baseType.Namespace == "System"); }
bool IsPersistent(ITypeReference type) { while (type != null) { ITypeDeclaration decl = type.Resolve(); if (decl != null) { if (decl.Namespace == "Perst" && decl.Name == "Persistent") { return true; } type = decl.BaseType; } else { break; } } return false; }
bool IsPersistent(ITypeReference type) { while (type != null) { ITypeDeclaration decl = type.Resolve(); if (decl != null) { if (decl.Namespace == "Perst" && decl.Name == "Persistent") { return(true); } type = decl.BaseType; } else { break; } } return(false); }
/// <summary> /// Adds the type of the additional. /// </summary> /// <param name="typeReference">The type reference.</param> private void AddAdditionalType(ITypeReference typeReference) { if (this.TypeDataList.Find(typeInfo => string.Compare(typeInfo.TypeName, typeReference.Name, StringComparison.Ordinal) == 0) != null) { // Type already added Logger.Current.Info("The type is already in the additional list..." + typeReference.ToString()); return; } this.AdditionalLoadList.Add(typeReference.Resolve()); }
static void AppendTypeName(StringBuilder b, ITypeReference type, ITypeResolveContext context) { IType resolvedType = type as IType; if (resolvedType != null) { AppendTypeName(b, resolvedType); return; } GetClassTypeReference gctr = type as GetClassTypeReference; if (gctr != null) { if (!string.IsNullOrEmpty(gctr.Namespace)) { b.Append(gctr.Namespace); b.Append('.'); } b.Append(gctr.Name); if (gctr.TypeParameterCount > 0) { b.Append('`'); b.Append(gctr.TypeParameterCount); } return; } NestedTypeReference ntr = type as NestedTypeReference; if (ntr != null) { AppendTypeName(b, ntr.DeclaringTypeReference, context); b.Append('.'); b.Append(ntr.Name); if (ntr.AdditionalTypeParameterCount > 0) { b.Append('`'); b.Append(ntr.AdditionalTypeParameterCount); } return; } ParameterizedTypeReference pt = type as ParameterizedTypeReference; if (pt != null && IsGetClassTypeReference(pt.GenericType)) { AppendParameterizedTypeName(b, pt.GenericType, pt.TypeArguments, context); return; } ArrayTypeReference array = type as ArrayTypeReference; if (array != null) { AppendTypeName(b, array.ElementType, context); b.Append('['); if (array.Dimensions > 1) { for (int i = 0; i < array.Dimensions; i++) { if (i > 0) b.Append(','); b.Append("0:"); } } b.Append(']'); return; } PointerTypeReference ptr = type as PointerTypeReference; if (ptr != null) { AppendTypeName(b, ptr.ElementType, context); b.Append('*'); return; } ByReferenceTypeReference brtr = type as ByReferenceTypeReference; if (brtr != null) { AppendTypeName(b, brtr.ElementType, context); b.Append('@'); return; } if (context == null) b.Append('?'); else AppendTypeName(b, type.Resolve(context)); }
public static IMember Resolve(ITypeResolveContext context, EntityType entityType, string name, ITypeReference explicitInterfaceTypeReference = null, IList<string> typeParameterNames = null, IList<ITypeReference> parameterTypeReferences = null) { if (context.CurrentTypeDefinition == null) return null; if (parameterTypeReferences == null) parameterTypeReferences = EmptyList<ITypeReference>.Instance; if (typeParameterNames == null || typeParameterNames.Count == 0) { // non-generic member // In this case, we can simply resolve the parameter types in the given context var parameterTypes = parameterTypeReferences.Resolve(context); if (explicitInterfaceTypeReference == null) { foreach (IMember member in context.CurrentTypeDefinition.Members) { if (member.IsExplicitInterfaceImplementation) continue; if (IsNonGenericMatch(member, entityType, name, parameterTypes)) return member; } } else { IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(context); foreach (IMember member in context.CurrentTypeDefinition.Members) { if (!member.IsExplicitInterfaceImplementation) continue; if (member.ImplementedInterfaceMembers.Count != 1) continue; if (IsNonGenericMatch(member, entityType, name, parameterTypes)) { if (explicitInterfaceType.Equals(member.ImplementedInterfaceMembers[0].DeclaringType)) return member; } } } } else { // generic member // In this case, we must specify the correct context for resolving the parameter types foreach (IMethod method in context.CurrentTypeDefinition.Methods) { if (method.EntityType != entityType) continue; if (method.Name != name) continue; if (method.Parameters.Count != parameterTypeReferences.Count) continue; // Compare type parameter count and names: if (!typeParameterNames.SequenceEqual(method.TypeParameters.Select(tp => tp.Name))) continue; // Once we know the type parameter names are fitting, we can resolve the // type references in the context of the method: var contextForMethod = context.WithCurrentMember(method); var parameterTypes = parameterTypeReferences.Resolve(contextForMethod); if (!IsParameterTypeMatch(method, parameterTypes)) continue; if (explicitInterfaceTypeReference == null) { if (!method.IsExplicitInterfaceImplementation) return method; } else if (method.IsExplicitInterfaceImplementation && method.ImplementedInterfaceMembers.Count == 1) { IType explicitInterfaceType = explicitInterfaceTypeReference.Resolve(contextForMethod); if (explicitInterfaceType.Equals(method.ImplementedInterfaceMembers[0].DeclaringType)) return method; } } } return null; }
/// <summary> /// Determines whether the specified value is delegate. /// </summary> /// <param name="value">The type reference value.</param> /// <returns> /// <c>true</c> if the specified value is delegate; otherwise, <c>false</c>. /// </returns> internal static bool IsDelegate(ITypeReference value) { if (value != null) { if ((value.Name == "MulticastDelegate") && (value.Namespace == "System")) { return false; } ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return false; } ITypeReference baseType = typeDeclaration.BaseType; return baseType != null && baseType.Namespace == "System" && (baseType.Name == "MulticastDelegate" || baseType.Name == "Delegate"); } return false; }
/// <summary> /// Determines whether the specified value is enumeration. /// </summary> /// <param name="value">The type reference value.</param> /// <returns> /// <c>true</c> if the specified value is enumeration; otherwise, <c>false</c>. /// </returns> internal static bool IsEnumeration(ITypeReference value) { if (value != null) { ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return false; } ITypeReference baseType = typeDeclaration.BaseType; return baseType != null && baseType.Name == "Enum" && baseType.Namespace == "System"; } return false; }
public TypeInfo Type(ITypeReference typeReference) { if (typeReference == null) { return null; } var typeDeclaration = typeReference.Resolve(); return Type(typeDeclaration); }
string TypeToString(ITypeReference type, ITypeDefinition currentTypeDef = null) { var builder = CreateBuilder(currentTypeDef); IType resolvedType = type.Resolve(ctx); AstType node = builder.ConvertType(resolvedType); return node.ToString(); }
/// <summary> /// Determines whether the specified value is a value type. /// </summary> /// <param name="value">The type reference value.</param> /// <returns> /// <c>true</c> if the specified value is a value type; otherwise, <c>false</c>. /// </returns> internal static bool IsValueType(ITypeReference value) { if (value != null) { ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return false; } return typeDeclaration.ValueType; } return false; }
public AstType ConvertTypeReference(ITypeReference typeRef) { ArrayTypeReference array = typeRef as ArrayTypeReference; if (array != null) { return ConvertTypeReference(array.ElementType).MakeArrayType(array.Dimensions); } PointerTypeReference pointer = typeRef as PointerTypeReference; if (pointer != null) { return ConvertTypeReference(pointer.ElementType).MakePointerType(); } ByReferenceType brt = typeRef as ByReferenceType; if (brt != null) { return ConvertTypeReference(brt.ElementType); } IType type = typeRef.Resolve(context); if (type.Kind != TypeKind.Unknown) return ConvertType(type); // Unknown type, let's try if we can find an appropriate type // (anything is better than displaying a question mark) KnownTypeReference knownType = typeRef as KnownTypeReference; if (knownType != null) { string keyword = ReflectionHelper.GetCSharpNameByTypeCode(knownType.TypeCode); if (keyword != null) return new PrimitiveType(keyword); } SimpleTypeOrNamespaceReference str = typeRef as SimpleTypeOrNamespaceReference; if (str != null) { return new SimpleType(str.Identifier, str.TypeArguments.Select(ConvertTypeReference)); } MemberTypeOrNamespaceReference mtr = typeRef as MemberTypeOrNamespaceReference; if (mtr != null) { return new MemberType(ConvertTypeReference(mtr.Target), mtr.Identifier, mtr.TypeArguments.Select(ConvertTypeReference)) { IsDoubleColon = mtr.Target is AliasNamespaceReference }; } AliasNamespaceReference alias = typeRef as AliasNamespaceReference; if (alias != null) { return new SimpleType(alias.Identifier); } // Unknown type reference that couldn't be resolved return new SimpleType("?"); }
private JsTypeReferenceExpression CreateTypeReferenceExpression(ITypeReference tr) { return new JsTypeReferenceExpression(tr.Resolve(_compilation).GetDefinition()); }
ITypeDefinition Resolve (TypeSystemService.ProjectContentWrapper dom, ITypeReference reference) { return reference.Resolve (dom.Compilation).GetDefinition (); }
public static bool IsDelegate(ITypeReference value) { if (value != null) { // TODO if ((value.Name == "MulticastDelegate") && (value.Namespace == "System")) { return false; } ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return false; } ITypeReference baseType = typeDeclaration.BaseType; return ((baseType != null) && (baseType.Namespace == "System") && ((baseType.Name == "MulticastDelegate") || (baseType.Name == "Delegate")) && (baseType.Namespace == "System")); } return false; }
public static bool IsValueType(ITypeReference value) { if (value != null) { ITypeDeclaration typeDeclaration = value.Resolve(); if (typeDeclaration == null) { return false; } // TODO ITypeReference baseType = typeDeclaration.BaseType; return ((baseType != null) && ((baseType.Name == "ValueType") || (baseType.Name == "Enum")) && (baseType.Namespace == "System")); } return false; }