Skip to content

Commit

Permalink
#746 Rolling back to 0.76.1 then adding features - IList changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyDentFree committed Aug 2, 2016
1 parent 6659136 commit 69574cf
Show file tree
Hide file tree
Showing 43 changed files with 887 additions and 584 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.userosscache
*.sln.docstates
*.opendb
*.VC.db

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down Expand Up @@ -142,6 +143,9 @@ Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# JetBrains Rider files

.idea.*


### Xcode ###
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
0.77.2 (2016-08-02)
-------------------

**Special private release**

To debug issues some users encountered after the release of 0.77.1, we went back to 0.76.1 and added in primarily just IList declarations and detached row detection.

### Major Changes
* To Many relationships can now be declared with an `IList<DestClass>` rather than requiring `RealmList<DestClass>`. This is significantly faster than using `RealmList` due to caching the list. (Issue #287)
* Creating standalone objects with lists of related objects is now possible. Passing such an object into `Realm.Manage` will cause the entire object graph from that object down to become managed.

### Minor Changes
* Accessing properties on invalid objects will throw an exception rather than crash with a segfault (#662)

Using core 1.0.2 (same as 0.76.0)


0.76.0 (2016-06-09)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion Doxygen/realmPublicAPI.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Realm Xamarin"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = v0.75.0
PROJECT_NUMBER = v0.77.2

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
43 changes: 18 additions & 25 deletions Realm.PCL/Properties/AssemblyInfo.cs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
////////////////////////////////////////////////////////////////////////////
//
// 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.
//
////////////////////////////////////////////////////////////////////////////

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
using System.Reflection;

[assembly: AssemblyTitle("Realm.PCL")]
[assembly: AssemblyDescription("Realm is a mobile database: a replacement for SQLite")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCopyright("Copyright © 2016 Realm")]
[assembly: AssemblyCompany("Realm Inc.")]
[assembly: AssemblyProduct("Realm C#")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]


// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion(("0.76.0.0"))]
[assembly: AssemblyFileVersion(("0.76.0.0"))]
8 changes: 8 additions & 0 deletions Realm.PCL/Realm.PCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<DocumentationFile>bin\Debug\Realm.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<DocumentationFile>bin\Release\Realm.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\RealmAssemblyInfo.cs">
<Link>Properties\RealmAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RealmPCLHelpers.cs" />
<Compile Include="TransactionPCL.cs" />
Expand Down Expand Up @@ -92,6 +97,9 @@
<Link>PreserveAttribute.cs</Link>
</Compile>
<Compile Include="Extensions\RealmResultsCollectionChangedPCL.cs" />
<Compile Include="..\Realm.Shared\ICopyValuesFrom.cs">
<Link>ICopyValuesFrom.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Realm.PCL/RealmListPCL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,11 @@ private void ManageObjectIfNeeded(T obj)
}

#endregion

void ICopyValuesFrom.CopyValuesFrom(IEnumerable<RealmObject> values)
{
RealmPCLHelpers.ThrowProxyShouldNeverBeUsed();
}

}
}
2 changes: 1 addition & 1 deletion Realm.PCL/RealmObjectPCL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected DateTimeOffset GetDateTimeOffsetValue(string propertyName)
return null;
}

protected RealmList<T> GetListValue<T>(string propertyName) where T : RealmObject
protected IList<T> GetListValue<T>(string propertyName) where T : RealmObject
{
RealmPCLHelpers.ThrowProxyShouldNeverBeUsed();
return null;
Expand Down
4 changes: 2 additions & 2 deletions Realm.PCL/RealmResultsPCL.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace Realms
/// Iterable collection of one kind of RealmObject resulting from Realm.All or from a LINQ query expression.
/// </summary>
/// <typeparam name="T">Type of the RealmObject which is being returned.</typeparam>
public class RealmResults<T> : IQueryable<T>
public class RealmResults<T> : IOrderedQueryable<T>
{
/// <summary>
/// A <see cref="ChangeSet" /> describes the changes inside a <see cref="RealmResults{T}" /> since the last time the notification callback was invoked.
Expand Down
7 changes: 6 additions & 1 deletion Realm.Shared/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
Expand All @@ -21,18 +21,22 @@

namespace Realms
{
[AttributeUsage(AttributeTargets.Property)]
public class ObjectIdAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Property)]
public class IndexedAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class IgnoredAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class MapToAttribute : Attribute
{
public string Mapping { get; set; }
Expand All @@ -42,6 +46,7 @@ public MapToAttribute(string mapping)
}
}

