Exemplo n.º 1
0
        //----------------------------------------------------------------------------------------

        private static void append_class_begin(StringBuilder sb, Type type, AopCoderDialect dialect)
        {
            sb.AppendFormat("\tpublic class {0} : {1} ", dialect.GetClassFullName(type, ""), type.Name);
            sb.Append("{");
            sb.AppendLine();
            sb.AppendLine();
        }
Exemplo n.º 2
0
        private static void append_method_before(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            if (x.Method.GetParameters().Length > 0)
            {
                sb.AppendFormat("\t\t\tMethodInfo m = {0}.GetType().GetMethod( \"{1}\", {2} );", dialect.GetInvokeTargetThis(), x.Method.Name, "new Type[] {" + getArgType(x.Method) + "}");
            }
            else
            {
                sb.AppendFormat("\t\t\tMethodInfo m = {0}.GetType().GetMethod( \"{1}\", {2} );", dialect.GetInvokeTargetThis(), x.Method.Name, "new Type[]{}");
            }
            sb.AppendLine();

            sb.AppendFormat("\t\t\tObject[] args = {0};", getArgArray(x.Method));
            sb.AppendLine();

            List <MethodObserver> osList = getMethodObserver(x.ObservedType.Type, x.Method.Name);
            int i = 1;

            foreach (MethodObserver os in osList)
            {
                sb.AppendFormat("\t\t\t{0} observer{1} = {2};", os.GetType().FullName, i, getObserverCreator(os));
                sb.AppendLine();
                sb.AppendFormat("\t\t\tobserver{0}.Before( m, args, {1} );", i, dialect.GetInvokeTargetThis());
                sb.AppendLine();
                i++;
            }
        }
Exemplo n.º 3
0
 //----------------------------------------------------------------------------------------
 private static void append_class_begin( StringBuilder sb, Type type, AopCoderDialect dialect )
 {
     sb.AppendFormat( "\tpublic class {0} : {1} ", dialect.GetClassFullName( type, "" ), type.Name );
     sb.Append( "{" );
     sb.AppendLine();
     sb.AppendLine();
 }
Exemplo n.º 4
0
        private static void append_method_invoke(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            sb.Append("\t\t\tObject returnValue = null;");
            sb.AppendLine();

            List <MethodObserver> osList = getMethodObserver(x.ObservedType.Type, x.Method.Name);

            String strReturn = getReturnString(x.Method);

            if (strReturn == "void")
            {
                strReturn = "";
            }
            else
            {
                strReturn = "returnValue = ";
            }

            int invokeObserverIndex = getInovkeObserverIndex(osList);

            if (invokeObserverIndex > -1)
            {
                append_invoke_object(sb, x, dialect);
                sb.AppendFormat("\t\t\t{0}observer{1}.Invoke( invocation );", strReturn, invokeObserverIndex);
                sb.AppendLine();
            }
            else
            {
                sb.AppendFormat("\t\t\t{0}{1}.{2}({3});", strReturn, dialect.GetInvokeTargetBase(), x.Method.Name, getArgBodyFromArray(x.Method));
                sb.AppendLine();
            }
        }
Exemplo n.º 5
0
        private static void append_interface_class_begin( StringBuilder sb, Type type, AopCoderDialect dialect, String interfaceFullName )
        {
            sb.AppendFormat( "\tpublic class {0} : {1} ", dialect.GetClassFullName( type, interfaceFullName ), interfaceFullName );
            sb.Append( "{" );
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendFormat( "\t\tprivate {0} _{1};", interfaceFullName, dialect.GetInvokeTargetBase() );
            sb.AppendLine();

            sb.AppendFormat( "\t\tpublic {0} {1} ", interfaceFullName, dialect.GetInvokeTargetBase() );
            sb.Append( "{" );
            sb.AppendLine();

            sb.Append( "\t\t\tget { return _" + dialect.GetInvokeTargetBase() + "; }" );
            sb.AppendLine();

            sb.Append( "\t\t\tset { _" + dialect.GetInvokeTargetBase() + " = value; }" );
            sb.AppendLine();

            sb.Append( "\t\t}" );
            sb.AppendLine();

            sb.AppendLine();
        }
