int IList.IndexOf(object value) { if (ReadOnlyCollectionBuilder <T> .IsCompatibleObject(value)) { return(this.IndexOf((T)value)); } return(-1); }
void IList.Insert(int index, object value) { ReadOnlyCollectionBuilder <T> .ValidateNullValue(value, "value"); try { this.Insert(index, (T)value); } catch (InvalidCastException) { ReadOnlyCollectionBuilder <T> .ThrowInvalidTypeException(value, "value"); } }
int IList.Add(object value) { ReadOnlyCollectionBuilder <T> .ValidateNullValue(value, "value"); try { this.Add((T)value); } catch (InvalidCastException) { ReadOnlyCollectionBuilder <T> .ThrowInvalidTypeException(value, "value"); } return(this.Count - 1); }
private static Expression <T> Stitch <T>(Expression binding, LambdaSignature <T> signature) where T : class { Type targetType = typeof(T); Type siteType = typeof(CallSite <T>); var body = new ReadOnlyCollectionBuilder <Expression>(3); body.Add(binding); var site = Expression.Parameter(typeof(CallSite), "$site"); var @params = signature.Parameters.AddFirst(site); Expression updLabel = Expression.Label(CallSiteBinder.UpdateLabel); #if DEBUG // put the AST into the constant pool for debugging purposes updLabel = Expression.Block( Expression.Constant(binding, typeof(Expression)), updLabel ); #endif body.Add(updLabel); body.Add( Expression.Label( signature.ReturnLabel, Expression.Condition( Expression.Call( typeof(CallSiteOps).GetMethod("SetNotMatched"), @params.First() ), Expression.Default(signature.ReturnLabel.Type), Expression.Invoke( Expression.Property( Expression.Convert(site, siteType), typeof(CallSite <T>).GetProperty("Update") ), new TrueReadOnlyCollection <Expression>(@params) ) ) ) ); return(new Expression <T>( Expression.Block(body), "CallSite.Target", true, // always compile the rules with tail call optimization new TrueReadOnlyCollection <ParameterExpression>(@params) )); }
private static Expression <T> Stitch <T>(Expression binding, LambdaSignature <T> signature) where T : class { ParameterExpression expression; Type type = typeof(CallSite <T>); ReadOnlyCollectionBuilder <Expression> expressions = new ReadOnlyCollectionBuilder <Expression>(3) { binding }; ParameterExpression[] source = signature.Parameters.AddFirst <ParameterExpression>(expression = Expression.Parameter(typeof(CallSite), "$site")); Expression item = Expression.Label(UpdateLabel); expressions.Add(item); expressions.Add(Expression.Label(signature.ReturnLabel, Expression.Condition(Expression.Call(typeof(CallSiteOps).GetMethod("SetNotMatched"), source.First <ParameterExpression>()), Expression.Default(signature.ReturnLabel.Type), Expression.Invoke(Expression.Property(Expression.Convert(expression, type), typeof(CallSite <T>).GetProperty("Update")), new TrueReadOnlyCollection <Expression>(source))))); return(new Expression <T>(Expression.Block(expressions), "CallSite.Target", true, new TrueReadOnlyCollection <ParameterExpression>(source))); }
object IList.this[int index] { get { return(this[index]); } set { ReadOnlyCollectionBuilder <T> .ValidateNullValue(value, "value"); try { this[index] = (T)value; } catch (InvalidCastException) { ReadOnlyCollectionBuilder <T> .ThrowInvalidTypeException(value, "value"); } } }
bool IList.Contains(object value) { return(ReadOnlyCollectionBuilder <T> .IsCompatibleObject(value) && this.Contains((T)value)); }