Ejemplo n.º 1
0
        public CodeMethod CreateStaticMethod(string name, Type returnType, params Type[] parameterTypes)
        {
            CodeMethod met = new CodeMethod(this, GetMethodName(name), MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes);

            methods.Add(met);
            return(met);
        }
Ejemplo n.º 2
0
        public CodeMethod CreateMethod(string name, MethodAttributes attributes, Type returnType, params Type[] parameterTypes)
        {
            CodeMethod met = new CodeMethod(this, GetMethodName(name), attributes, returnType, parameterTypes);

            methods.Add(met);
            return(met);
        }
Ejemplo n.º 3
0
        public Type CreateType()
        {
            if (ctor == null)
            {
                ctor = GetDefaultConstructor();
            }

            foreach (CodeProperty prop in properties)
            {
                prop.Generate();
            }

            foreach (CodeMethod met in methods)
            {
                met.Generate();
            }

            Type t = typeBuilder.CreateType();

            foreach (CodeMethod met in methods)
            {
                met.UpdateMethodBase(t);
            }

            foreach (CodeProperty prop in properties)
            {
                prop.UpdatePropertyInfo(t);
            }

            return(t);
        }
Ejemplo n.º 4
0
 public void Call(CodeMethod method, params CodeExpression[] parameters)
 {
     if ((object)method == null)
     {
         throw new ArgumentNullException("method");
     }
     currentBlock.Add(new CodeMethodCall(method, parameters));
 }
Ejemplo n.º 5
0
 public CodeExpression CallFunc(CodeMethod method, params CodeExpression[] parameters)
 {
     if ((object)method == null)
     {
         throw new ArgumentNullException("method");
     }
     return(new CodeMethodCall(method, parameters));
 }
Ejemplo n.º 6
0
 public CodeMethod GetDefaultConstructor()
 {
     if (ctor != null)
     {
         return(ctor);
     }
     ctor = CreateConstructor(MethodAttributes.Public, Type.EmptyTypes);
     return(ctor);
 }
Ejemplo n.º 7
0
        public CodeMethod GetStaticConstructor()
        {
            if (cctor != null)
            {
                return(cctor);
            }
            cctor = CodeMethod.DefineConstructor(this, MethodAttributes.Public | MethodAttributes.Static, Type.EmptyTypes);
            methods.Add(cctor);
            CodeBuilder cb = GetClassInitBuilder();

            cctor.CodeBuilder.CurrentBlock.Add(cb.CurrentBlock);
            return(cctor);
        }
Ejemplo n.º 8
0
        public CodeMethod CreateConstructor(MethodAttributes attributes, params Type[] parameters)
        {
            if (ctor != null)
            {
                return(ctor);
            }
            ctor = CodeMethod.DefineConstructor(this, attributes, parameters);
            methods.Add(ctor);
            CodeBuilder cb = GetInstanceInitBuilder();

            ctor.CodeBuilder.CurrentBlock.Add(cb.CurrentBlock);
            return(ctor);
        }
Ejemplo n.º 9
0
        public CodeMethod ImplementMethod(Type baseType, MethodInfo basem)
        {
            ParameterInfo[] pinfos = basem.GetParameters();
            Type[]          pars   = new Type[pinfos.Length];
            for (int n = 0; n < pinfos.Length; n++)
            {
                pars[n] = pinfos[n].ParameterType;
            }

            CodeMethod met = CodeMethod.DefineMethod(this, basem.Name, MethodAttributes.Public | MethodAttributes.Virtual, basem.ReturnType, pars);

            typeBuilder.DefineMethodOverride(met.MethodInfo, basem);
            methods.Add(met);
            return(met);
        }
Ejemplo n.º 10
0
		public void Call (CodeMethod method, params CodeExpression[] parameters)
		{
			if ((object) method == null)
				throw new ArgumentNullException ("method");
			currentBlock.Add (new CodeMethodCall (method, parameters));
		}
Ejemplo n.º 11
0
		public CodeExpression CallFunc (CodeMethod method, params CodeExpression[] parameters)
		{
			if ((object) method == null)
				throw new ArgumentNullException ("method");
			return new CodeMethodCall (method, parameters);
		}
Ejemplo n.º 12
0
 public CodeMethodCall(CodeMethod method, params CodeExpression[] parameters)
 {
     this.parameters = parameters;
     this.codeMethod = method;
 }
Ejemplo n.º 13
0
		public CodeMethod CreateConstructor (MethodAttributes attributes, params Type[] parameters)
		{
			if (ctor != null) return ctor;
			ctor = CodeMethod.DefineConstructor (this, attributes, parameters);
			methods.Add (ctor);
			CodeBuilder cb = GetInstanceInitBuilder ();
			ctor.CodeBuilder.CurrentBlock.Add (cb.CurrentBlock);
			return ctor;
		}
Ejemplo n.º 14
0
Archivo: Exp.cs Proyecto: zgramana/mono
 public static CodeExpression Call(CodeExpression target, CodeMethod method, params CodeExpression[] parameters)
 {
     return(new CodeMethodCall(target, method, parameters));
 }
Ejemplo n.º 15
0
		public CodeMethod GetDefaultConstructor ()
		{
			if (ctor != null) return ctor;
			ctor = CreateConstructor (MethodAttributes.Public, Type.EmptyTypes);
			return ctor;
		}
