public MethodName(MethodInfo method, TypeNameFlag flags) { Method = method; ReturnType = TypeNameFactory.Create(method.ReturnType, flags); if (!method.Name.Contains(".")) { Name = method.Name; ExplicitInterface = null; } else { var iSplit = method.Name.LastIndexOf('.'); var interfacePart = method.Name.Substring(0, iSplit); Name = method.Name.Substring(iSplit + 1); var interfaceType = method.DeclaringType.GetInterface(interfacePart); ExplicitInterface = TypeNameFactory.Create(interfaceType, flags); } Generics = new GenericList(); if (method.IsGenericMethod) { foreach (var generic in method.GetGenericArguments()) { Generics.Add(TypeNameFactory.Create(generic, flags)); } } Parameters = new ParameterList(); foreach (var parameter in method.GetParameters()) { Parameters.Add(new ParameterName(parameter, flags)); } }
internal ParameterName(ParameterInfo parameter, TypeNameFlag flags) { Parameter = parameter; TypeName = TypeNameFactory.Create(parameter.ParameterType, flags); Name = parameter.Name; if (parameter.IsOut) { Modifier = "out"; } else if (parameter.ParameterType.IsByRef) { if (!flags.Has(TypeNameFlag.ExplicitRef)) { Modifier = "ref"; } } else if (parameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0) { Modifier = "params"; } else { Modifier = null; } }
internal static TypeName Create(Type type, TypeNameFlag flags) { if (SimpleTypeName.IsSimpleType(type)) { return(new SimpleTypeName(type, flags)); } if (type.IsArray) { return(new ArrayTypeName(type, flags)); } if (type.IsGenericParameter) { return(new GenericParameterTypeName(type, flags)); } if (type.IsPointer) { return(new PointerTypeName(type, flags)); } if (type.IsByRef) { return(new RefTypeName(type, flags)); } if (type.IsGenericType) { if (type.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(new NullableTypeName(type, flags)); } return(new GenericTypeName(type, flags)); } return(new DirectTypeName(type)); }
internal TypeNameView(Type type, GenericVisitor visitor, TypeNameFlag flags) { Type = type; Generics = new GenericList(); var genericName = type.Name; var iQuota = genericName.LastIndexOf('`'); int lenGeneric; if (iQuota > 0) { Name = genericName.Substring(0, iQuota); lenGeneric = int.Parse(genericName.Substring(iQuota + 1)); } else { Name = genericName; lenGeneric = 0; } for (int i = 0; i < lenGeneric; i++) { Generics.Add(TypeNameFactory.Create(visitor.Next(), flags)); } }
public static IMethodName GetDefinitionName(this MethodInfo method, TypeNameFlag flags = TypeNameFlag.Default) { var name = new MethodName(method, flags); var filter = new NamespaceFilter(); name.FilterNamespace(filter); filter.ClearNamespace(); return(name); }
public static ITypeName GetTypeName(this Type type, TypeNameFlag flags = TypeNameFlag.Default) { var name = TypeNameFactory.Create(type, flags); var filter = new NamespaceFilter(); name.FilterNamespace(filter); filter.ClearNamespace(); return(name); }
internal ArrayTypeName(Type type, TypeNameFlag flags) : base(type) { ArrayRanks = new ArrayRankList(); while (type.IsArray) { ArrayRanks.Add(type.GetArrayRank()); type = type.GetElementType(); } ComponentType = TypeNameFactory.Create(type, flags); }
internal GenericParameterTypeName(Type type, TypeNameFlag flags) : base(type) { if (flags.Has(TypeNameFlag.OmitGenericParameter)) { Name = ""; } else { Name = type.Name; } }
internal RefTypeName(Type type, TypeNameFlag flags) : base(type) { ComponentType = TypeNameFactory.Create(type.GetElementType(), flags); if (flags.Has(TypeNameFlag.ExplicitRef)) { Sign = SignConstant.Ref; } else { Sign = null; } }
internal SimpleTypeName(Type type, TypeNameFlag flags) : base(type) { if (flags.Has(TypeNameFlag.FullPrimitive)) { Namespace = new Namespace(type.Namespace); Name = type.Name; } else { Namespace = Namespace.Empty; Name = SimpleNames[type]; } }
public GenericTypeName(Type type, TypeNameFlag flags) : base(type) { Namespace = new Namespace(type.Namespace); EnclosingNames = new EnclosingNameList(); Generics = new GenericList(); var visitor = new GenericVisitor(type); { var super = type.DeclaringType; while (super != null) { if (super.IsGenericType) { EnclosingNames.AddBefore(new TypeNameView(super, visitor, flags)); } else { EnclosingNames.AddBefore(new TypeNameView(super)); } super = super.DeclaringType; } } var genericName = type.Name; var iQuota = genericName.LastIndexOf('`'); int lenGeneric; if (iQuota > 0) { Name = iQuota < 0 ? genericName : genericName.Substring(0, iQuota); lenGeneric = int.Parse(genericName.Substring(iQuota + 1)); } else { Name = genericName; lenGeneric = 0; } for (var i = 0; i < lenGeneric; i++) { Generics.Add(TypeNameFactory.Create(visitor.Next(), flags)); } }
public MethodName(MethodInfo method, TypeNameFlag flags) { Method = method; ReturnType = TypeNameFactory.Create(method.ReturnType, flags); Name = method.Name; ExplicitInterface = null; Generics = new GenericList(); if (method.IsGenericMethod) { foreach (var generic in method.GetGenericArguments()) { Generics.Add(TypeNameFactory.Create(generic, flags)); } } Parameters = new ParameterList(); foreach (var parameter in method.GetParameters()) { Parameters.Add(new ParameterName(parameter, flags)); } }
internal NullableTypeName(Type type, TypeNameFlag flags) : base(type) { var component = type.GetGenericArguments()[0]; var componentType = TypeNameFactory.Create(component, flags); if (flags.Has(TypeNameFlag.FullNullable)) { Namespace = new Namespace(type.Namespace); BaseNames = BaseNameList.Empty; Name = nameof(Sign); Generics = new GenericList { componentType }; Sign = null; } else { Namespace = componentType.Namespace; BaseNames = componentType.BaseNames; Name = componentType.Name; Generics = GenericList.Empty; Sign = SignConstant.Nullable; } }
internal PointerTypeName(Type type, TypeNameFlag flags) : base(type) { ComponentType = TypeNameFactory.Create(type.GetElementType(), flags); }
public static ITypeName GetTypeFullName(this Type type, TypeNameFlag flags = TypeNameFlag.Default) { return(TypeNameFactory.Create(type, flags)); }
public static string GetTypeFullNameString(this Type type, TypeNameFlag flags = TypeNameFlag.Default) { return(GetTypeFullName(type, flags).ToString()); }
public static bool Has(this TypeNameFlag flags, TypeNameFlag flag) { return((flags & flag) != 0); }
public static string GetDefinitionNameString(this MethodInfo method, TypeNameFlag flags = TypeNameFlag.Default) { return(GetDefinitionName(method, flags).ToString()); }
public static IMethodName GetDefinitionFullName(this MethodInfo method, TypeNameFlag flags = TypeNameFlag.Default) { return(new MethodName(method, flags)); }