Skip to content

Commit

Permalink
First attempt at fixing arbitrary member access issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenniak committed Apr 15, 2015
1 parent a6b3910 commit 7e2b51f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
15 changes: 15 additions & 0 deletions rethinkdb-net-test/Integration/MultiObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,5 +1133,20 @@ public void FilterByRegexpMatches()
}
count.Should().Be(1);
}

[Test]
public void FilterByRegexpGroup()
{
int count = 0;
foreach (var row in connection.Run(testTable.Filter(o =>
o.Name.Match("^([3])$") != null &&
o.Name.Match("^([3])$").Groups[0].MatchedString == "3"
)))
{
row.Name.Should().Be("3");
count += 1;
}
count.Should().Be(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override bool TryGet<T>(IDatumConverterFactory rootDatumConverterFactory,

public bool IsTypeSupported(Type t)
{
if (t.IsClass && t.Name.Contains("Anon") && t.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length == 1)
if (t.IsClass && t.Name.Contains("Anon") && t.Name.StartsWith("<>") && t.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length == 1)
return true;
return false;
}
Expand Down
47 changes: 44 additions & 3 deletions rethinkdb-net/Expressions/BaseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,45 @@ protected Term SimpleMap(IDatumConverterFactory datumConverterFactory, Expressio
DefaultExpressionConverterFactory.ExpressionMappingDelegate<MemberExpression> memberAccessMapping;
if (expressionConverterFactory.TryGetMemberAccessMapping(member, out memberAccessMapping))
return memberAccessMapping(memberExpression, RecursiveMap, datumConverterFactory, expressionConverterFactory);
else
return AttemptClientSideConversion(datumConverterFactory, expr);

// Check if this is a member access on an object, rather than a static member access. If so,
// see if we can use the IObjectDatumConverter interface to access a field on it.
if (memberExpression.Expression != null)
{
// If we even can get a datum converter for this type...
IDatumConverter datumConverter;
if (datumConverterFactory.TryGet(memberExpression.Expression.Type, out datumConverter))
{
// And if it implements IObjectDatumConverter
var fieldConverter = datumConverter as IObjectDatumConverter;
if (fieldConverter != null)
{
var datumFieldName = fieldConverter.GetDatumFieldName(memberExpression.Member);
if (string.IsNullOrEmpty(datumFieldName))
throw new NotSupportedException(String.Format("Member {0} on type {1} could not be mapped to a datum field", memberExpression.Member.Name, memberExpression.Type));

Console.WriteLine("Expr being mapped to object access: {0}", expr);

var getAttrTerm = new Term()
{
type = Term.TermType.GET_FIELD
};
getAttrTerm.args.Add(RecursiveMap(memberExpression.Expression));
getAttrTerm.args.Add(new Term()
{
type = Term.TermType.DATUM,
datum = new Datum()
{
type = Datum.DatumType.R_STR,
r_str = datumFieldName
}
});
return getAttrTerm;
}
}
}

return AttemptClientSideConversion(datumConverterFactory, expr);
}

case ExpressionType.Conditional:
Expand Down Expand Up @@ -205,7 +242,11 @@ private Term AttemptClientSideConversion(IDatumConverterFactory datumConverterFa
}
catch (InvalidOperationException ex)
{
throw new InvalidOperationException("Failed to perform client-side evaluation of expression tree node; often this is caused by refering to a server-side variable in a node that is only supported w/ client-side evaluation", ex);
throw new InvalidOperationException(
String.Format(
"Failed to perform client-side evaluation of expression tree node '{0}'; this is caused by refering to a server-side variable in an expression tree that isn't convertible to ReQL logic",
expr),
ex);
}
}

Expand Down

0 comments on commit 7e2b51f

Please sign in to comment.