private static void DefineTable(MobileServiceLocalStore store, Type type) { if (type == null) { throw new ArgumentNullException("The data table type cannot be null"); } System.Diagnostics.Debug.WriteLine($"AzureMobileClient.Helpers is defining a local store table for: {type.Name}"); // Adopted from SQLite Store Generic Extensions var settings = new MobileServiceJsonSerializerSettings(); var contract = settings.ContractResolver.ResolveContract(type) as JsonObjectContract; if (contract.DefaultCreator == null) { throw new ArgumentException($"The TableData type '{type.Name}' does not have parameterless constructor."); } object theObject = contract.DefaultCreator(); SetEnumDefault(contract, theObject); var item = ConvertToJObject(settings, theObject); // set default values so serialized version can be used to infer types item["id"] = String.Empty; SetNullDefault(contract, item); store.DefineTable(type.Name, item); }
internal static bool DefineTables(MobileServiceLocalStore store, Type dataContextType) { bool hasSyncTables = false; foreach (var pi in dataContextType.GetTypeInfo().DeclaredProperties) { Type type = pi.PropertyType; if (type.GetTypeInfo().IsGenericType&& (type.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICloudSyncTable <>) || type.GetTypeInfo().GetGenericTypeDefinition() == typeof(IMobileServiceSyncTable <>))) { DefineTable(store, type.GetTypeInfo().GenericTypeArguments.FirstOrDefault()); hasSyncTables = true; } } return(hasSyncTables); }