private static void SetPropertyInfo2(string[] unbs, object IsClassObject)
 {
     PropertyInfo[] propertyInfoTypes = IsClassObject.GetType().GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiValueAttribute>().First().Order).ToArray();
     for (int i = 0; i < propertyInfoTypes.Length; i++)
     {
         EdiValueAttribute ediValueAttribute = (EdiValueAttribute)propertyInfoTypes[i].GetCustomAttribute(typeof(EdiValueAttribute));
         if (propertyInfoTypes[i].PropertyType.Name == "Int32")
         {
             propertyInfoTypes[i].SetValue(IsClassObject, Convert.ToInt32(unbs[i]));
         }
         else if (propertyInfoTypes[i].PropertyType.Name == "DateTime")
         {
             DateTime dt = DateTime.ParseExact(unbs[i], ediValueAttribute.Format, null);
             propertyInfoTypes[i].SetValue(IsClassObject, dt);
         }
         else if (propertyInfoTypes[i].PropertyType.Name == "TimeSpan")
         {
             TimeSpan.TryParseExact(unbs[i], ediValueAttribute.Format, null, out TimeSpan timeSpan);
             propertyInfoTypes[i].SetValue(IsClassObject, timeSpan);
         }
         else
         {
             propertyInfoTypes[i].SetValue(IsClassObject, unbs[i]);
         }
     }
 }
        private static void SetPropertyInfo(string[] unbs, object IsClassObject)
        {
            if ((unbs.Length == 1) && (unbs[0].Contains(":")))
            {
                unbs = unbs[0].Split(':');
            }

            var a = IsClassObject.GetType().GetProperties();

            PropertyInfo[] propertyInfoTypes = IsClassObject.GetType().GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiOrderAttribute>().First().Order).ToArray();
            if (propertyInfoTypes.Length != unbs.Length)
            {
                string aaa = string.Empty;
            }
            for (int i = 0; i < unbs.Length; i++)
            {
                Type propertyType = propertyInfoTypes[i].PropertyType;
                if (!propertyType.IsGenericType)
                {
                    EdiValueAttribute ediValueAttribute = (EdiValueAttribute)propertyInfoTypes[i].GetCustomAttribute(typeof(EdiValueAttribute));
                    if (propertyInfoTypes[i].PropertyType.Name == "Int32")
                    {
                        if ((unbs[i] != null) && (unbs[i].Length > 0))
                        {
                            propertyInfoTypes[i].SetValue(IsClassObject, Convert.ToInt32(unbs[i]));
                        }
                    }
                    else if (propertyInfoTypes[i].PropertyType.Name == "String")
                    {
                        propertyInfoTypes[i].SetValue(IsClassObject, unbs[i]);
                    }
                    else if (propertyInfoTypes[i].PropertyType.Name == "DateTime")
                    {
                        string   sample = unbs[i].PadRight(12, '0');
                        DateTime dt     = DateTime.ParseExact(sample, ediValueAttribute.Format, null);
                        propertyInfoTypes[i].SetValue(IsClassObject, dt);
                    }
                    else
                    {
                        object IsClassObject2 = Activator.CreateInstance(propertyType);
                        SetPropertyInfo2(unbs[i].Split(':'), IsClassObject2);
                        propertyInfoTypes[i].SetValue(IsClassObject, IsClassObject2);
                    }
                }
                else
                {
                    object IsClassObject2 = Activator.CreateInstance(propertyType);
                    SetPropertyInfo2(unbs[i].Split(':'), IsClassObject2);
                    propertyInfoTypes[i].SetValue(IsClassObject, IsClassObject2);
                }
            }
        }
        public static string[] IsNotGenericType(string[] readToEndLines, object dataObject)
        {
            if (readToEndLines.Length == 0)
            {
                return(readToEndLines);
            }
            Type dataObjectType = dataObject.GetType();

            PropertyInfo[] propertyInfos = dataObjectType.GetProperties();
            try {
                propertyInfos = dataObjectType.GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiSegmentAttribute>().First().Order).ToArray();
            }
            catch {
                propertyInfos = dataObjectType.GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiOrderAttribute>().First().Order).ToArray();
            }
            for (int i = 0; i < propertyInfos.Length; i++)
            {
                bool IsHave       = true;
                Type propertyType = propertyInfos[i].PropertyType;
                EdiSegmentAttribute eEdiSegmentAttribute = (EdiSegmentAttribute)propertyInfos[i].GetCustomAttribute(typeof(EdiSegmentAttribute));
                if ((eEdiSegmentAttribute != null) && (eEdiSegmentAttribute.SequenceEnd != null))
                {
                    if (!propertyType.IsGenericType)
                    {
                        EdiSegmentAttribute eEdiSegmentAttributeproperty = (EdiSegmentAttribute)propertyType.GetCustomAttribute(typeof(EdiSegmentAttribute));
                        if (eEdiSegmentAttributeproperty != null)
                        {
                            IsHave = false;
                            foreach (string item in readToEndLines)
                            {
                                if (item.StartsWith(eEdiSegmentAttribute.SequenceEnd))
                                {
                                    break;
                                }
                                else if (item.StartsWith(eEdiSegmentAttributeproperty.Path))
                                {
                                    IsHave = true;
                                }
                            }
                        }
                    }
                }
                else
                {
                    EdiValueAttribute ediValueAttribute = (EdiValueAttribute)propertyInfos[i].GetCustomAttribute(typeof(EdiValueAttribute));
                    if (ediValueAttribute != null)
                    {
                        if (ediValueAttribute != null)
                        {
                            if (readToEndLines.Length > 0)
                            {
                                string[] parts = readToEndLines[0].Split('+');
                                if (ediValueAttribute.Path == parts[0])
                                {
                                    parts = parts.Skip(1).ToArray();
                                    if (parts.Length == 1)
                                    {
                                        SetPropertyInfo(parts[0].Split(':'), dataObject);
                                        readToEndLines = readToEndLines.Where(w => w != readToEndLines[0]).ToArray();
                                    }
                                    else
                                    {
                                        SetPropertyInfo(parts, dataObject);
                                        readToEndLines = readToEndLines.Where(w => w != readToEndLines[0]).ToArray();
                                    }
                                }
                            }
                        }
                    }
                }
                if (!propertyType.IsGenericType && IsHave)
                {
                    if (readToEndLines.Length > 0)
                    {
                        readToEndLines = SetPropertyInfo(readToEndLines, dataObject, propertyInfos[i], propertyType);
                    }
                }
            }
            return(readToEndLines);
        }