Exemplo n.º 6
0
 public Object Proceed()
 {
     if (this.IsSubClass)
     {
         return(rft.CallMethod(Target, AopCoderDialect.GetBasePrefixOne() + Method.Name, Args));
     }
     else
     {
         return(rft.CallMethod(Target, Method.Name, Args));
     }
 }
Exemplo n.º 7
0
        private static void append_method_after(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            List <MethodObserver> osList = getMethodObserver(x.ObservedType.Type, x.Method.Name);
            int i = 1;

            foreach (MethodObserver os in osList)
            {
                sb.AppendFormat("\t\t\tobserver{0}.After( returnValue, m, args, {1} );", i, dialect.GetInvokeTargetThis());
                sb.AppendLine();
                i++;
            }
        }
Exemplo n.º 8
0
        private static void append_method_single(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            String strArgs   = getArgString(x.Method);
            String strReturn = getReturnString(x.Method);

            append_method_begin(sb, x, strArgs, strReturn, dialect);
            append_method_before(sb, x, dialect);

            append_method_invoke(sb, x, dialect);

            append_method_after(sb, x, dialect);
            append_method_end(sb, x);
        }
Exemplo n.º 9
0
        private static void append_invoke_object(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            sb.Append("\t\t\tIMethodInvocation invocation = new MethodInvocation();");
            sb.AppendLine();

            sb.Append("\t\t\tinvocation.Method = m;");
            sb.AppendLine();

            sb.AppendFormat("\t\t\tinvocation.Args = args;");
            sb.AppendLine();

            sb.AppendFormat("\t\t\tinvocation.Target = {0};", dialect.GetInvokeTargetThis());
            sb.AppendLine();

            sb.AppendFormat("\t\t\tinvocation.IsSubClass = {0};", dialect.IsSubClassStr());
            sb.AppendLine();
        }
Exemplo n.º 10
0
        // 不在监控中的、接口必须包含的方法
        private static void append_interface_methods_other( StringBuilder sb, KeyValuePair<Type, ObservedType> kv, AopCoderDialect dialect, Type interfaceType ) {

            MethodInfo[] methods = interfaceType.GetMethods();
            foreach (MethodInfo m in methods) {

                if (isMethodCoded( m, kv.Value.MethodList )) continue;

                if (rft.IsMethodProperty( m )) {
                    continue;
                }

                append_interface_methods_other_single( sb, m, dialect );
            }

            PropertyInfo[] properties = interfaceType.GetProperties();
            foreach (PropertyInfo p in properties) {
                append_interface_properties_other_single( sb, p, dialect );
            }
        }
