public static CodeCustomAttribute Create (Type attributeType, Type [] ctorArgTypes, CodeLiteral [] ctorArgs, MemberInfo [] members, CodeLiteral [] values)
		{
			ArrayList props = new ArrayList ();
			ArrayList pvalues  = new ArrayList ();
			ArrayList fields = new ArrayList ();
			ArrayList fvalues = new ArrayList ();
			for (int i = 0; i < members.Length; i++) {
				if (members [i] == null)
					throw new ArgumentException (String.Format ("MemberInfo at {0} was null for type {1}.", i, attributeType));
				if (members [i] is PropertyInfo) {
					props.Add ((PropertyInfo) members [i]);
					pvalues.Add (values [i].Value);
				} else {
					fields.Add ((FieldInfo) members [i]);
					fvalues.Add (values [i].Value);
				}
			}

			ConstructorInfo ci = attributeType.GetConstructor (ctorArgTypes);
			CustomAttributeBuilder cab = new CustomAttributeBuilder (
				ci, ctorArgs,
				(PropertyInfo []) props.ToArray (typeof (PropertyInfo)), pvalues.ToArray (),
				(FieldInfo []) fields.ToArray (typeof (FieldInfo)), fvalues.ToArray ());

			CodeCustomAttribute attr = new CodeCustomAttribute (
				cab, attributeType, ci, ctorArgs, members, values);

			return attr;
		}
Ejemplo n.º 2
0
        public static CodeCustomAttribute Create(Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgNames, object [] namedArgValues)
        {
            MemberInfo [] members = new MemberInfo [namedArgNames.Length];
            for (int i = 0; i < namedArgNames.Length; i++)
            {
                members [i] = attributeType.GetField(namedArgNames [i]);
                if (members [i] == null)
                {
                    members [i] = attributeType.GetProperty(namedArgNames [i]);
                }
                if (members [i] == null)
                {
                    throw new ArgumentException(String.Format("Named argument {0} was not found in attribute type {1}", namedArgNames [i], attributeType));
                }
            }

            CodeLiteral [] args = new CodeLiteral [ctorArgs.Length];
            for (int i = 0; i < args.Length; i++)
            {
                args [i] = new CodeLiteral(ctorArgs [i]);
            }

            CodeLiteral [] nargs = new CodeLiteral [namedArgValues.Length];
            for (int i = 0; i < nargs.Length; i++)
            {
                nargs [i] = new CodeLiteral(namedArgValues [i]);
            }

            return(Create(attributeType, ctorArgTypes, args, members, nargs));
        }
Ejemplo n.º 3
0
		public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, CodeLiteral [] ctorArgs, FieldInfo [] fields, CodeLiteral [] fieldValues)
		{
			CodeCustomAttribute cca = CodeCustomAttribute.Create (
				attributeType, ctorArgTypes, ctorArgs, fields, fieldValues);

			typeBuilder.SetCustomAttribute (cca.Builder);
			customAttributes.Add (cca);
			return cca;
		}
 public CodeCustomAttribute(
     CustomAttributeBuilder attributeBuilder,
     Type type,
     ConstructorInfo constructor,
     CodeLiteral [] ctorArgs,
     MemberInfo [] namedArgMembers,
     CodeLiteral [] namedArgValues)
 {
     this.type = type;
     this.constructor = constructor;
     this.customAttributeBuilder = attributeBuilder;
     this.ctorArgs = ctorArgs;
     this.members = namedArgMembers;
     this.namedArgValues = namedArgValues;
 }
		public static CodeCustomAttribute Create (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgNames, object [] namedArgValues)
		{
			MemberInfo [] members = new MemberInfo [namedArgNames.Length];
			for (int i = 0; i < namedArgNames.Length; i++) {
				members [i] = attributeType.GetField (namedArgNames [i]);
				if (members [i] == null)
					members [i] = attributeType.GetProperty (namedArgNames [i]);
				if (members [i] == null)
					throw new ArgumentException (String.Format ("Named argument {0} was not found in attribute type {1}", namedArgNames [i], attributeType));
			}

			CodeLiteral [] args = new CodeLiteral [ctorArgs.Length];
			for (int i = 0; i < args.Length; i++)
				args [i] = new CodeLiteral (ctorArgs [i]);

			CodeLiteral [] nargs = new CodeLiteral [namedArgValues.Length];
			for (int i = 0; i < nargs.Length; i++)
				nargs [i] = new CodeLiteral (namedArgValues [i]);

			return Create (attributeType, ctorArgTypes, args, members, nargs);
		}
