本文整理汇总了C#中ITypeReference.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeReference.Resolve方法的具体用法?C# ITypeReference.Resolve怎么用?C# ITypeReference.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeReference
的用法示例。
在下文中一共展示了ITypeReference.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Substitute
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);
}
示例2: IsPersistent
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;
}
示例3: Resolve
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;
}
示例4: Type
public TypeInfo Type(ITypeReference typeReference)
{
if (typeReference == null)
{
return null;
}
var typeDeclaration = typeReference.Resolve();
return Type(typeDeclaration);
}
示例5: AppendTypeName
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));
}
示例6: IsValueType
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;
}
示例7: IsDelegate
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;
}
示例8: Resolve
ITypeDefinition Resolve (TypeSystemService.ProjectContentWrapper dom, ITypeReference reference)
{
return reference.Resolve (dom.Compilation).GetDefinition ();
}
示例9: CreateTypeReferenceExpression
private JsTypeReferenceExpression CreateTypeReferenceExpression(ITypeReference tr) {
return new JsTypeReferenceExpression(tr.Resolve(_compilation).GetDefinition());
}
示例10: ConvertTypeReference
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("?");
}
示例11: TypeToString
string TypeToString(ITypeReference type, ITypeDefinition currentTypeDef = null)
{
var builder = CreateBuilder(currentTypeDef);
IType resolvedType = type.Resolve(ctx);
AstType node = builder.ConvertType(resolvedType);
return node.ToString();
}
示例12: IsValueType
/// <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;
}
示例13: IsEnumeration
/// <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;
}
示例14: IsDelegate
/// <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;
}
示例15: AddAdditionalType
/// <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());
}