private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { #if NO_SYSTEM_REFLECTION_EMIT switch (gos) { case SetOrGet.Get: return((target, args) => field.GetValue(target)); case SetOrGet.Set: return((target, args) => { var value = args[0]; field.SetValue(target, RuntimeServices.Coerce(value, field.FieldType)); return value; }); default: throw new ArgumentException(); } #else return(SetOrGet.Get == gos ? new Emitters.GetFieldEmitter(field).Emit() : new Emitters.SetFieldEmitter(field, GetArgumentTypes()[0]).Emit()); #endif }
private Dispatcher Create(SetOrGet gos) { MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property|MemberTypes.Field, RuntimeServices.DefaultBindingFlags); if (candidates.Length == 0) return FindExtension(GetCandidateExtensions(gos)); if (candidates.Length > 1) throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); return EmitDispatcherFor(candidates[0], gos); }
private IEnumerable<MethodInfo> GetCandidateExtensions(SetOrGet gos) { foreach (PropertyInfo p in GetExtensions<PropertyInfo>(MemberTypes.Property)) { MethodInfo m = Accessor(p, gos); if (null == m) continue; yield return m; } }
private Dispatcher EmitDispatcherFor(MemberInfo info, SetOrGet gos) { switch (info.MemberType) { case MemberTypes.Property: return EmitPropertyDispatcher((PropertyInfo) info, gos); default: return EmitFieldDispatcher((FieldInfo) info, gos); } }
private Dispatcher EmitDispatcherFor(MemberInfo info, SetOrGet gos) { switch (info.MemberType) { case MemberTypes.Property: return(EmitPropertyDispatcher((PropertyInfo)info, gos)); default: return(EmitFieldDispatcher((FieldInfo)info, gos)); } }
private IEnumerable <MethodInfo> GetCandidateExtensions(SetOrGet gos) { foreach (PropertyInfo p in GetExtensions <PropertyInfo>(MemberTypes.Property)) { MethodInfo m = Accessor(p, gos); if (null == m) { continue; } yield return(m); } }
private Dispatcher Create(SetOrGet gos) { MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property | MemberTypes.Field, RuntimeServices.DefaultBindingFlags); if (candidates.Length == 0) { return(FindExtension(GetCandidateExtensions(gos))); } if (candidates.Length > 1) { throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); } return(EmitDispatcherFor(candidates[0], gos)); }
private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { #if NO_SYSTEM_REFLECTION_EMIT return(ReflectionBasedFieldDispatcherFor(field, gos)); #else if (field.IsLiteral) { return(ReflectionBasedFieldDispatcherFor(field, gos)); } return(SetOrGet.Get == gos ? new Emitters.GetFieldEmitter(field).Emit() : new Emitters.SetFieldEmitter(field, GetArgumentTypes()[0]).Emit()); #endif }
private Dispatcher Create(SetOrGet gos) { #if !DNXCORE50 MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property | MemberTypes.Field, RuntimeServices.DefaultBindingFlags); #else MemberInfo[] candidates = _type.GetMember(_name, RuntimeServices.DefaultBindingFlags); candidates = candidates.Where((v) => v.MemberType == MemberTypes.Property || v.MemberType == MemberTypes.Field).ToArray(); #endif if (candidates.Length == 0) { return(FindExtension(GetCandidateExtensions(gos))); } if (candidates.Length > 1) { throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); } return(EmitDispatcherFor(candidates[0], gos)); }
static Dispatcher ReflectionBasedFieldDispatcherFor(FieldInfo field, SetOrGet gos) { switch (gos) { case SetOrGet.Get: return((target, args) => field.GetValue(target)); case SetOrGet.Set: return((target, args) => { var value = args[0]; field.SetValue(target, RuntimeServices.Coerce(value, field.FieldType)); return value; }); default: throw new ArgumentException(); } }
private Dispatcher EmitPropertyDispatcher(PropertyInfo property, SetOrGet gos) { Type[] argumentTypes = GetArgumentTypes(); MethodInfo accessor = Accessor(property, gos); if (null == accessor) { throw MissingField(); } CandidateMethod found = ResolveMethod(argumentTypes, new MethodInfo[] { accessor }); if (null == found) { throw MissingField(); } #if NO_SYSTEM_REFLECTION_EMIT switch (gos) { case SetOrGet.Get: return((target, args) => property.GetValue(target, args)); case SetOrGet.Set: return((target, args) => { var value = args[args.Length - 1]; var remainingArgs = new object[args.Length - 1]; Array.Copy(args, remainingArgs, remainingArgs.Length); property.SetValue(target, RuntimeServices.Coerce(value, property.PropertyType), remainingArgs); return value; }); default: throw new ArgumentException(); } #else if (SetOrGet.Get == gos) { return(new Emitters.MethodDispatcherEmitter(_type, found, argumentTypes).Emit()); } return(new Emitters.SetPropertyEmitter(_type, found, argumentTypes).Emit()); #endif }
private Dispatcher EmitPropertyDispatcher(PropertyInfo property, SetOrGet gos) { Type[] argumentTypes = GetArgumentTypes(); MethodInfo accessor = Accessor(property, gos); if (null == accessor) { throw MissingField(); } CandidateMethod found = ResolveMethod(argumentTypes, new MethodInfo[] { accessor }); if (null == found) { throw MissingField(); } if (SetOrGet.Get == gos) { return(new MethodDispatcherEmitter(_type, found, argumentTypes).Emit()); } return(new SetPropertyEmitter(_type, found, argumentTypes).Emit()); }
private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { #if NO_SYSTEM_REFLECTION_EMIT switch (gos) { case SetOrGet.Get: return (target, args) => field.GetValue(target); case SetOrGet.Set: return (target, args) => { var value = args[0]; field.SetValue(target, RuntimeServices.Coerce(value, field.FieldType)); return value; }; default: throw new ArgumentException(); } #else return SetOrGet.Get == gos ? new Emitters.GetFieldEmitter(field).Emit() : new Emitters.SetFieldEmitter(field, GetArgumentTypes()[0]).Emit(); #endif }
private Dispatcher EmitPropertyDispatcher(PropertyInfo property, SetOrGet gos) { Type[] argumentTypes = GetArgumentTypes(); MethodInfo accessor = Accessor(property, gos); if (null == accessor) throw MissingField(); CandidateMethod found = ResolveMethod(argumentTypes, new MethodInfo[] { accessor }); if (null == found) throw MissingField(); if (SetOrGet.Get == gos) return new MethodDispatcherEmitter(_type, found, argumentTypes).Emit(); return new SetPropertyEmitter(_type, found, argumentTypes).Emit(); }
private static MethodInfo Accessor(PropertyInfo p, SetOrGet gos) { return(gos == SetOrGet.Get ? p.GetGetMethod(true) : p.GetSetMethod(true)); }
private Dispatcher EmitPropertyDispatcher(PropertyInfo property, SetOrGet gos) { Type[] argumentTypes = GetArgumentTypes(); MethodInfo accessor = Accessor(property, gos); if (null == accessor) throw MissingField(); CandidateMethod found = ResolveMethod(argumentTypes, new MethodInfo[] { accessor }); if (null == found) throw MissingField(); #if NO_SYSTEM_REFLECTION_EMIT switch (gos) { case SetOrGet.Get: return (target, args) => property.GetValue(target, args); case SetOrGet.Set: return (target, args) => { var value = args[args.Length - 1]; property.SetValue(target, RuntimeServices.Coerce(value, property.PropertyType), args.Take(args.Length - 1).ToArray()); return value; }; default: throw new ArgumentException(); } #else if (SetOrGet.Get == gos) return new Emitters.MethodDispatcherEmitter(_type, found, argumentTypes).Emit(); return new Emitters.SetPropertyEmitter(_type, found, argumentTypes).Emit(); #endif }
private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { #if NO_SYSTEM_REFLECTION_EMIT return ReflectionBasedFieldDispatcherFor(field, gos); #else if (field.IsLiteral) return ReflectionBasedFieldDispatcherFor(field, gos); return SetOrGet.Get == gos ? new Emitters.GetFieldEmitter(field).Emit() : new Emitters.SetFieldEmitter(field, GetArgumentTypes()[0]).Emit(); #endif }
private static MemberInfo SelectSliceMember(MemberInfo[] found, ref object[] args, SetOrGet sliceKind) { if (1 == found.Length) return found[0]; MethodBase[] candidates = new MethodBase[found.Length]; for(int i = 0; i < found.Length; ++i) { MemberInfo member = found[i]; PropertyInfo property = member as PropertyInfo; if (null == property) MemberNotSupported(member); MethodInfo method = sliceKind == SetOrGet.Get ? GetGetMethod(property) : GetSetMethod(property); candidates[i] = method; } object state = null; return Type.DefaultBinder.BindToMethod(DefaultBindingFlags | BindingFlags.OptionalParamBinding, candidates, ref args, null, null, null, out state); }
private static MethodInfo Accessor(PropertyInfo p, SetOrGet gos) { return gos == SetOrGet.Get ? p.GetGetMethod(true) : p.GetSetMethod(true); }
static Dispatcher ReflectionBasedFieldDispatcherFor(FieldInfo field, SetOrGet gos) { switch (gos) { case SetOrGet.Get: return (target, args) => field.GetValue(target); case SetOrGet.Set: return (target, args) => { var value = args[0]; field.SetValue(target, RuntimeServices.Coerce(value, field.FieldType)); return value; }; default: throw new ArgumentException(); } }
private static MemberInfo SelectSliceMember(MemberInfo[] found, ref object[] args, SetOrGet sliceKind) { if (1 == found.Length) { return(found[0]); } var candidates = new MethodBase[found.Length]; for (var i = 0; i < found.Length; ++i) { var member = found[i]; var property = member as PropertyInfo; if (null == property) { MemberNotSupported(member); } var method = sliceKind == SetOrGet.Get ? GetGetMethod(property) : GetSetMethod(property); candidates[i] = method; } object state; return (Type.DefaultBinder.BindToMethod(DefaultBindingFlags | BindingFlags.OptionalParamBinding, candidates, ref args, null, null, null, out state)); }
private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { return SetOrGet.Get == gos ? new GetFieldEmitter(field).Emit() : new SetFieldEmitter(field, GetArgumentTypes()[0]).Emit(); }
private Dispatcher EmitFieldDispatcher(FieldInfo field, SetOrGet gos) { return(SetOrGet.Get == gos ? new GetFieldEmitter(field).Emit() : new SetFieldEmitter(field, GetArgumentTypes()[0]).Emit()); }