alielie
2026-09-10 f3889f2d36c50cf99468594854def9b7ed069fb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DynamicExpresso.Reflection;
using DynamicExpresso.Resources;
 
namespace DynamicExpresso
{
    public class ReferenceType
    {
        public Type Type { get; private set; }
 
        /// <summary>
        /// Public name that must be used in the expression.
        /// </summary>
        public string Name { get; private set; }
 
        public IList<MethodInfo> ExtensionMethods { get; private set; }
 
        public ReferenceType(string name, Type type)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException(nameof(name));
 
            if (type == null)
                throw new ArgumentNullException(nameof(type));
 
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                var genericType = type.GetGenericTypeDefinition();
                var genericTypeName = genericType.Name.Substring(0, genericType.Name.IndexOf('`'));
                genericTypeName += $"<{new string(',', genericType.GetGenericArguments().Length - 1)}>";
                throw new ArgumentException(string.Format(ErrorMessages.GenericTypeReference, genericTypeName));
            }
 
            Type = type;
            Name = name;
            ExtensionMethods = ReflectionExtensions.GetExtensionMethods(type).ToList();
        }
 
        public ReferenceType(Type type)
        {
            if (type == null)
                throw new ArgumentNullException(nameof(type));
 
            Type = type;
            Name = type.Name;
            ExtensionMethods = ReflectionExtensions.GetExtensionMethods(type).ToList();
        }
    }
}