Example #1
0
        private PExpr FindOrCreateMethod(IAccessorFrame frame, string name, out ExternalTypeHandler.IHandler handler)
        {
            handler = null;
            foreach (var m in _methods)
            {
                if (m.Name == name)
                {
                    return(frame.SetResult(m));
                }
            }
            ExternalTypeHandler type = _context.FindType(_o.GetType());

            if (type == null)
            {
                return(frame.SetError($"Unhandled type '{_o.GetType().FullName}'."));
            }
            handler = type.GetHandler(name);
            if (handler == null)
            {
                return(frame.SetError($"Missing member {name} on '{_o.GetType().FullName}'."));
            }
            if (handler.PropertyGetter == null)
            {
                var meth = new Method(this, handler);
                _methods.Add(meth);
                return(frame.SetResult(meth));
            }
            return(new PExpr());
        }
Example #2
0
 public MethodGroupHandler(ExternalTypeHandler h, string name, IEnumerable <MethodInfo> methods)
 {
     Holder   = h;
     Name     = name;
     _methods = methods
                .Select(m => new Method(m))
                .OrderBy(m => m.MinParameterCount).ThenBy(m => m.Parameters.Length)
                .GroupBy(m => m.MinParameterCount)
                .Select(g => g.First())
                .ToArray();
 }
Example #3
0
 public PropertyHandler(ExternalTypeHandler h, string name, PropertyInfo p)
 {
     Holder = h;
     Name   = name;
     PropertyOrFieldType = p.PropertyType;
     PropertyGetter      = (o, args) => p.GetValue(o, args);
     if (p.CanWrite)
     {
         PropertySetter = (o, args, value) => p.SetValue(o, value, args);
     }
 }
Example #4
0
 public PropertyHandler(ExternalTypeHandler h, string name, FieldInfo f)
 {
     Holder = h;
     Name   = name;
     PropertyOrFieldType = f.FieldType;
     PropertyGetter      = (o, args) => f.GetValue(o);
     if (!f.IsInitOnly)
     {
         PropertySetter = (o, args, value) => f.SetValue(o, value);
     }
 }
        public ExternalTypeHandler FindType(Type type)
        {
            ExternalTypeHandler t;

            if (!_types.TryGetValue(type, out t))
            {
                t = new ExternalTypeHandler(type);
                _types.Add(type, t);
            }
            return(t);
        }