forum

home / developersection / forums / what is managed way to use a variable's pointer in structure?

what is managed way to use a variable's pointer in structure?

Anonymous User 1997 03-Nov-2014

Hi Guys

i'm trying to write a generic function which should be able to parse a xml file

here is the code

        public struct XmlArg
        {
            public string Name;
            public Type T;
            public object Value;
        };
 
        static bool ParseXmlArgs(XmlReader xml, params XmlArg[] args)
        {
            for (int i = 0; i < args.Length; ++i)
            {
                if (xml.MoveToContent() != XmlNodeType.Element || xml.Name != args[i].Name)
                {
                    return false;
                }
                args[i].Value = xml.ReadElementContentAs(args[i].T, null);
            }
            return true;
        }
 
        static void Main(string[] args)
        {
            int a = 0;
 
            ParseXmlArgs(
                XmlTextReader.Create("C:\\Users\\Yazilim\\Desktop\\XML.xml"),
                new XmlArg[]{
            new XmlArg() { Name = "ErrorCode", T = typeof(int), Value = a}});
        }

i know that i should pass a's pointer to Value ( it's type should be some different type other than object of course )

but i don't want it to be non-managed way.

is there any managed way to use a variable's pointer in structure ?

Thanks


Updated on 04-Nov-2014

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By