调试空指针错误2

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.IO;
using System.Runtime.InteropServices;

namespace StaticTest
{

 

    public class MyClass
    {
        public int Value;
    }

    public static class TestClass
    {
        public static void Test1(MyClass myClass)
        {
            myClass.Value = 1;
            HttpContext.Current.Response.Write(myClass.Value.ToString() + ",");
        }

        public static void Test2(ref MyClass myClass)
        {
            myClass = new MyClass();
            myClass.Value = 2;
            HttpContext.Current.Response.Write(myClass.Value.ToString() + ",");
        }

        public static void Test3(MyClass myClass)
        {
            myClass = new MyClass();
            myClass.Value = 3;
            HttpContext.Current.Response.Write(myClass.Value.ToString() + ",");
        }

        public static void Test4(string str)
        {
            str = "4";
            HttpContext.Current.Response.Write(str + ",");
        }

        public static void Test5(ref string str)
        {
            str = "5";
            HttpContext.Current.Response.Write(str + ",");
        }

        public static void Test6(out string str, string str2)
        {
            str = str2;
            HttpContext.Current.Response.Write(str + ",");
        }

        public static void Test7(int integer)
        {
            integer = 6;
            HttpContext.Current.Response.Write(integer.ToString() + ",");
        }
    }

    [Flags]
    enum fabric
    {
        cotton = 1,
        silk = 2,
        wool = 4,
        rayon = 8,
        other = 128,
    }

    public partial class _Default : System.Web.UI.Page
    {
        private string _name;
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            GetData();

 

 

            // fabric fab = fabric.cotton | fabric.wool;
            // Response.Write(fab);//output:cotton,wool 

            //MyClass myClass = new MyClass();
            //myClass.Value = 0;
            //string str = "0";
            //int integer = 0;

            //TestClass.Test1(myClass);
            //Response.Write(myClass.Value.ToString() + ",");
            //TestClass.Test2(ref myClass);
            //Response.Write(myClass.Value.ToString() + ",");
            //TestClass.Test3(myClass);
            //Response.Write(myClass.Value.ToString() + ",");

            //TestClass.Test4(str);
            //Response.Write(str + ",");
            //TestClass.Test5(ref str);
            //Response.Write(str + ",");
            //TestClass.Test6(out str, "8");
            //Response.Write(str.ToString() + ",");
            //TestClass.Test7(integer);
            //Response.Write(integer.ToString());
        }

        private void GetData()
        {

            try
            {
                VbService service = new VbService();
                service = null;
                string[] str = service.getAreaString();
                foreach (string s in str)
                {
                    ddl.Items.Add(s);
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('"+ex.Message+"');</script>");
            }
            //try
            //{
             
            //}
            //catch (Exception ex)
            //{
            //     //获取调用堆栈

            //    StackTrace trace = new StackTrace(ex, true);

            //    StackFrame frame = trace.GetFrame(0);

            //    int offset = frame.GetILOffset();

            //    byte[] il = frame.GetMethod().GetMethodBody().GetILAsByteArray();


            //    //获取调用指令

            //    offset++;

            //    ushort instruction = il[offset++];


            //    //打开潘多拉魔盒

            //    ILGlobals global = new ILGlobals();

            //    global.LoadOpCodes();


            //    //翻译

            //    OpCode code = OpCodes.Nop;

            //    if (instruction != 0xfe)
            //    {
            //        code = global.SingleByteOpCodes[(int)instruction];
            //    }
            //    else
            //    {
            //        instruction = il[offset++];
            //        code = global.MultiByteOpCodes[(int)instruction];
            //        instruction = (ushort)(instruction | 0xfe00);
            //    }


            //    //获取方法信息

            //    int metadataToken = Marshal.ReadInt32(il,  offset);

            //    MethodBase callmethod = frame.GetMethod().Module.ResolveMethod(metadataToken,
            //         frame.GetMethod().DeclaringType.GetGenericArguments(),
            //         frame.GetMethod().GetGenericArguments());

            //    //完成
            //    string str = callmethod.DeclaringType + "." + callmethod.Name ;
            //    Response.Write("<script>alert('"+str+"');</script>");

            //    Console.WriteLine(callmethod.DeclaringType + "." + callmethod.Name);

            //    Console.Read();

            //}
        }

        public class ILGlobals
        {
            private OpCode[] multiByteOpCodes;

            private OpCode[] singleByteOpCodes;

            /// <summary>
            /// Loads the OpCodes for later use.
            /// </summary>
            public void LoadOpCodes()
            {
                singleByteOpCodes = new OpCode[0x100];
                multiByteOpCodes = new OpCode[0x100];
                FieldInfo[] infoArray1 = typeof(OpCodes).GetFields();
                for (int num1 = 0; num1 < infoArray1.Length; num1++)
                {
                    FieldInfo info1 = infoArray1[num1];
                    if (info1.FieldType == typeof(OpCode))
                    {
                        OpCode code1 = (OpCode)info1.GetValue(null);
                        ushort num2 = (ushort)code1.Value;
                        if (num2 < 0x100)
                        {
                            singleByteOpCodes[(int)num2] = code1;
                        }
                        else
                        {
                            if ((num2 & 0xff00) != 0xfe00)
                            {
                                throw new Exception("Invalid OpCode.");
                            }
                            multiByteOpCodes[num2 & 0xff] = code1;
                        }
                    }
                }
            }

            /// <summary>
            /// Retrieve the friendly name of a type
            /// </summary>
            /// <param name="typeName">
            /// The complete name to the type
            /// </param>
            /// <returns>
            /// The simplified name of the type (i.e. "int" instead f System.Int32)
            /// </returns>
            public static string ProcessSpecialTypes(string typeName)
            {
                string result = typeName;
                switch (typeName)
                {
                    case "System.string":
                    case "System.String":
                    case "String":
                        result = "string"; break;
                    case "System.Int32":
                    case "Int":
                    case "Int32":
                        result = "int"; break;
                }
                return result;
            }


            public OpCode[] MultiByteOpCodes
            {
                get { return multiByteOpCodes; }
            }

            public OpCode[] SingleByteOpCodes
            {
                get { return singleByteOpCodes; }
            }
        }

    }

}

你可能感兴趣的:(调试空指针错误2)