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); }
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); }
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); }
public void Call(CodeMethod method, params CodeExpression[] parameters) { if ((object)method == null) { throw new ArgumentNullException("method"); } currentBlock.Add(new CodeMethodCall(method, parameters)); }
public CodeExpression CallFunc(CodeMethod method, params CodeExpression[] parameters) { if ((object)method == null) { throw new ArgumentNullException("method"); } return(new CodeMethodCall(method, parameters)); }
public CodeMethod GetDefaultConstructor() { if (ctor != null) { return(ctor); } ctor = CreateConstructor(MethodAttributes.Public, Type.EmptyTypes); return(ctor); }
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); }
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); }
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); }
public void Call (CodeMethod method, params CodeExpression[] parameters) { if ((object) method == null) throw new ArgumentNullException ("method"); currentBlock.Add (new CodeMethodCall (method, parameters)); }
public CodeExpression CallFunc (CodeMethod method, params CodeExpression[] parameters) { if ((object) method == null) throw new ArgumentNullException ("method"); return new CodeMethodCall (method, parameters); }
public CodeMethodCall(CodeMethod method, params CodeExpression[] parameters) { this.parameters = parameters; this.codeMethod = method; }
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; }
public static CodeExpression Call(CodeExpression target, CodeMethod method, params CodeExpression[] parameters) { return(new CodeMethodCall(target, method, parameters)); }
public CodeMethod GetDefaultConstructor () { if (ctor != null) return ctor; ctor = CreateConstructor (MethodAttributes.Public, Type.EmptyTypes); return ctor; }
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; }
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; }
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("}"); }
public CodeMethodCall (CodeMethod method, params CodeExpression[] parameters) { this.parameters = parameters; this.codeMethod = method; }
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; }
public static void GenerateMethodCall(ILGenerator gen, CodeExpression target, CodeMethod method, params CodeExpression[] parameters) { GenerateMethodCall(gen, target, method.MethodBase, method.ParameterTypes, parameters); }
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; }
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)); }
public static CodeExpression Call (CodeMethod method, params CodeExpression[] parameters) { return new CodeMethodCall (method, parameters); }
public static void GenerateMethodCall (ILGenerator gen, CodeExpression target, CodeMethod method, params CodeExpression[] parameters) { GenerateMethodCall (gen, target, method.MethodBase, method.ParameterTypes, parameters); }