Ejemplo n.º 6
0
		static void GenerateEndMethodImpl (CodeClass c, MethodInfo endProcessMethod, string name, MethodInfo mi)
		{
			CodeMethod m = c.ImplementMethod (mi);
			CodeBuilder b = m.CodeBuilder;
			ParameterInfo [] pinfos = mi.GetParameters ();

			ParameterInfo p = pinfos [0];
			CodeArgumentReference asyncResultRef = m.GetArg (0);
			
			CodeVariableDeclaration paramsDecl = new CodeVariableDeclaration (typeof (object []), "parameters");
			b.CurrentBlock.Add (paramsDecl);
			CodeVariableReference paramsRef = paramsDecl.Variable;
			b.Assign (paramsRef,
				  new CodeNewArray (typeof (object), new CodeLiteral (pinfos.Length - 1)));
			/*
			for (int i = 0; i < pinfos.Length - 2; i++) {
				ParameterInfo par = pinfos [i];
				if (!par.IsOut)
					b.Assign (
						new CodeArrayItem (paramsRef, new CodeLiteral (i)),
						new CodeCast (typeof (object),
							new CodeArgumentReference (par.ParameterType, par.Position + 1, "arg" + i)));
			}
			*/
#if USE_OD_REFERENCE_IN_PROXY
			CodePropertyReference argMethodInfo = GetOperationMethod (m, b, name, "EndMethod");
#else
			CodeMethodCall argMethodInfo = new CodeMethodCall (typeof (MethodBase), "GetCurrentMethod");
#endif
			CodeLiteral argOperName = new CodeLiteral (name);
			
			CodeVariableReference retValue = null;
			if (mi.ReturnType == typeof (void))
				b.Call (m.GetThis (), endProcessMethod, argMethodInfo, argOperName, paramsRef, asyncResultRef);
			else {
				CodeVariableDeclaration retValueDecl = new CodeVariableDeclaration (mi.ReturnType, "retValue");
				b.CurrentBlock.Add (retValueDecl);
				retValue = retValueDecl.Variable;
				b.Assign (retValue,
					new CodeCast (mi.ReturnType,
						b.CallFunc (m.GetThis (), endProcessMethod, argMethodInfo, argOperName, paramsRef, asyncResultRef)));
			}
			// FIXME: fill out parameters
			if (retValue != null)
				b.Return (retValue);
		}