[AttributeUsage(AttributeTargets.Class)]
public class WovenAttribute : Attribute
{
internal Type HelperType { get; private set; }
Expand Down
11 changes: 11 additions & 0 deletions Realm.Shared/ICopyValuesFrom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Realms
{

// Interface allows us to cast a generic RealmList to this and invoke CopyValuesFrom
internal interface ICopyValuesFrom
{
void CopyValuesFrom(IEnumerable<RealmObject> values);
}
}

25 changes: 21 additions & 4 deletions Realm.Shared/PreserveAttribute.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////


using System;

namespace Realms
{
// Tell the linker to preserve a class or method even if it looks like it's not invoked.
// Since it matches by name, it works to just declare it here.
[System.AttributeUsage(System.AttributeTargets.All)]
public class PreserveAttribute : System.Attribute
[AttributeUsage(AttributeTargets.All)]
public class PreserveAttribute : Attribute
{
public PreserveAttribute (string reason = null) {}
#if WINDOWS
public bool AllMembers { get; set; }
public bool Conditional { get; set; }
#else
public bool AllMembers;
public bool Conditional;
#endif

public PreserveAttribute(bool allMembers, bool conditional)
{
AllMembers = allMembers;
Conditional = conditional;
}

public PreserveAttribute()
{
}
}
}

1 change: 1 addition & 0 deletions Realm.Shared/Realm.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="$(MSBuildThisFileDirectory)handles\NotificationTokenHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)exceptions\RealmInvalidTransactionException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)extensions\RealmResultsCollectionChanged.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ICopyValuesFrom.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)weaving\" />
Expand Down
4 changes: 2 additions & 2 deletions Realm.Shared/Realm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ private static IntPtr GenerateObjectSchema(Type objectClass)
var isIndexed = indexedAttribute != null;

var isNullable = !(p.PropertyType.IsValueType ||
p.PropertyType.Name == "IList`1" ||
p.PropertyType.Name == "RealmList`1") ||
// IGNORING IList FOR NOW p.PropertyType.Name == "IList`1") ||
Nullable.GetUnderlyingType(p.PropertyType) != null;

var objectType = "";
if (!p.PropertyType.IsValueType && p.PropertyType.Name!="String") {
if (p.PropertyType.Name == "RealmList`1") // IGNORING IList FOR NOW || p.PropertyType.Name == "IList`1")
if (p.PropertyType.Name == "IList`1" || p.PropertyType.Name == "RealmList`1")
objectType = p.PropertyType.GetGenericArguments()[0].Name;
else {
if (p.PropertyType.BaseType.Name == "RealmObject")
Expand Down
58 changes: 27 additions & 31 deletions Realm.Shared/RealmList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,39 @@ namespace Realms
/// </remarks>
///
/// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
public class RealmList<T> : IList<T> where T : RealmObject
[Preserve(AllMembers = true)]
public class RealmList<T> : IList<T>, ICopyValuesFrom where T : RealmObject
{
private class RealmListEnumerator : IEnumerator<T>
public class Enumerator : IEnumerator<T>
{
private int index;
private RealmList<T> enumerating;
private readonly RealmList<T> _enumerating;
private int _index;

internal RealmListEnumerator(RealmList<T> parent)
internal Enumerator(RealmList<T> parent)
{
index = -1;
enumerating = parent;
_index = -1;
_enumerating = parent;
}

/// <summary>
/// Return the current related object when iterating a related set.
/// </summary>
/// <exception cref="IndexOutOfRangeException">When we are not currently pointing at a valid item, either MoveNext has not been called for the first time or have iterated through all the items.</exception>
public T Current
{
get
{
return enumerating[index];
}
}
public T Current => _enumerating[_index];

// also needed - https://msdn.microsoft.com/en-us/library/s793z9y2.aspx
object IEnumerator.Current
{
get
{
return enumerating[index];
}
}
object IEnumerator.Current => Current;

/// <summary>
/// Move the iterator to the next related object, starting "before" the first object.
/// </summary>
/// <returns>True only if can advance.</returns>
public bool MoveNext()
{
index++;
if (index >= enumerating.Count)
var index = _index + 1;
if (index >= _enumerating.Count)
return false;

_index = index;
return true;
}

Expand All @@ -83,7 +73,7 @@ public bool MoveNext()
/// </summary>
public void Reset()
{
index = -1; // by definition BEFORE first item
_index = -1; // by definition BEFORE first item
}

/// <summary>
Expand Down Expand Up @@ -146,6 +136,7 @@ public bool IsSynchronized
/// <typeparam name="T">Type of the RealmObject which is the target of the relationship.</typeparam>
/// <returns>A related item, if exception not thrown.</returns>
/// <exception cref="IndexOutOfRangeException">When the index is out of range for the related items.</exception>
[System.Runtime.CompilerServices.IndexerName("Item")]
public T this[int index]
{
get
Expand Down Expand Up @@ -222,9 +213,9 @@ public void CopyTo(T[] array, int arrayIndex)
/// Factory for an iterator to be called explicitly or used in a foreach loop.
/// </summary>
/// <returns>A RealmListEnumerator as the generic IEnumerator<T>.</returns>
public IEnumerator<T> GetEnumerator()
public Enumerator GetEnumerator()
{
return new RealmListEnumerator(this);
return new Enumerator(this);
}

/// <summary>
Expand Down Expand Up @@ -286,10 +277,8 @@ public void RemoveAt(int index)
NativeLinkList.erase(_listHandle, (IntPtr)index);
}

IEnumerator IEnumerable.GetEnumerator()
{
return new RealmListEnumerator(this);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

private void ManageObjectIfNeeded(T obj)
{
Expand All @@ -298,5 +287,12 @@ private void ManageObjectIfNeeded(T obj)
}

#endregion
void ICopyValuesFrom.CopyValuesFrom(IEnumerable<RealmObject> values)
{
foreach (var item in values.Cast<T>())
{
Add(item);
}
}
}
}
Loading

0 comments on commit 69574cf

Please sign in to comment.