Esempio n. 1
0
    public static bool IsRealmObjectDescendant(this TypeReference @this, ImportedReferences references)
    {
        try
        {
            while (true)
            {
                if (@this == null || !Weaver.ShouldTraverseAssembly(@this.Module.Assembly.Name))
                {
                    return(false);
                }

                var definition = @this?.Resolve();
                if (definition == null)
                {
                    return(false);
                }

                if (definition.BaseType.IsSameAs(references.RealmObject) || definition.BaseType.IsSameAs(references.EmbeddedObject))
                {
                    return(true);
                }

                @this = definition.BaseType;
            }
        }
        catch
        {
            // Unity may fail to resolve some of its assemblies, but that's okay
            // they don't contain RealmObject classes.
        }

        return(false);
    }
    internal static bool IsIndexable(this PropertyDefinition property, ImportedReferences references)
    {
        Debug.Assert(property.DeclaringType.IsValidRealmObjectBaseInheritor(references), "Required properties only make sense on RealmObject/EmbeddedObject classes");
        var propertyType = property.PropertyType;

        if (propertyType.IsRealmInteger(out var isNullable, out var backingType))
        {
            if (isNullable)
            {
                return(false);
            }

            propertyType = backingType;
        }

        return(_indexableTypes.Contains(propertyType.FullName));
    }
 public static bool ContainsEmbeddedObject(this PropertyDefinition property, ImportedReferences references) => property.PropertyType.Resolve().IsEmbeddedObjectInheritor(references);
 public static bool IsValidRealmObjectBaseInheritor(this TypeDefinition type, ImportedReferences references) => type.IsEmbeddedObjectInheritor(references) || type.IsRealmObjectInheritor(references);
 public static bool IsRealmObjectInheritor(this TypeDefinition type, ImportedReferences references) => type.BaseType.IsSameAs(references.RealmObject);
 internal static bool IsRequired(this PropertyDefinition property, ImportedReferences references)
 {
     Debug.Assert(property.DeclaringType.IsValidRealmObjectBaseInheritor(references), "Required properties only make sense on RealmObject/EmbeddedObject classes");
     return(property.CustomAttributes.Any(a => a.AttributeType.Name == "RequiredAttribute"));
 }