Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
        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));
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 internal GenericParameterTypeName(Type type, TypeNameFlag flags) : base(type)
 {
     if (flags.Has(TypeNameFlag.OmitGenericParameter))
     {
         Name = "";
     }
     else
     {
         Name = type.Name;
     }
 }
Esempio n. 9
0
 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;
     }
 }
Esempio n. 10
0
 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];
     }
 }
Esempio n. 11
0
        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));
            }
        }
Esempio n. 12
0
        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));
            }
        }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
 internal PointerTypeName(Type type, TypeNameFlag flags) : base(type)
 {
     ComponentType = TypeNameFactory.Create(type.GetElementType(), flags);
 }
Esempio n. 15
0
 public static ITypeName GetTypeFullName(this Type type, TypeNameFlag flags = TypeNameFlag.Default)
 {
     return(TypeNameFactory.Create(type, flags));
 }
Esempio n. 16
0
 public static string GetTypeFullNameString(this Type type, TypeNameFlag flags = TypeNameFlag.Default)
 {
     return(GetTypeFullName(type, flags).ToString());
 }
Esempio n. 17
0
 public static bool Has(this TypeNameFlag flags, TypeNameFlag flag)
 {
     return((flags & flag) != 0);
 }
Esempio n. 18
0
 public static string GetDefinitionNameString(this MethodInfo method, TypeNameFlag flags = TypeNameFlag.Default)
 {
     return(GetDefinitionName(method, flags).ToString());
 }
Esempio n. 19
0
 public static IMethodName GetDefinitionFullName(this MethodInfo method, TypeNameFlag flags = TypeNameFlag.Default)
 {
     return(new MethodName(method, flags));
 }