Exemplo n.º 1
0
        private bool InitFromBaObject(BaObject schema)
        {
            if (schema == null)
            {
                return(false);
            }
            if (schema == this)
            {
                return(false);                            // Can't initialize from itself!
            }
            foreach (var fld in schema.Fields)
            {
                // Can't share fields.
                var newfld = Add(fld.Name, fld.FieldType, null);

                // Setting the DefaultValue can throw an exception
                // if the field is required and the value is null.
                if (fld.DefaultValue != null)
                {
                    newfld.DefaultValue = fld.DefaultValue;
                }

                // Validators can be reused. They should be thread-safe.
                newfld.Validators.AddRange(fld.Validators);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of BaField
        /// </summary>
        /// <param name="obj">The object this belongs to.</param>
        /// <param name="name">Name of the field.</param>
        /// <param name="fieldType">The data type for the field.</param>
        /// <param name="dflt">Default value for the field. Used to determine if the field has changed. If null, it is converted to the default value for fieldType.</param>
        internal BaField(BaObject obj, string name, Type fieldType, object dflt = null)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (name.IsEmpty())
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (fieldType == null)
            {
                throw new ArgumentNullException(nameof(fieldType));
            }

            Object    = obj;
            Name      = name;
            FieldType = fieldType;
            if (dflt == null || dflt == DBNull.Value)
            {
                mDefaultValue = ConvertEx.GetDefaultEmptyValue(fieldType);
            }
            else
            {
                VerifyValue(dflt, "default value");
                mDefaultValue = dflt;
            }
        }
Exemplo n.º 3
0
 public BaDynamicObject(BaObject obj)
 {
     Object = obj;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates an instance of BaFieldList.
 /// </summary>
 internal BaFieldList(BaObject obj)
 {
 }