Esempio n. 4
0
        public static string[] IsGenericType(string[] readToEndLines, object dataObject)
        {
            Type dataObjectType = dataObject.GetType();

            PropertyInfo[] propertyInfos = dataObjectType.GetProperties();
            try {
                propertyInfos = dataObjectType.GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiSegmentAttribute>().First().Order).ToArray();
            }
            catch {
                propertyInfos = dataObjectType.GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiValueAttribute>().First().Order).ToArray();
            }

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                Type propertyType = propertyInfo.PropertyType;
                if (propertyType.IsGenericType)
                {
                    EdiSegmentAttribute eEdiSegmentAttribute = (EdiSegmentAttribute)propertyInfo.GetCustomAttribute(typeof(EdiSegmentAttribute));
                    Type            GenericArgument          = propertyInfo.PropertyType.GetGenericArguments()[0];
                    List <string[]> bloks    = new List <string[]>();
                    List <string>   tempBlok = new List <string>();
                    foreach (string readToEndLine in readToEndLines)
                    {
                        if (eEdiSegmentAttribute.SequenceEnd == null)
                        {
                        }
                        else
                        {
                            if ((tempBlok.Count > 0) && (readToEndLine.StartsWith(eEdiSegmentAttribute.SequenceEnd) | readToEndLine.StartsWith(eEdiSegmentAttribute.Path)))
                            {
                                if (eEdiSegmentAttribute.IsWithSequenceEnd)
                                {
                                    tempBlok.Add(readToEndLine);
                                    bloks.Add(tempBlok.ToArray());
                                    tempBlok.Clear();
                                }
                                else
                                {
                                    bloks.Add(tempBlok.ToArray());
                                    //readToEndLines = readToEndLines.Skip(tempBlok.Count).ToArray();
                                    tempBlok.Clear();
                                    tempBlok.Add(readToEndLine);
                                }
                            }
                            else
                            {
                                tempBlok.Add(readToEndLine);
                            }
                        }
                    }
                    if (tempBlok.Count > 0)
                    {
                        bloks.Add(tempBlok.ToArray());
                        tempBlok.Clear();
                    }
                    object instance = Activator.CreateInstance(propertyInfo.PropertyType);
                    IList  list     = (IList)instance;
                    if (bloks.Count == 0)
                    {
                        bool           IsValueType         = true;
                        PropertyInfo[] propertiesForValues = GenericArgument.GetProperties();
                        foreach (PropertyInfo propertiesForValue in propertiesForValues)
                        {
                            IsValueType &= propertiesForValue.GetCustomAttribute <EdiValueAttribute>() != null;
                        }

                        if (!IsValueType)
                        {
                            object newObject = Edi850Deserialize.DeserializeInternal(readToEndLines, GenericArgument);
                            list.Add(newObject);
                        }
                        else
                        {
                            foreach (PropertyInfo propertiesForValue in propertiesForValues)
                            {
                                if (readToEndLines.Length > 0)
                                {
                                    EdiValueAttribute EdiValueAttributeValue = propertiesForValue.GetCustomAttribute <EdiValueAttribute>();
                                    string[]          ValueResults           = readToEndLines.Where(x => x.Contains(EdiValueAttributeValue.Path)).ToArray();
                                    foreach (string ValueResult in ValueResults)
                                    {
                                        object newObject = Edi850Deserialize.DeserializeInternal(new[] { ValueResult }, GenericArgument);
                                        list.Add(newObject);
                                        readToEndLines = readToEndLines.Where(w => w != ValueResult).ToArray();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (string[] items in bloks)
                        {
                            if (items[0].StartsWith(eEdiSegmentAttribute.Path))
                            {
                                object newObject = Edi850Deserialize.DeserializeInternal(items, GenericArgument);
                                list.Add(newObject);
                            }
                        }
                    }
                    propertyInfo.SetValue(dataObject, list, null);
                }
            }
            return(readToEndLines);
        }
Esempio n. 5
0
 public static void SetPropertyInfo(string[] parts, object IsClassObject)
 {
     PropertyInfo[] propertyInfoTypes = IsClassObject.GetType().GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiValueAttribute>().First().Order).ToArray();
     foreach (PropertyInfo propertyInfoType in propertyInfoTypes)
     {
         #region
         object[]          ediValueAttributes = propertyInfoType.GetCustomAttributes(typeof(EdiValueAttribute), true);
         EdiValueAttribute ediValueAttribute  = (EdiValueAttribute)ediValueAttributes[0];
         if ((ediValueAttribute.Order + 1) >= parts.Length)
         {
             break;
         }
         if (ediValueAttributes.Length > 1)
         {
             string   formatString = ediValueAttribute.Format + ((EdiValueAttribute)ediValueAttributes[1]).Format;
             string   sample       = parts[ediValueAttribute.Order + 1] + parts[ediValueAttribute.Order + 2];
             DateTime dt           = DateTime.ParseExact(sample, formatString, null);
             propertyInfoType.SetValue(IsClassObject, dt);
         }
         else
         {
             if (ediValueAttribute.Picture.Kind == Enums.PictureKind.Numeric)
             {
                 if (propertyInfoType.PropertyType.IsGenericType)
                 {
                     string result = parts[ediValueAttribute.Order + 1].ToString();
                     if (result != string.Empty)
                     {
                         bool boolValue = result == "0" ? false : true;
                         propertyInfoType.SetValue(IsClassObject, boolValue);
                     }
                 }
                 else
                 {
                     if (parts[ediValueAttribute.Order + 1] != string.Empty)
                     {
                         if (propertyInfoType.PropertyType.Name == "Decimal")
                         {
                             Decimal decimalValue = Convert.ToDecimal(parts[ediValueAttribute.Order + 1].ToString());
                             propertyInfoType.SetValue(IsClassObject, decimalValue);
                         }
                         else if (propertyInfoType.PropertyType.Name == "DateTime")
                         {
                             string   s  = parts[ediValueAttribute.Order + 1];
                             DateTime dt = DateTime.ParseExact(s, ediValueAttribute.Format, null);
                             propertyInfoType.SetValue(IsClassObject, dt);
                         }
                         else
                         {
                             propertyInfoType.SetValue(IsClassObject, Convert.ToInt32(parts[ediValueAttribute.Order + 1]));
                         }
                     }
                 }
             }
             else
             {
                 if (propertyInfoType.PropertyType.IsGenericType)
                 {
                     propertyInfoType.SetValue(IsClassObject, '\0');
                 }
                 else
                 {
                     if (propertyInfoType.PropertyType.Name == "Decimal")
                     {
                         if (parts[ediValueAttribute.Order + 1] != string.Empty)
                         {
                             decimal a = Convert.ToDecimal(parts[ediValueAttribute.Order + 1].ToString());
                             propertyInfoType.SetValue(IsClassObject, a);
                         }
                     }
                     else
                     {
                         propertyInfoType.SetValue(IsClassObject, parts[ediValueAttribute.Order + 1]);
                     }
                 }
             }
         }
         #endregion
     }
 }
Esempio n. 6
0
        private object DeserializeInternal(string[] ReadToEndLines, Type objectType)
        {
            object dataObject     = Activator.CreateInstance(objectType);
            Type   dataObjectType = dataObject.GetType();

            PropertyInfo[] propertyInfos = dataObjectType.GetProperties();

            EdiValueAttribute ediValueAttribute = (EdiValueAttribute)propertyInfos[0].GetCustomAttribute(typeof(EdiValueAttribute));

            if (ediValueAttribute != null)
            {
                var      a     = objectType.GetCustomAttributes();
                string[] parts = ReadToEndLines[0].Split('*');
                SetPropertyInfo(parts, dataObject);
                return(dataObject);
            }
            propertyInfos = dataObjectType.GetProperties().OrderBy(p => p.GetCustomAttributes().OfType <EdiSegmentAttribute>().First().Order).ToArray();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                Type propertyType = propertyInfo.PropertyType;
                if (!propertyType.IsGenericType)
                {
                    ReadToEndLines = SetPropertyInfo(ReadToEndLines, dataObject, propertyInfo, propertyType);
                }
            }

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                Type propertyType = propertyInfo.PropertyType;
                if (propertyType.IsGenericType)
                {
                    EdiSegmentAttribute eEdiSegmentAttribute = (EdiSegmentAttribute)propertyInfo.GetCustomAttribute(typeof(EdiSegmentAttribute));
                    Type GenericArgument = propertyInfo.PropertyType.GetGenericArguments()[0];

                    List <string>   readToEndLineTemp = new List <string>();
                    List <string[]> details           = new List <string[]>();
                    foreach (string readToEndLine in ReadToEndLines)
                    {
                        string[] parts  = readToEndLine.Split('*');
                        string   master = parts[0];
                        if (eEdiSegmentAttribute.SequenceEnd == null)
                        {
                            IEnumerable <Attribute> Attributes = GenericArgument.GetCustomAttributes();
                            if (Attributes.Count() == 0)
                            {
                                readToEndLineTemp.Add(readToEndLine);
                            }
                            else
                            {
                                if (eEdiSegmentAttribute.Path == master)
                                {
                                    readToEndLineTemp.Add(readToEndLine);
                                }
                            }
                        }
                        else if (eEdiSegmentAttribute.SequenceEnd == master)
                        {
                            readToEndLineTemp.Add(readToEndLine);
                            details.Add(readToEndLineTemp.ToArray());
                            readToEndLineTemp = new List <string>();
                        }
                        else
                        {
                            readToEndLineTemp.Add(readToEndLine);
                        }
                    }
                    if (details.Count > 0)
                    {
                        object instance = Activator.CreateInstance(propertyInfo.PropertyType);
                        IList  list     = (IList)instance;
                        foreach (string[] strings in details)
                        {
                            object newObject = DeserializeInternal(strings, GenericArgument);
                            list.Add(newObject);
                        }
                        propertyInfo.SetValue(dataObject, list, null);
                    }
                    else
                    {
                        List <string> readToEndLineTempDetay = new List <string>();
                        foreach (string readToEndLine in readToEndLineTemp)
                        {
                            string[] parts  = readToEndLine.Split('*');
                            string   master = parts[0];
                            if (master == "SE")
                            {
                                continue;
                            }
                            if ((eEdiSegmentAttribute.Path == master) && (readToEndLineTempDetay.Count > 1))
                            {
                                details.Add(readToEndLineTempDetay.ToArray());
                                readToEndLineTempDetay = new List <string>();
                            }
                            readToEndLineTempDetay.Add(readToEndLine);
                        }
                        if (readToEndLineTempDetay.Count > 0)
                        {
                            details.Add(readToEndLineTempDetay.ToArray());
                            readToEndLineTempDetay = new List <string>();
                        }

                        object instance = Activator.CreateInstance(propertyInfo.PropertyType);
                        IList  list     = (IList)instance;
                        foreach (string[] strings in details)
                        {
                            object newObject = DeserializeInternal(strings, GenericArgument);
                            list.Add(newObject);
                        }
                        propertyInfo.SetValue(dataObject, list, null);
                    }
                }
            }
            return(dataObject);
        }
