-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for subscription inclusions
- Loading branch information
Showing
9 changed files
with
249 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2018 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace Realms.Helpers | ||
{ | ||
internal static class LinqHelper | ||
{ | ||
public static string[] ToStringPaths<TSource, TProperty>(this Expression<Func<TSource, TProperty>>[] expressions) | ||
{ | ||
return expressions.Select(ToStringPath).ToArray(); | ||
} | ||
|
||
public static string ToStringPath<TSource, TResult>(this Expression<Func<TSource, TResult>> expression) | ||
{ | ||
var visitor = new PropertyVisitor(); | ||
visitor.Visit(expression.Body); | ||
visitor.Path.Reverse(); | ||
return string.Join(".", visitor.Path); | ||
} | ||
|
||
private class PropertyVisitor : ExpressionVisitor | ||
{ | ||
public List<string> Path { get; } = new List<string>(); | ||
|
||
protected override Expression VisitMember(MemberExpression node) | ||
{ | ||
if (!(node.Member is PropertyInfo)) | ||
{ | ||
throw new ArgumentException("The path can only contain properties", nameof(node)); | ||
} | ||
|
||
this.Path.Add(node.Member.Name); | ||
return base.VisitMember(node); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2016 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Realms.Sync.Native | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct StringValue | ||
{ | ||
internal static readonly int Size = Marshal.SizeOf<StringValue>(); | ||
|
||
[MarshalAs(UnmanagedType.LPStr)] | ||
public string Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.