Exemplo n.º 1
0
        public void TestAccessIndexer()
        {
            IReflector r = Reflector.Bind(new ReflectSampleClass1(), ReflectorPolicy.InstancePublic);

            Assert.AreEqual(5, r.GetIndexerValue(new object[] { 5 }));

            r.SetIndexerValue(new object[] { 3 }, 4);

            var cs = r.FindAllConstructors();
        }
Exemplo n.º 2
0
        public static bool HasPublicConstructor(this Type t)
        {
            IReflector r = Reflector.Bind(t, ReflectorPolicy.CreateInstance(false, false, false, false));

            foreach (var ctor in r.FindAllConstructors())
            {
                if (ctor.IsPublic)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static bool HasDefaultConstructor(this Type t)
        {
            IReflector r = Reflector.Bind(t, ReflectorPolicy.CreateInstance(true, false, false, false));

            foreach (var ctor in r.FindAllConstructors())
            {
                if (ctor.GetParameters().Length == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        protected bool FindAvailableMethod(string method, object[] args, bool ctor)
        {
            IEnumerable <MethodBase> methods;

            if (ctor)
            {
                methods = _r.FindAllConstructors();
            }
            else
            {
                methods = _r.GetMethods(method);
            }

            foreach (MethodBase mi in methods)
            {
                ParameterInfo[] paramInfos = mi.GetParameters();
                if (!(mi.IsVarArgs() || mi.HasOptionalArgs()) && (paramInfos.Length != args.Length))
                {
                    continue;
                }

                object[] converted_args;
                bool     converted = Convert(mi, args, out converted_args);
                if (converted)
                {
                    if (_candidate != null)//Note: if already has candidate, we need mimic the C# compiler's strategy.
                    {
                        FindBetterCandidate(args, mi, converted_args);
                    }
                    else//Note: No candidate yet, record it.
                    {
                        SaveCurrentFound(mi, converted_args);
                    }
                }
            }
            return(_candidate != null);
        }