Exemple #1
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;
            }
        }
Exemple #2
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));
            }
        }
        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));
            }
        }
Exemple #4
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);
        }
 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);
 }
Exemple #6
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;
     }
 }
        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));
            }
        }
Exemple #8
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));
            }
        }
Exemple #9
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;
            }
        }
 internal PointerTypeName(Type type, TypeNameFlag flags) : base(type)
 {
     ComponentType = TypeNameFactory.Create(type.GetElementType(), flags);
 }
Exemple #11
0
 public static ITypeName GetTypeFullName(this Type type, TypeNameFlag flags = TypeNameFlag.Default)
 {
     return(TypeNameFactory.Create(type, flags));
 }