Esempio n. 7
0
        private static void SetEdiSegmentAttribute(StreamWriter streamWriter, object objectTypeDetail, EdiSegmentAttribute ediSegmentAttribute)
        {
            string lineInfo = string.Empty;

            lineInfo += ediSegmentAttribute.Path + Separate;
            foreach (PropertyInfo propertyInfoDetail in PropertyInfoClass.GetPropertyInfos(objectTypeDetail))
            {
                object[] EdiValueAttributes = propertyInfoDetail.GetCustomAttributes(typeof(EdiValueAttribute), true);
                foreach (object ediValueAttribute in EdiValueAttributes)
                {
                    EdiValueAttribute ediValueAttributeInfo = ediValueAttribute as EdiValueAttribute;
                    string            detailValue           = string.Empty;
                    switch (ediValueAttributeInfo.Picture.Kind)
                    {
                    case Enums.PictureKind.Alphanumeric:
                        if (propertyInfoDetail.PropertyType == typeof(string))
                        {
                            detailValue = (string)propertyInfoDetail.GetValue(objectTypeDetail);
                            if (ediValueAttributeInfo.IsTrim)
                            {
                                if (detailValue != null && detailValue.Length > ediValueAttributeInfo.Picture.Scale)
                                {
                                    detailValue = detailValue.Substring(0, ediValueAttributeInfo.Picture.Scale);
                                }
                            }
                            else
                            {
                                detailValue = detailValue.PadRight(ediValueAttributeInfo.Picture.Scale, ' ');
                            }
                        }
                        else if (propertyInfoDetail.PropertyType == typeof(char))
                        {
                            detailValue = ((char)propertyInfoDetail.GetValue(objectTypeDetail)).ToString();
                            if (ediValueAttributeInfo.IsTrim)
                            {
                                if (detailValue != null && detailValue.Length > ediValueAttributeInfo.Picture.Scale)
                                {
                                    detailValue = detailValue.Substring(0, ediValueAttributeInfo.Picture.Scale);
                                }
                            }
                            else
                            {
                                detailValue = detailValue.PadRight(ediValueAttributeInfo.Picture.Scale, ' ');
                            }
                        }
                        else if (propertyInfoDetail.PropertyType.IsGenericType && propertyInfoDetail.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            var genericType = propertyInfoDetail.PropertyType.GetGenericArguments()[0];
                            if (genericType.FullName == "System.Char")
                            {
                                detailValue = ((char)propertyInfoDetail.GetValue(objectTypeDetail)).ToString();
                                if (ediValueAttributeInfo.IsTrim)
                                {
                                    detailValue = detailValue.PadRight(ediValueAttributeInfo.Picture.Scale, ' ');
                                }
                                else
                                {
                                    if (detailValue != null && detailValue.Length > ediValueAttributeInfo.Picture.Scale)
                                    {
                                        detailValue = detailValue.Substring(0, ediValueAttributeInfo.Picture.Scale);
                                    }
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Hata");
                        }
                        break;

                    case Enums.PictureKind.Numeric:
                        if (propertyInfoDetail.GetValue(objectTypeDetail) == null)
                        {
                            var a = propertyInfoDetail.GetType();
                            detailValue = string.Empty;
                            break;
                        }
                        else
                        {
                            detailValue = propertyInfoDetail.GetValue(objectTypeDetail).ToString();
                        }
                        if (detailValue == "True")
                        {
                            detailValue = "1";
                        }
                        if (detailValue == "False")
                        {
                            detailValue = "0";
                        }
                        if (ediValueAttributeInfo.Format != null)
                        {
                            detailValue = DateTime.Parse(detailValue).ToString(ediValueAttributeInfo.Format);
                            detailValue = detailValue.PadLeft(ediValueAttributeInfo.Picture.Scale, '0');
                        }
                        else
                        {
                            detailValue = detailValue.PadLeft(ediValueAttributeInfo.Picture.Scale, '0');
                        }
                        break;

                    default:
                        break;
                    }
                    if (detailValue != null)
                    {
                        lineInfo += detailValue + Separate;
                    }
                }
            }
            lineInfo = lineInfo.Substring(0, lineInfo.Length - 1) + "~";
            streamWriter.WriteLine(lineInfo);
        }