internal static ValidationInfo /*!*/ GetValidationInfo(params DynamicMetaObject /*!*/[] /*!*/ args) { Expression typeTest = null; for (int i = 0; i < args.Length; i++) { if (args[i].HasValue) { IPythonObject val = args[i].Value as IPythonObject; if (val != null) { Expression test = BindingHelpers.CheckTypeVersion( AstUtils.Convert(args[i].Expression, val.GetType()), val.PythonType.Version ); test = Ast.AndAlso( Ast.TypeEqual(args[i].Expression, val.GetType()), test ); if (typeTest != null) { typeTest = Ast.AndAlso(typeTest, test); } else { typeTest = test; } } } } return(new ValidationInfo(typeTest)); }
internal static FastBindResult <T> MakeSetBinding <T>(CodeContext codeContext, CallSite <T> site, IPythonObject self, object value, Binding.PythonSetMemberBinder setBinder) where T : class { if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(self.GetType().BaseType)) { // very tricky, user is inheriting from a class which implements IDO, we // don't optimize this yet. return(new FastBindResult <T>()); } // optimized versions for possible literals that can show up in code. Type setType = typeof(T); if (setType == typeof(Func <CallSite, object, object, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <object>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, string, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <string>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, int, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <int>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, double, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <double>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, List, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <List>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, PythonTuple, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <PythonTuple>( codeContext, self, value, setBinder).MakeSet()); } else if (setType == typeof(Func <CallSite, object, PythonDictionary, object>)) { return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <PythonDictionary>( codeContext, self, value, setBinder).MakeSet()); } return(new FastBindResult <T>()); }