Methods invoke in .net
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace BindingFlagsCS
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll";
Assembly a = Assembly.LoadFrom(path);
Type hu = a.GetType("System.Web.HttpUtility");
MethodInfo encode = hu.GetMethod("HtmlEncode", new Type[] { typeof(string) });
MethodInfo decode = hu.GetMethod("HtmlDecode", new Type[] { typeof(string) });
String original = "<okey-dokey>";
Console.WriteLine(original);
String encoded = encode.Invoke(null, new object[] { original }) as string;
Console.WriteLine(encoded);
String decoded = decode.Invoke(null, new object[] { encoded }) as string;
Console.WriteLine(decoded);
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace BindingFlagsCS
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll";
Assembly a = Assembly.LoadFrom(path);
Type hu = a.GetType("System.Web.HttpUtility");
MethodInfo encode = hu.GetMethod("HtmlEncode", new Type[] { typeof(string) });
MethodInfo decode = hu.GetMethod("HtmlDecode", new Type[] { typeof(string) });
String original = "<okey-dokey>";
Console.WriteLine(original);
String encoded = encode.Invoke(null, new object[] { original }) as string;
Console.WriteLine(encoded);
String decoded = decode.Invoke(null, new object[] { encoded }) as string;
Console.WriteLine(decoded);
Console.Read();
}
}
}
VB.NET:
Imports System.Reflection
Module Module1
Sub Main()
Dim path As String = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll"
Dim a As Assembly = Assembly.LoadFrom(path)
Dim hu As Type = a.GetType("System.Web.HttpUtility")
Dim encode As MethodInfo = hu.GetMethod("HtmlEncode", New Type() {GetType(String)})
Dim decode As MethodInfo = hu.GetMethod("HtmlDecode", New Type() {GetType(String)})
Dim original As String = "<okey-dokey>"
Console.WriteLine(original)
Dim encoded As String = CType(encode.Invoke(Nothing, New Object() {original}), String)
Console.WriteLine(encoded)
Dim decoded As String = CType(decode.Invoke(Nothing, New Object() {encoded}), String)
Console.WriteLine(decoded)
Console.Read()
End Sub
End Module
Module Module1
Sub Main()
Dim path As String = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll"
Dim a As Assembly = Assembly.LoadFrom(path)
Dim hu As Type = a.GetType("System.Web.HttpUtility")
Dim encode As MethodInfo = hu.GetMethod("HtmlEncode", New Type() {GetType(String)})
Dim decode As MethodInfo = hu.GetMethod("HtmlDecode", New Type() {GetType(String)})
Dim original As String = "<okey-dokey>"
Console.WriteLine(original)
Dim encoded As String = CType(encode.Invoke(Nothing, New Object() {original}), String)
Console.WriteLine(encoded)
Dim decoded As String = CType(decode.Invoke(Nothing, New Object() {encoded}), String)
Console.WriteLine(decoded)
Console.Read()
End Sub
End Module