Ejemplo n.º 7
0
		static void GenerateBeginMethodImpl (CodeClass c, MethodInfo beginProcessMethod, string name, MethodInfo mi)
		{
			CodeMethod m = c.ImplementMethod (mi);
			CodeBuilder b = m.CodeBuilder;
			// object [] parameters = new object [x];
			// parameters [0] = arg1;
			// parameters [1] = arg2;
			// ...
			// (return) BeginProcess (Contract.Operations [operName].BeginMethod, operName, parameters, asyncCallback, userState);
			ParameterInfo [] pinfos = mi.GetParameters ();
			CodeVariableDeclaration paramsDecl = new CodeVariableDeclaration (typeof (object []), "parameters");
			b.CurrentBlock.Add (paramsDecl);
			CodeVariableReference paramsRef = paramsDecl.Variable;
			b.Assign (paramsRef,
				  new CodeNewArray (typeof (object), new CodeLiteral (pinfos.Length - 2)));
			for (int i = 0; i < pinfos.Length - 2; i++) {
				ParameterInfo par = pinfos [i];
				if (!par.IsOut)
					b.Assign (
						new CodeArrayItem (paramsRef, new CodeLiteral (i)),
						new CodeCast (typeof (object), m.GetArg (i)));
			}
#if USE_OD_REFERENCE_IN_PROXY
			CodePropertyReference argMethodInfo = GetOperationMethod (m, b, name, "BeginMethod");
#else
			CodeMethodCall argMethodInfo = new CodeMethodCall (typeof (MethodBase), "GetCurrentMethod");
#endif
			CodeLiteral argOperName = new CodeLiteral (name);

			ParameterInfo p = pinfos [pinfos.Length - 2];
			CodeArgumentReference callbackRef = new CodeArgumentReference (typeof (AsyncCallback), p.Position + 1, p.Name);
			p = pinfos [pinfos.Length - 1];
			CodeArgumentReference stateRef = new CodeArgumentReference (typeof (object), p.Position + 1, p.Name);

			CodeVariableDeclaration retValueDecl = new CodeVariableDeclaration (mi.ReturnType, "retValue");
			b.CurrentBlock.Add (retValueDecl);
			CodeVariableReference retValue = retValueDecl.Variable;
			b.Assign (retValue,
				new CodeCast (mi.ReturnType,
					b.CallFunc (m.GetThis (), beginProcessMethod, argMethodInfo, argOperName, paramsRef, callbackRef, stateRef)));

			b.Return (retValue);
		}
Ejemplo n.º 8
0
		static void GenerateMethodImpl (CodeClass c, MethodInfo processMethod, string name, MethodInfo mi)
		{
			CodeMethod m = c.ImplementMethod (mi);
			CodeBuilder b = m.CodeBuilder;
			// object [] parameters = new object [x];
			// parameters [0] = arg1;
			// parameters [1] = arg2;
			// ...
			// (return) Process (Contract.Operations [operName].SyncMethod, operName, parameters);
			ParameterInfo [] pinfos = mi.GetParameters ();
			CodeVariableDeclaration paramsDecl = new CodeVariableDeclaration (typeof (object []), "parameters");
			b.CurrentBlock.Add (paramsDecl);
			CodeVariableReference paramsRef = paramsDecl.Variable;
			b.Assign (paramsRef,
				  new CodeNewArray (typeof (object), new CodeLiteral (pinfos.Length)));
			for (int i = 0; i < pinfos.Length; i++) {
				ParameterInfo par = pinfos [i];
				if (!par.IsOut)
					b.Assign (
						new CodeArrayItem (paramsRef, new CodeLiteral (i)),
						new CodeCast (typeof (object),
							new CodeArgumentReference (par.ParameterType, par.Position + 1, "arg" + i)));
			}
#if USE_OD_REFERENCE_IN_PROXY
			CodePropertyReference argMethodInfo = GetOperationMethod (m, b, name, "SyncMethod");
#else
			CodeMethodCall argMethodInfo = new CodeMethodCall (typeof (MethodBase), "GetCurrentMethod");
#endif
			CodeLiteral argOperName = new CodeLiteral (name);
			CodeVariableReference retValue = null;
			if (mi.ReturnType == typeof (void))
				b.Call (m.GetThis (), processMethod, argMethodInfo, argOperName, paramsRef);
			else {
				CodeVariableDeclaration retValueDecl = new CodeVariableDeclaration (mi.ReturnType, "retValue");
				b.CurrentBlock.Add (retValueDecl);
				retValue = retValueDecl.Variable;
				b.Assign (retValue,
					new CodeCast (mi.ReturnType,
						b.CallFunc (m.GetThis (), processMethod, argMethodInfo, argOperName, paramsRef)));
			}
			for (int i = 0; i < pinfos.Length; i++) {
				ParameterInfo par = pinfos [i];
				if (par.IsOut || par.ParameterType.IsByRef)
					b.Assign (
						new CodeArgumentReference (par.ParameterType, par.Position + 1, "arg" + i),
						new CodeCast (par.ParameterType.GetElementType (),
							new CodeArrayItem (paramsRef, new CodeLiteral (i))));
			}
			if (retValue != null)
				b.Return (retValue);
		}