Пример #1
0
        /// <summary>
        /// Defines the table.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="store">The store.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="System.ArgumentException">
        /// The generic type T is not an object.
        /// or
        /// The generic type T does not have parameterless constructor.
        /// </exception>
        public static void DefineTable <T>(this SqlStore store,
                                           MobileServiceJsonSerializerSettings settings)
        {
            string tableName = settings.ContractResolver.ResolveTableName(typeof(T));

            if (!(settings.ContractResolver.ResolveContract(typeof(T)) is JsonObjectContract contract))
            {
                throw new ArgumentException("The generic type T is not an object.");
            }

            if (contract.DefaultCreator == null)
            {
                throw new ArgumentException("The generic type T does not have parameterless constructor.");
            }

            // create an empty object
            object theObject = contract.DefaultCreator();

            SetEnumDefault(contract, theObject);

            JObject item = ConvertToJObject(settings, theObject);

            //// set default values so serialized version can be used to infer types
            SetIdDefault <T>(settings, item);
            SetNullDefault(contract, item);

            store.DefineTable(tableName, item);
        }
Пример #2
0
 /// <summary>
 /// Defines the table.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="store">The store.</param>
 public static void DefineTable <T>(this SqlStore store) => DefineTable <T>(store, new MobileServiceJsonSerializerSettings());