Ejemplo n.º 16
0
		public CodeMethod CreateMethod (string name, MethodAttributes attributes, Type returnType, params Type[] parameterTypes)
		{
			CodeMethod met = new CodeMethod (this, GetMethodName (name), attributes, returnType, parameterTypes);
			methods.Add (met);
			return met;
		}
Ejemplo n.º 17
0
		public CodeMethod CreateStaticMethod (string name, Type returnType, params Type[] parameterTypes)
		{
			CodeMethod met = new CodeMethod (this, GetMethodName (name), MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes);
			methods.Add (met);
			return met;
		}
Ejemplo n.º 18
0
        public void PrintCode(CodeWriter cw)
        {
            for (int n = 0; n < customAttributes.Count; n++)
            {
                CodeCustomAttribute cca = customAttributes [n] as CodeCustomAttribute;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                cca.PrintCode(cw);
            }

/*			if ((typeBuilder.Attributes & TypeAttributes.Abstract) != 0) cw.Write ("abstract ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedAssembly) != 0) cw.Write ("internal ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedPrivate) != 0) cw.Write ("private ");
 */         if ((typeBuilder.Attributes & TypeAttributes.Public) != 0)
            {
                cw.Write("public ");
            }
            cw.Write("class ").Write(typeBuilder.Name);

            bool dots = false;

            if (baseType != null && baseType != typeof(object))
            {
                cw.Write(" : " + baseType);
                dots = true;
            }

            if (interfaces != null && interfaces.Length > 0)
            {
                if (!dots)
                {
                    cw.Write(" : ");
                }
                else
                {
                    cw.Write(", ");
                }
                for (int n = 0; n < interfaces.Length; n++)
                {
                    if (n > 0)
                    {
                        cw.Write(", ");
                    }
                    cw.Write(interfaces[n].ToString());
                }
            }

            cw.EndLine().WriteLineInd("{");

            foreach (FieldInfo f in fields)
            {
                cw.BeginLine();
                ArrayList atts = (ArrayList)fieldAttributes [f];
                foreach (CodeCustomAttribute a in atts)
                {
                    a.PrintCode(cw);
                }
                if ((f.Attributes & FieldAttributes.Static) != 0)
                {
                    cw.Write("static ");
                }
                cw.Write(f.FieldType.Name + " ");
                cw.Write(f.Name + ";");
                cw.EndLine();
                cw.WriteLine("");
            }

            for (int n = 0; n < properties.Count; n++)
            {
                CodeProperty prop = properties [n] as CodeProperty;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                prop.PrintCode(cw);
            }

            for (int n = 0; n < methods.Count; n++)
            {
                CodeMethod met = methods[n] as CodeMethod;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                met.PrintCode(cw);
            }
            cw.WriteLineUnind("}");
        }
Ejemplo n.º 19
0
		public CodeMethodCall (CodeMethod method, params CodeExpression[] parameters)
		{
			this.parameters = parameters;
			this.codeMethod = method;
		}
Ejemplo n.º 20
0
		public CodeMethod GetStaticConstructor ()
		{
			if (cctor != null) return cctor;
			cctor = CodeMethod.DefineConstructor (this, MethodAttributes.Public | MethodAttributes.Static, Type.EmptyTypes);
			methods.Add (cctor);
			CodeBuilder cb = GetClassInitBuilder ();
			cctor.CodeBuilder.CurrentBlock.Add (cb.CurrentBlock);
			return cctor;
		}
Ejemplo n.º 21
0
 public static void GenerateMethodCall(ILGenerator gen, CodeExpression target, CodeMethod method, params CodeExpression[] parameters)
 {
     GenerateMethodCall(gen, target, method.MethodBase, method.ParameterTypes, parameters);
 }
Ejemplo n.º 22
0
		public Type CreateType ()
		{
			if (ctor == null)
				ctor = GetDefaultConstructor ();
				
			foreach (CodeProperty prop in properties)
				prop.Generate ();

			foreach (CodeMethod met in methods)
				met.Generate ();
				
			Type t = typeBuilder.CreateType ();
			
			foreach (CodeMethod met in methods)
				met.UpdateMethodBase (t);
				
			foreach (CodeProperty prop in properties)
				prop.UpdatePropertyInfo (t);

			return t;
		}
Ejemplo n.º 23
0
		static CodePropertyReference GetOperationMethod (CodeMethod m, CodeBuilder b, string name, string methodPropertyName)
		{
			return new CodePropertyReference (
				b.CallFunc (
					// this.Contract.Operations
					new CodePropertyReference (
						new CodePropertyReference (
							m.GetThis (),
							typeof (ClientRuntimeChannel).GetProperty ("Contract")),
						typeof (ContractDescription).GetProperty ("Operations")),
					// .Find (name)
					typeof (OperationDescriptionCollection).GetMethod ("Find"),
					new CodeLiteral (name)),
				// .SyncMethod
				typeof (OperationDescription).GetProperty (methodPropertyName));
		}
Ejemplo n.º 24
0
Archivo: Exp.cs Proyecto: nickchal/pash
		public static CodeExpression Call (CodeMethod method, params CodeExpression[] parameters)
		{
			return new CodeMethodCall (method, parameters);
		}
Ejemplo n.º 25
0
		public static void GenerateMethodCall (ILGenerator gen, CodeExpression target, CodeMethod method, params CodeExpression[] parameters)
		{
			GenerateMethodCall (gen, target, method.MethodBase, method.ParameterTypes, parameters);
		}