Exemple #1
0
        /// <summary>
        /// Creates a DataObject for storing CLR objects based on <paramref name="format"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public DataContainerBuilder Data <T>(string name, T value, SerializationFormat format)
            where T : class, new()
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            DataObject obj;

            if (format == SerializationFormat.Container)
            {
                obj = DataObjectFactory.GetDataObjectFor(name, value);
            }
            else if (format == SerializationFormat.Json)
            {
                obj = new JsonDataObject(name, value);
            }
            else if (format == SerializationFormat.Xml)
            {
                obj = new XmlDataObject(name, value);
            }
            else
            {
                throw new NotImplementedException();
            }

            config.Add(obj);

            return(this);
        }
Exemple #2
0
        /// <summary>
        /// Function to make use of list initializers
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void Add(string key, object value)
        {
            if (IdentifierExtensions.IsValidIdentifier(key) == false)
            {
                throw new ArgumentException($"{key} is not a valid c# identifier");
            }

            internalDictionary.Add(key, DataObjectFactory.GetDataObjectFor(key, value));

            RaiseCollectionChanged(NotifyCollectionChangedAction.Add, internalDictionary[key]);
        }
Exemple #3
0
        /// <summary>
        /// Generic method to add <see cref="DataObject"/> based on <see cref="Type"/> of <paramref name="value"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DataContainerBuilder Data(string name, object value)
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            config.Add(DataObjectFactory.GetDataObjectFor(name, value));

            return(this);
        }
 public static void PutValue(this IDataContainer container, string key, object value)
 {
     if (container.ContainsData(key))
     {
         container.SetValue(key, value);
     }
     else
     {
         if (container is IPropertyContainer)
         {
             container.Add(DataObjectFactory.GetPropertyObjectFor(key, value));
         }
         else
         {
             container.Add(DataObjectFactory.GetDataObjectFor(key, value));
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Internal method to create <see cref="IDataContainer"/> from CLR Objects
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        private DataContainerBuilder Data(PropertyInfo pi, object obj)
        {
            var value = pi.GetValue(obj);

            if (value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {pi.Name}");

                return(this);
            }

            // ??
            if (value is IDataContainer dc && dc.Count == 0)
            {
                return(this);
            }

            config.Add(DataObjectFactory.GetDataObjectFor(pi.Name, value));

            return(this);
        }