Exemplo n.º 11
0
        private static void append_method_before( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
        {
            if (x.Method.GetParameters().Length > 0) {
                sb.AppendFormat( "\t\t\tMethodInfo m = {0}.GetType().GetMethod( \"{1}\", {2} );", dialect.GetInvokeTargetThis(), x.Method.Name, "new Type[] {" + getArgType( x.Method ) + "}" );
            }
            else {

                sb.AppendFormat( "\t\t\tMethodInfo m = {0}.GetType().GetMethod( \"{1}\", {2} );", dialect.GetInvokeTargetThis(), x.Method.Name, "new Type[]{}" );
            }
            sb.AppendLine();

            sb.AppendFormat( "\t\t\tObject[] args = {0};", getArgArray( x.Method ) );
            sb.AppendLine();

            List<MethodObserver> osList = getMethodObserver( x.ObservedType.Type, x.Method.Name );
            int i = 1;
            foreach (MethodObserver os in osList) {
                sb.AppendFormat( "\t\t\t{0} observer{1} = {2};", os.GetType().FullName, i, getObserverCreator( os ) );
                sb.AppendLine();
                sb.AppendFormat( "\t\t\tobserver{0}.Before( m, args, {1} );", i, dialect.GetInvokeTargetThis() );
                sb.AppendLine();
                i++;
            }
        }
Exemplo n.º 12
0
 //----------------------------------------------------------------------------------------
 private static void append_method_begin( StringBuilder sb, ObservedMethod x, String strArgs, String strReturn, AopCoderDialect dialect )
 {
     sb.AppendFormat( "\t\tpublic {0} {1} {2}( {3} ) ", dialect.GetMethodOverride(), strReturn, x.Method.Name, strArgs );
     sb.Append( "{" );
     sb.AppendLine();
 }
Exemplo n.º 13
0
 private static void append_method_after( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
 {
     List<MethodObserver> osList = getMethodObserver( x.ObservedType.Type, x.Method.Name );
     int i = 1;
     foreach (MethodObserver os in osList) {
         sb.AppendFormat( "\t\t\tobserver{0}.After( returnValue, m, args, {1} );", i, dialect.GetInvokeTargetThis() );
         sb.AppendLine();
         i++;
     }
 }
Exemplo n.º 14
0
        private static void append_method_base_single( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
        {
            String strReturn = getReturnString( x.Method );
            String strArg = getArgString( x.Method );
            String strArgBody = getArgBody( x.Method );

            sb.AppendFormat( "\t\tpublic {0} {1}{2}({3}) ", strReturn, dialect.GetMethodBasePrefix(), x.Method.Name, strArg );
            sb.Append( "{" );
            sb.AppendLine();

            String strReturnLable = strReturn == "void" ? "" : "return ";

            sb.AppendFormat( "\t\t\t{0}{1}.{2}( {3} );", strReturnLable, dialect.GetInvokeTargetBase(), x.Method.Name, strArgBody );
            sb.AppendLine();

            sb.Append( "\t\t}" );
            sb.AppendLine();
            sb.AppendLine();
        }
Exemplo n.º 15
0
 private static void append_interface_methods_base(StringBuilder sb, KeyValuePair <Type, ObservedType> kv, AopCoderDialect dialect)
 {
     foreach (ObservedMethod x in kv.Value.MethodList)
     {
         append_method_base_single(sb, x, dialect);
     }
 }
Exemplo n.º 16
0
        private static void append_methods_base( StringBuilder sb, KeyValuePair<Type, ObservedType> kv, AopCoderDialect dialect )
        {
            foreach (ObservedMethod x in kv.Value.MethodList) {

                if (x.Method.IsVirtual == false) continue;

                append_method_base_single( sb, x, dialect );
            }
        }
Exemplo n.º 17
0
        private static void append_interface_methods_other_single( StringBuilder sb, MethodInfo m, AopCoderDialect dialect )
        {
            String strReturn = getReturnString( m );
            String strArgs = getArgString( m );
            String strArgBody = getArgBody( m );

            sb.AppendFormat( "\t\tpublic {0} {1} ( {2} ) ", strReturn, m.Name, strArgs );
            sb.Append( "{" );
            sb.AppendLine();

            String strReturnLabel = getReturnString( m );
            strReturnLabel = (strReturnLabel == "void" ? "" : "return ");

            sb.AppendFormat( "\t\t\t{3}{0}.{1}({2});", dialect.GetInvokeTargetThis(), m.Name, strArgBody, strReturnLabel );
            sb.AppendLine();

            sb.Append( "\t\t}" );
            sb.AppendLine();
            sb.AppendLine();
        }
Exemplo n.º 18
0
 private static void append_interface_properties_other_single(StringBuilder sb, PropertyInfo p, AopCoderDialect dialect)
 {
     sb.AppendLine("\t\tpublic " + p.PropertyType.FullName + " " + p.Name + " {");
     if (p.CanRead)
     {
         sb.AppendLine("\t\t\tget { return " + dialect.GetInvokeTargetThis() + "." + p.Name + ";}");
     }
     if (p.CanWrite)
     {
         sb.AppendLine("\t\t\tset { " + dialect.GetInvokeTargetThis() + "." + p.Name + " = value;}");
     }
     sb.AppendLine("\t\t}");
     sb.AppendLine();
 }
Exemplo n.º 19
0
        // 不在监控中的、接口必须包含的方法
        private static void append_interface_methods_other(StringBuilder sb, KeyValuePair <Type, ObservedType> kv, AopCoderDialect dialect, Type interfaceType)
        {
            MethodInfo[] methods = interfaceType.GetMethods();
            foreach (MethodInfo m in methods)
            {
                if (isMethodCoded(m, kv.Value.MethodList))
                {
                    continue;
                }

                if (rft.IsMethodProperty(m))
                {
                    continue;
                }

                append_interface_methods_other_single(sb, m, dialect);
            }

            PropertyInfo[] properties = interfaceType.GetProperties();
            foreach (PropertyInfo p in properties)
            {
                append_interface_properties_other_single(sb, p, dialect);
            }
        }
Exemplo n.º 20
0
 private static void append_interface_methods_base( StringBuilder sb, KeyValuePair<Type, ObservedType> kv, AopCoderDialect dialect )
 {
     foreach (ObservedMethod x in kv.Value.MethodList) {
         append_method_base_single( sb, x, dialect );
     }
 }
Exemplo n.º 21
0
        private static void append_interface_methods_other_single(StringBuilder sb, MethodInfo m, AopCoderDialect dialect)
        {
            String strReturn  = getReturnString(m);
            String strArgs    = getArgString(m);
            String strArgBody = getArgBody(m);

            sb.AppendFormat("\t\tpublic {0} {1} ( {2} ) ", strReturn, m.Name, strArgs);
            sb.Append("{");
            sb.AppendLine();

            String strReturnLabel = getReturnString(m);

            strReturnLabel = (strReturnLabel == "void" ? "" : "return ");

            sb.AppendFormat("\t\t\t{3}{0}.{1}({2});", dialect.GetInvokeTargetThis(), m.Name, strArgBody, strReturnLabel);
            sb.AppendLine();

            sb.Append("\t\t}");
            sb.AppendLine();
            sb.AppendLine();
        }
Exemplo n.º 22
0
        private static void append_interface_class_begin(StringBuilder sb, Type type, AopCoderDialect dialect, String interfaceFullName)
        {
            sb.AppendFormat("\tpublic class {0} : {1} ", dialect.GetClassFullName(type, interfaceFullName), interfaceFullName);
            sb.Append("{");
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendFormat("\t\tprivate {0} _{1};", interfaceFullName, dialect.GetInvokeTargetBase());
            sb.AppendLine();

            sb.AppendFormat("\t\tpublic {0} {1} ", interfaceFullName, dialect.GetInvokeTargetBase());
            sb.Append("{");
            sb.AppendLine();

            sb.Append("\t\t\tget { return _" + dialect.GetInvokeTargetBase() + "; }");
            sb.AppendLine();

            sb.Append("\t\t\tset { _" + dialect.GetInvokeTargetBase() + " = value; }");
            sb.AppendLine();

            sb.Append("\t\t}");
            sb.AppendLine();

            sb.AppendLine();
        }
Exemplo n.º 23
0
        private static void append_methods_base(StringBuilder sb, KeyValuePair <Type, ObservedType> kv, AopCoderDialect dialect)
        {
            foreach (ObservedMethod x in kv.Value.MethodList)
            {
                if (x.Method.IsVirtual == false)
                {
                    continue;
                }

                append_method_base_single(sb, x, dialect);
            }
        }
Exemplo n.º 24
0
        private static void append_method_invoke( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
        {
            sb.Append( "\t\t\tObject returnValue = null;" );
            sb.AppendLine();

            List<MethodObserver> osList = getMethodObserver( x.ObservedType.Type, x.Method.Name );

            String strReturn = getReturnString( x.Method );
            if (strReturn == "void") {
                strReturn = "";
            }
            else {
                strReturn = "returnValue = ";
            }

            int invokeObserverIndex = getInovkeObserverIndex( osList );

            if (invokeObserverIndex > -1) {
                append_invoke_object( sb, x, dialect );
                sb.AppendFormat( "\t\t\t{0}observer{1}.Invoke( invocation );", strReturn, invokeObserverIndex );
                sb.AppendLine();
            }
            else {
                sb.AppendFormat( "\t\t\t{0}{1}.{2}({3});", strReturn, dialect.GetInvokeTargetBase(), x.Method.Name, getArgBodyFromArray( x.Method ) );
                sb.AppendLine();
            }
        }
Exemplo n.º 25
0
 private static void append_interface_properties_other_single( StringBuilder sb, PropertyInfo p, AopCoderDialect dialect )
 {
     sb.AppendLine( "\t\tpublic " + p.PropertyType.FullName + " " + p.Name + " {" );
     if (p.CanRead) {
         sb.AppendLine( "\t\t\tget { return " + dialect.GetInvokeTargetThis() + "." + p.Name + ";}" );
     }
     if (p.CanWrite) {
         sb.AppendLine( "\t\t\tset { " + dialect.GetInvokeTargetThis() + "." + p.Name + " = value;}" );
     }
     sb.AppendLine( "\t\t}" );
     sb.AppendLine();
 }
Exemplo n.º 26
0
        private static void append_method_single( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
        {
            String strArgs = getArgString( x.Method );
            String strReturn = getReturnString( x.Method );

            append_method_begin( sb, x, strArgs, strReturn, dialect );
            append_method_before( sb, x, dialect );

            append_method_invoke( sb, x, dialect );

            append_method_after( sb, x, dialect );
            append_method_end( sb, x );
        }
Exemplo n.º 27
0
        private static void append_invoke_object( StringBuilder sb, ObservedMethod x, AopCoderDialect dialect )
        {
            sb.Append( "\t\t\tIMethodInvocation invocation = new MethodInvocation();" );
            sb.AppendLine();

            sb.Append( "\t\t\tinvocation.Method = m;" );
            sb.AppendLine();

            sb.AppendFormat( "\t\t\tinvocation.Args = args;" );
            sb.AppendLine();

            sb.AppendFormat( "\t\t\tinvocation.Target = {0};", dialect.GetInvokeTargetThis() );
            sb.AppendLine();

            sb.AppendFormat( "\t\t\tinvocation.IsSubClass = {0};", dialect.IsSubClassStr() );
            sb.AppendLine();
        }
Exemplo n.º 28
0
        //----------------------------------------------------------------------------------------

        private static void append_method_begin(StringBuilder sb, ObservedMethod x, String strArgs, String strReturn, AopCoderDialect dialect)
        {
            sb.AppendFormat("\t\tpublic {0} {1} {2}( {3} ) ", dialect.GetMethodOverride(), strReturn, x.Method.Name, strArgs);
            sb.Append("{");
            sb.AppendLine();
        }
Exemplo n.º 29
0
        private static void append_method_base_single(StringBuilder sb, ObservedMethod x, AopCoderDialect dialect)
        {
            String strReturn  = getReturnString(x.Method);
            String strArg     = getArgString(x.Method);
            String strArgBody = getArgBody(x.Method);

            sb.AppendFormat("\t\tpublic {0} {1}{2}({3}) ", strReturn, dialect.GetMethodBasePrefix(), x.Method.Name, strArg);
            sb.Append("{");
            sb.AppendLine();

            String strReturnLable = strReturn == "void" ? "" : "return ";

            sb.AppendFormat("\t\t\t{0}{1}.{2}( {3} );", strReturnLable, dialect.GetInvokeTargetBase(), x.Method.Name, strArgBody);
            sb.AppendLine();

            sb.Append("\t\t}");
            sb.AppendLine();
            sb.AppendLine();
        }