Показаны сообщения с ярлыком Attribute. Показать все сообщения
Показаны сообщения с ярлыком Attribute. Показать все сообщения

понедельник, 14 октября 2019 г.

Serialization/DeSerialization List

https://stackoverflow.com/questions/608110/is-it-possible-to-deserialize-xml-into-listt

https://docs.microsoft.com/ru-ru/dotnet/standard/serialization/controlling-xml-serialization-using-attributes

private void Serialize<T>(XDocument doc, List<T> paramList)
        {
            var serializer = new System.Xml.Serialization.XmlSerializer(paramList.GetType());
            var writer = doc.CreateWriter();
            serializer.Serialize(writer, paramList);
            writer.Close();
        }

        private List<T> Deserialize<T>(XDocument doc)
        {
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<T>));
            var reader = doc.CreateReader();
            var result = (List<T>)serializer.Deserialize(reader);
            reader.Close();
            return result;
        }

https://docs.microsoft.com/ru-ru/dotnet/standard/serialization/examples-of-xml-serialization

вторник, 25 марта 2014 г.

Changing Class Attribute


Copy from Here: 

http://stackoverflow.com/questions/2160476/how-to-set-attributes-values-using-reflection

 AttributeCollection ac  = TypeDescriptor.GetAttributes(yourObj);

        foreach (var att in ac)
        {
            //DataEntityAttribute  -- ur attribute class name
            DataEntityAttribute da = att as DataEntityAttribute ;
            Console.WriteLine(da.field1);  //initially it shows MESSAGE_STAGING
            da.field1= "Test_Message_Staging";  
         }


         //Check the changed value
        AttributeCollection acc = TypeDescriptor.GetAttributes(yourObj);

        foreach (var att in ac)
        {
            DataEntityAttribute da = att as DataEntityAttribute ;
            Console.WriteLine(da.field1); //now it shows Test_Message_Staging
        }