Search Results

Search found 6 results on 1 pages for 'entrase'.

Page 1/1 | 1 

  • .NET and XML: How can I read nested namespaces (<abc:xyz:name attr="value"/>)?

    - by Entrase
    Suppose there is an element in XML data: <abc:xyz:name attr="value"/> I'm trying to read it with XmlReader. The problem is that I get XmlException that says The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name I have already declared "abc" namespace. I have also tried adding "abc:xyz" and "xyz" namespaces. But this doesn't help at all. I could replace some text before parsing but there may be some more elegant solution. So what should I do? Here is my code: XmlReaderSettings settings = new XmlReaderSettings() NameTable nt = new NameTable(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); nsmgr.AddNamespace("abc", ""); nsmgr.AddNamespace("xyz", ""); XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); // So this reader can't read <abc:xyz:name attr="value"/> XmlReader reader = XmlReader.Create(path, settings, context);“

    Read the article

  • .NET: How to pass value when subscribing to event and obtain it when the event is triggered (Dynamic

    - by Entrase
    The task is to create event handlers in runtime. I need the one method to be called with different parameter value for different events. The events and their number are only known in runtime. So I'm trying to generate dynamic methods, each of which will be assigned to some event, but in general they all just pass some value to an instance method and call it. It would be great if something similar could be done the easier way. I mean passing some value at subscribing stage and then obtaining it when the event is triggered. This is what I'm trying to do now: public class EventSource { public event EventHandler eventOne; public event EventHandler eventTwO; public event EventHandler eventThree; } public class EventListener { SubscribeForEvents() { BindingFlags flags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance; // Suppose we've already got EventInfo // and target source somewhere // so we can do eventInfo.AddEventHandler(target, delegate) // Now we need a delegate. int value = 42; Type tDelegate = eventInfo.EventHandlerType; // http://msdn.microsoft.com/en-us/library/ms228976(VS.95).aspx Type returnType = GetDelegateReturnType(tDelegate); DynamicMethod listener = new DynamicMethod("", null, GetDelegateParameterTypes(tDelegate), this.GetType()); ///////// Type[] callParameters = { typeof(int) }; MethodInfo method = this.GetType().GetMethod("ToCallFromDelegate", flags); ILGenerator generator = listener.GetILGenerator(); // No success in this mess. What's wrong? generator.Emit(OpCodes.Ldc_I4, value); generator.Emit(OpCodes.Call, method); generator.Emit(OpCodes.Pop); generator.Emit(OpCodes.Ret); ///////////// Delegate delegate = listener.CreateDelegate(tDelegate); eventInfo.AddEventHandler(target, delegate); // When triggered, there is InvalidProgramException } void ToCallFromDelegate(int value) { doSomething(); } }

    Read the article

  • XML and .NET: How to replace specific node with many other ones loaded from raw xml data

    - by Entrase
    Let's suppose we have an element like this one in the main xml file: <group name="gr1" filename="groups/gr1.xml"/>. The second file gr1.xml contains something like this: <item name="i1">Item one</item> <item name="i2">Item two</item> <item name="i3">Item three</item> Note that there is no XML declaration in gr1.xml, just plain items without single parent node. So… Which is the best way to replace <group/> with its <item/>s? I have already tried some things like manual enclosing of gr1.xml content into a single node with XML declaration and loading it into XmlDocument, but it doesn't look like a good solution.

    Read the article

1