Exemplo n.º 1
0
        public static T JsonTo <T>(this string s, T targetTypeDefault)
        {
            var jDic = new JsonDictionaryConverter(s);

            var com = new CommunicationBase();

            foreach (var p in jDic.Dictionary.Keys)
            {
                /*
                 * Get Deeper Level From string Result
                 */

                var val = jDic.Dictionary[p].StringValue;

                var newCom = new CommunicationBase()
                {
                    Name = p, Value = val.ToCurrentType()
                };

                var jDic2 = new JsonDictionaryConverter(jDic.Dictionary[p].StringValue);

                if (jDic2.Dictionary != null && jDic2.Dictionary.Count > 0)
                {
                    newCom = val.JsonTo <CommunicationBase>(newCom);
                }

                com.Add(newCom);
            }



            return(com.To <T>(targetTypeDefault));
        }
Exemplo n.º 2
0
        private static void ConvertListToICommunicationDictionary(object sourceValue, CommunicationBase result)
        {
            try { if (sourceValue == null || ((IDictionary)sourceValue).Count == 0)
                  {
                      return;
                  }
            }
            catch
            {
                return;
            }
            var dic = ((IDictionary)sourceValue);

            foreach (var key in dic.Keys)
            {
                var iComBase = new CommunicationBase();


                iComBase.Name = "Dic";
                var i = (CommunicationBase)dic[key].To <ICommunication>(new CommunicationBase());

                if (i.Count > 0)
                {
                    iComBase.Value = key.ToString() + ":" + i;
                }
                else
                {
                    iComBase.Value = key.ToString() + ":" + dic[key];
                }

                iComBase.Property = null;

                result.Add(iComBase);
            }
        }
Exemplo n.º 3
0
        private static void ConvertListToICommunicationList(object sourceValue, CommunicationBase result)
        {
            try { if (sourceValue == null || ((IEnumerable)sourceValue).Cast <object>().ToList().Count == 0)
                  {
                      return;
                  }
            }
            catch
            {
                return;
            }
            foreach (var listElement in ((IEnumerable)sourceValue).Cast <object>().ToList())
            {
                var iComBase = (CommunicationBase)listElement.To <ICommunication>(new CommunicationBase());

                iComBase.Name = "List";
                if (iComBase.Count == 0)
                {
                    iComBase.Value = listElement;
                }

                iComBase.Property = null;

                result.Add(iComBase);
            }
        }
Exemplo n.º 4
0
        private static void ConvertFlaggedPropertyToICommunication(object sourceValue, CommunicationBase result, PropertyInfo flaggedProperty)
        {
            var flaggedPropertyValue = flaggedProperty.GetValue(sourceValue, null);

            var iComBase = (CommunicationBase)flaggedPropertyValue.To <ICommunication>(new CommunicationBase());

            var flaggedPropertyCustomAttributes = flaggedProperty.GetCustomAttributes(typeof(AssignValueToAttribute), true).Select(x => (AssignValueToAttribute)x).FirstOrDefault();

            if (flaggedPropertyCustomAttributes != null && flaggedPropertyCustomAttributes.Pattern != flaggedProperty.Name)
            {
                AssignToPatternRelatedProperty(result, flaggedProperty, flaggedPropertyValue, iComBase, flaggedPropertyCustomAttributes);
            }
            else
            {
                iComBase.Name = flaggedProperty.Name;

                if (iComBase.Count == 0)
                {
                    iComBase.Value = flaggedPropertyValue;
                }

                iComBase.Property = flaggedProperty;
                result.Add(iComBase);
            }
        }
Exemplo n.º 5
0
        private static void ConvertArrayToICommunicationList(object sourceValue, CommunicationBase result)
        {
            foreach (var arrayElement in (object[])sourceValue)
            {
                var iComBase = (CommunicationBase)arrayElement.To <ICommunication>(new CommunicationBase());

                iComBase.Name = "Array";
                if (iComBase.Count == 0)
                {
                    iComBase.Value = arrayElement;
                }
                iComBase.Property = null;

                result.Add(iComBase);
            }
        }
Exemplo n.º 6
0
        private static void AssignToPatternRelatedProperty(CommunicationBase result, PropertyInfo flaggedProperty, object flaggedPropertyValue, CommunicationBase iComBase, AssignValueToAttribute flaggedPropertyCustomAttributes)
        {
            if (result.All(x => x.Name != flaggedPropertyCustomAttributes.Pattern))
            {
                iComBase.Name = flaggedPropertyCustomAttributes.Pattern;
                if (iComBase.Count == 0)
                {
                    iComBase.Value = flaggedPropertyValue;
                }
                iComBase.Property = flaggedProperty;
                result.Add(iComBase);
            }
            else
            {
                var firstOrDefault
                    = result.FirstOrDefault(x => x.Name == flaggedPropertyCustomAttributes.Pattern);

                if (firstOrDefault != null)
                {
                    firstOrDefault.Value += CommunicationBase.PatternJoint + flaggedPropertyValue;
                }
            }
        }