Problem With enums

Aug 22, 2013 at 7:07 AM
I have a class that contain an enum.
my class is :
    public class Student
    {
        public Student(int id,string name,StudentType type)
        {
            Id = id;
            Name = name;
            Type = type;
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public StudentType Type { get; set; }
    }
StudentType enum :
    public enum StudentType : byte
    {
        Normal=0,
        Good
    };
i create a controller class for work with list of students.
in my controller i have a method to find students by type.

this is FindByType Method:
        public IList<Student> FindByType(string type)
        {
            return _students.AsQueryable().Where("Type.ToString().StartWith(@0)", type).ToList();
        }
when i call FindByType Method i get this error in ParseMemberAccess method :
Methods on type 'Enum' are not accessible
Coordinator
Oct 7, 2013 at 1:24 PM
Unfortunately the code to bind methods dynamically is not comprehensive, I began an attempt to derive a more generic method (specifically for extension methods) but did not finish, see the UNDONE comment in the source. You will need to debug your issue using the source. Your issue will most likely occur as a result of one of the following methods.

int FindMethod(Type type, string methodName, bool staticAccess, Expression[] args, out MethodBase method) {
        BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly |
            (staticAccess ? BindingFlags.Static : BindingFlags.Instance);
        foreach (Type t in SelfAndBaseTypes(type)) {
            MemberInfo[] members = t.FindMembers(MemberTypes.Method,
                flags, Type.FilterNameIgnoreCase, methodName).ToArray();//GetExtensionMethods
            int count = FindBestMethod(members.Cast<MethodBase>(), args, out method);
            if (count != 0) return count;
        }
        method = null;
        return 0;
    }
int FindBestMethod(IEnumerable<MethodBase> methods, Expression[] args, out MethodBase method)
    {
        MethodData[] applicable = methods.
            Select(m => new MethodData { MethodBase = m, Parameters = m.GetParameters().Where(p=>p.ParameterType!=((MethodInfo)m).ReturnType ).ToArray()}).
            Where(m => IsApplicable(m, args)).
            ToArray();
        if (applicable.Length > 1) {
            applicable = applicable.
                Where(m => applicable.All(n => m == n || IsBetterThan(args, m, n))).
                ToArray();
        }
        if (applicable.Length == 1) {
            MethodData md = applicable[0];
            for (int i = 0; i < args.Length; i++) args[i] = md.Args[i];
            method = md.MethodBase;
        }
        else {
            method = null;
        }
        return applicable.Length;
    }
bool IsApplicable(MethodData method, Expression[] args) {
        if (method.Parameters.Length != args.Length) return false;
        Expression[] promotedArgs = new Expression[args.Length];
        for (int i = 0; i < args.Length; i++) {
            ParameterInfo pi = method.Parameters[i];
            if (pi.IsOut) return false;
            Expression promoted = PromoteExpression(args[i], pi.ParameterType, false);
            if (promoted == null) return false;
            promotedArgs[i] = promoted;
        }
        method.Args = promotedArgs;
        return true;
    }
Nov 24, 2014 at 7:26 AM
Hello,

Is there any progress with the above issue?