static void Main(string[] args)
    {
        MyFruit myFruit = new MyFruit()
        {
            Fruits = new List <Fruit>()
            {
                new Apple()
                {
                    Name = "Apple", Size = "Big"
                },
                new Orange()
                {
                    Name = "Orange", Price = 10.00f
                }
            }
        };
        string        xml;
        XmlSerializer xsSubmit = new XmlSerializer(typeof(MyFruit));
        StringWriter  sww      = new StringWriter();

        using (XmlTextWriter writer = new XmlTextWriter(sww))
        {
            writer.Formatting = Formatting.Indented;
            xsSubmit.Serialize(writer, myFruit);
            xml = sww.ToString();
            Console.WriteLine(xml);
        }
    }
    public static MyColor GetColor(this MyFruit fruit)
    {
        var type       = fruit.GetType();
        var memInfo    = type.GetMember(fruit.ToString());
        var attributes = memInfo[0].GetCustomAttributes(typeof(MyFunkyAttribute), false);

        if (attributes.Length > 0)
        {
            return(((MyFunkyAttribute)attributes[0]).Color);
        }
        throw new InvalidOperationException("blah");
    }
Ejemplo n.º 3
0
 public void SimpleEnum(MyFruit fruit)
 {
     Context.Logger.LogInformation(fruit.ToString());
 }