Click here to Skip to main content
15,891,567 members
Articles / Web Development

WPF Two-way Databinding in ASP.NET - Enabling MVVM

Rate me:
Please Sign up or sign in to vote.
4.88/5 (35 votes)
29 Jan 2011CPOL21 min read 139.7K   1.8K   66  
Bringing WPF like declarative data binding to ASP.NET Web Forms to enable declarative two-way data binding to any object whilst opening up MVVM UI development.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;

namespace SDILReader
{
        //public enum AssemblyType
        //{
        //    None,
        //    Console,
        //    Application,
        //    Library
        //}

        //public enum BinaryOperator
        //{
        //    Add,
        //    Subtract,
        //    Multiply,
        //    Divide,
        //    Modulus,
        //    ShiftLeft,
        //    ShiftRight,
        //    IdentityEquality,
        //    IdentityInequality,
        //    ValueEquality,
        //    ValueInequality,
        //    BitwiseOr,
        //    BitwiseAnd,
        //    BitwiseExclusiveOr,
        //    BooleanOr,
        //    BooleanAnd,
        //    LessThan,
        //    LessThanOrEqual,
        //    GreaterThan,
        //    GreaterThanOrEqual
        //}

        //public enum ExceptionHandlerType
        //{
        //    Finally,
        //    Catch,
        //    Filter,
        //    Fault
        //}

        //public enum FieldVisibility
        //{
        //    Private,
        //    Public,
        //    Internal,
        //    Protected,
        //}

        //public enum MethodVisibility
        //{
        //    Private,
        //    Public,
        //    Internal,
        //    External,
        //    Protected,
        //}
        //public enum MethodModifier
        //{
        //    Static,
        //    Override,
        //    Abstract,
        //    Virtual,
        //    Final,
        //    None,
        //}


        //public enum ResourceVisibility
        //{
        //    Public,
        //    Private
        //}

        //public enum TypeVisibility
        //{
        //    vPublic,
        //    vProtected,
        //    vInternal,
        //    vProtectedInternal,
        //    vPrivate
        //}

        //public enum ClassModifiers
        //{
        //    mAbstract,
        //    mSealed,
        //    mStatic,
        //    mNone,
        //}

        //public enum UnaryOperator
        //{
        //    Negate,
        //    BooleanNot,
        //    BitwiseNot,
        //    PreIncrement,
        //    PreDecrement,
        //    PostIncrement,
        //    PostDecrement
        //}



    public static class Globals
    {
        public static Dictionary<int, object> Cache = new Dictionary<int, object>();

        public static OpCode[] multiByteOpCodes;
        public static OpCode[] singleByteOpCodes;
        public static Module[] modules = null;

        public static 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 static string SpaceGenerator(int count)
        //{
        //    string result = "";
        //    for (int i = 0; i < count; i++) result += " ";
        //    return result;
        //}

        //public static string AddBeginSpaces(string source, int count)
        //{
        //    string[] elems = source.Split('\n');
        //    string result = "";
        //    for (int i = 0; i < elems.Length; i++)
        //    {
        //        result += SpaceGenerator(count) + elems[i] + "\n";
        //    }
        //    return result;
        //}
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions