当前位置: 首页>>代码示例>>C#>>正文


C# ParameterList.Add方法代码示例

本文整理汇总了C#中ParameterList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterList.Add方法的具体用法?C# ParameterList.Add怎么用?C# ParameterList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParameterList的用法示例。


在下文中一共展示了ParameterList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FetchPage

		public void FetchPage(string board, int? start=null)
		{
			this.board = board;
			this.start = start;
			ParameterList qry = new ParameterList();
			qry.Add("board", board);
			if (start != null)
				qry.Add("start", start.Value.ToString());
			DoAction(this.FetchPageCompleted, "bbstdoc", qry);
		}
开发者ID:roxit,项目名称:LilyBBS.WP,代码行数:10,代码来源:FetchPageRequest.cs

示例2: Login

		public void Login(string username, string password)
		{
			Random rand = new Random();
			connection.BaseUrl = string.Format("{0}vd{1}/", Connection.BbsUrl, new Random().Next(10000, 100000));
			ParameterList qry = new ParameterList();
			qry.Add("type", "2");
			ParameterList data = new ParameterList();
			data.Add("id", username);
			data.Add("pw", password);
			DoAction(LoginCompleted, "bbslogin", qry, data);
		}
开发者ID:roxit,项目名称:LilyBBS.WP,代码行数:11,代码来源:LoginRequest.cs

示例3: TestExpand

		public void TestExpand ()
		{
			Func<SampleContext,List<string>> r1 = (ctx) => new List<string>() {"1","2","3"}; 
			Func<SampleContext,List<string>> r2 = (ctx) => new List<string>() {"a","b","c","d"}; 
			Func<SampleContext,List<string>> r3 = (ctx) => new List<string>() {"Green","Blue"}; 


			var context = new SampleContext ();
			var parameterList = new ParameterList<SampleContext> ();
			parameterList.Add (new mtgfool.Utils.Parameter<SampleContext> ("number",r1));
			parameterList.Add (new mtgfool.Utils.Parameter<SampleContext> ("letter",r2));
			parameterList.Add (new mtgfool.Utils.Parameter<SampleContext> ("color",r3));

			var x = parameterList.Expand (context);

			Assert.AreEqual (24, x.Count);
			var y = x.FindAll ((d) => d ["number"] == "2" && d ["letter"] == "d" && d ["color"] == "Green");
			Assert.AreEqual	(1, y.Count);

		}
开发者ID:,项目名称:,代码行数:20,代码来源:

示例4: AddExtensionMethod

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="type">the current type being extended</param>
        /// <param name="extensionMethodTemplate">A reference to the extension method. For generic methods, this is a reference to the 
        /// non-specialized method, e.g. System.Linq.Enumerable.Select``2.
        /// </param>
        /// <param name="specialization">When the current type implements or inherits from a specialization of a generic type,
        /// this parameter has a TypeNode for the type used as apecialization of the generic type's first template param. 
        /// </param>
        private void AddExtensionMethod(XmlWriter writer, TypeNode type, Method extensionMethodTemplate, TypeNode specialization)
        {
            // If this is a specialization of a generic method, construct a Method object that describes the specialization
            Method extensionMethodTemplate2 = extensionMethodTemplate;
            if (extensionMethodTemplate2.IsGeneric && (specialization != null))
            {
                // the specialization type is the first of the method's template arguments
                TypeNodeList templateArgs = new TypeNodeList();
                templateArgs.Add(specialization);
                // add any additional template arguments
                for (int i = 1; i < extensionMethodTemplate.TemplateParameters.Count; i++)
                    templateArgs.Add(extensionMethodTemplate.TemplateParameters[i]);
                extensionMethodTemplate2 = extensionMethodTemplate.GetTemplateInstance(type, templateArgs);
            }
            TypeNode extensionMethodTemplateReturnType = extensionMethodTemplate2.ReturnType;
            ParameterList extensionMethodTemplateParameters = extensionMethodTemplate2.Parameters;

            ParameterList extensionMethodParameters = new ParameterList();
            for (int i = 1; i < extensionMethodTemplateParameters.Count; i++)
            {
                Parameter extensionMethodParameter = extensionMethodTemplateParameters[i];
                extensionMethodParameters.Add(extensionMethodParameter);
            }
            Method extensionMethod = new Method(extensionMethodTemplate.DeclaringType, new AttributeList(), extensionMethodTemplate.Name, extensionMethodParameters, extensionMethodTemplate.ReturnType, null);
            extensionMethod.Flags = extensionMethodTemplate.Flags & ~MethodFlags.Static;

            // for generic methods, set the template args and params so the template data is included in the id and the method data
            if (extensionMethodTemplate2.IsGeneric)
            {
                extensionMethod.IsGeneric = true;
                if (specialization != null)
                {
                    // set the template args for the specialized generic method
                    extensionMethod.TemplateArguments = extensionMethodTemplate2.TemplateArguments;
                }
                else
                {
                    // set the generic template params for the non-specialized generic method
                    extensionMethod.TemplateParameters = extensionMethodTemplate2.TemplateParameters;
                }
            }

            // Get the id
            string extensionMethodTemplateId = reflector.ApiNamer.GetMemberName(extensionMethodTemplate);

            // write the element node
            writer.WriteStartElement("element");
            writer.WriteAttributeString("api", extensionMethodTemplateId);
            writer.WriteAttributeString("source", "extension");
            isExtensionMethod = true;
            reflector.WriteMember(extensionMethod);
            isExtensionMethod = false;
            writer.WriteEndElement();
        }
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:65,代码来源:ExtensionMethodAddIn.cs

示例5: SourceBase

        private SourceBase(Uri uri)
        {
            m_parameters = new ParameterList();

            var defaultParams = GetDefaultParameters();
            if (defaultParams != null)
            {
                foreach (Parameter parameter in defaultParams)
                {
                    m_parameters.Add(parameter.Name, parameter);
                }
            }

            SetParameterValue(SourceCreatorBase.UriParameterName, uri);
        }
开发者ID:jdauie,项目名称:squid,代码行数:15,代码来源:SourceBase.cs

示例6: SendPost

		public void SendPost(string brd, string title, string text, int? pid=null, int? gid=null, int signature=0, string autocr="on")
		{
			ParameterList qry = new ParameterList();
			qry.Add("board", brd);
			ParameterList data = new ParameterList();
			data.Add("title", title);
			data.Add("text", text);
			if (pid != null)		// replying a post
			{
				data.Add("reid", pid.ToString());
				data.Add("pid", gid.ToString());
			}
			data.Add("signature", signature.ToString());
			data.Add("autocr", autocr);
			DoAction(SendPostCompleted, "bbssnd", qry, data);
		}
开发者ID:roxit,项目名称:LilyBBS.WP,代码行数:16,代码来源:SendPostRequest.cs

示例7: GetParameters

 public ParameterList GetParameters(string CommandName)
 {
     ParameterList pList=new ParameterList();
     CommandInteraction ci = new CommandInteraction();
     try
     {
         List<string> requierdInputs = ci.getRequiredInputs(CommandName);
         foreach (string i in requierdInputs)
         {
             Parameter p = new Parameter();
             p.Name = i;
             pList.Add(p);
         }
     }
     catch (Exception e)
     {
         throw new HttpException((int)HttpStatusCode.InternalServerError,e.Message);
     }
     return pList;
 }
开发者ID:cpm2710,项目名称:cellbank,代码行数:20,代码来源:TrackingService.svc.cs

示例8: GetRuntimeContractsAttributeCtor

    /// <summary>
    /// Tries to reuse or create the attribute
    /// </summary>
    private static InstanceInitializer GetRuntimeContractsAttributeCtor(AssemblyNode assembly)
    {
      EnumNode runtimeContractsFlags = assembly.GetType(ContractNodes.ContractNamespace, Identifier.For("RuntimeContractsFlags")) as EnumNode;
      Class RuntimeContractsAttributeClass = assembly.GetType(ContractNodes.ContractNamespace, Identifier.For("RuntimeContractsAttribute")) as Class;

      if (runtimeContractsFlags == null)
      {
        #region Add [Flags]
        Member flagsConstructor = RewriteHelper.flagsAttributeNode.GetConstructor();
        AttributeNode flagsAttribute = new AttributeNode(new MemberBinding(null, flagsConstructor), null, AttributeTargets.Class);
        #endregion Add [Flags]
        runtimeContractsFlags = new EnumNode(assembly,
          null, /* declaringType */
          new AttributeList(2),
          TypeFlags.Sealed,
          ContractNodes.ContractNamespace,
          Identifier.For("RuntimeContractsFlags"),
          new InterfaceList(),
          new MemberList());
        runtimeContractsFlags.Attributes.Add(flagsAttribute);
        RewriteHelper.TryAddCompilerGeneratedAttribute(runtimeContractsFlags);
        runtimeContractsFlags.UnderlyingType = SystemTypes.Int32;

        Type copyFrom = typeof(RuntimeContractEmitFlags);
        foreach (System.Reflection.FieldInfo fi in copyFrom.GetFields())
        {
          if (fi.IsLiteral)
          {
            AddEnumValue(runtimeContractsFlags, fi.Name, fi.GetRawConstantValue());
          }
        }
        assembly.Types.Add(runtimeContractsFlags);

      }


      InstanceInitializer ctor = (RuntimeContractsAttributeClass == null) ? null : RuntimeContractsAttributeClass.GetConstructor(runtimeContractsFlags);

      if (RuntimeContractsAttributeClass == null)
      {
        RuntimeContractsAttributeClass = new Class(assembly,
          null, /* declaringType */
          new AttributeList(),
          TypeFlags.Sealed,
          ContractNodes.ContractNamespace,
          Identifier.For("RuntimeContractsAttribute"),
          SystemTypes.Attribute,
          new InterfaceList(),
          new MemberList(0));

        RewriteHelper.TryAddCompilerGeneratedAttribute(RuntimeContractsAttributeClass);
        assembly.Types.Add(RuntimeContractsAttributeClass);
      }
      if (ctor == null) {

        Block returnBlock = new Block(new StatementList(new Return()));

        Block body = new Block(new StatementList());
        Block b = new Block(new StatementList());
        ParameterList pl = new ParameterList();
        Parameter levelParameter = new Parameter(Identifier.For("contractFlags"), runtimeContractsFlags);
        pl.Add(levelParameter);

        ctor = new InstanceInitializer(RuntimeContractsAttributeClass, null, pl, body);
        ctor.Flags = MethodFlags.Assembly | MethodFlags.HideBySig | MethodFlags.SpecialName | MethodFlags.RTSpecialName;

        Method baseCtor = SystemTypes.Attribute.GetConstructor();

        b.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(null, baseCtor), new ExpressionList(ctor.ThisParameter))));
        b.Statements.Add(returnBlock);
        body.Statements.Add(b);

        RuntimeContractsAttributeClass.Members.Add(ctor);
      }

      return ctor;
    }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:80,代码来源:Rewriter.cs

示例9: MakeMethod

    /// <summary>
    /// Constructs (and returns) a method that looks like this:
    /// 
    ///   [System.Diagnostics.DebuggerNonUserCodeAttribute]
    ///   [System.Runtime.ConstrainedExecution.ReliabilityContractReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
    ///   static void name(bool condition, string message, string conditionText){
    ///     if (!condition) {
    ///       System.Diagnostics.Contracts.Contract.Failure(kind, message, conditionText, null);
    ///     }
    ///   }
    ///
    /// Or, if the ContractFailureKind is PostconditionOnException, then the generated method
    /// gets an extra parameter which is an Exception and that parameter is passed to Contract.Failure instead of null
    /// </summary>
    private Method MakeMethod(string name, ContractFailureKind kind)
    {
      Parameter conditionParameter = new Parameter(Identifier.For("condition"), SystemTypes.Boolean);
      Parameter messageParameter = new Parameter(Identifier.For("msg"), SystemTypes.String);
      Parameter conditionTextParameter = new Parameter(Identifier.For("conditionTxt"), SystemTypes.String);
      Parameter exceptionParameter = new Parameter(Identifier.For("originalException"), SystemTypes.Exception);

      Block returnBlock = new Block(new StatementList(new Return()));

      Block body = new Block(new StatementList());
      Block b = new Block(new StatementList());
      b.Statements.Add(new Branch(conditionParameter, returnBlock));
      ExpressionList elist = new ExpressionList();
      elist.Add(TranslateKindForBackwardCompatibility(kind));
      elist.Add(messageParameter);
      elist.Add(conditionTextParameter);
      if (kind == ContractFailureKind.PostconditionOnException)
      {
        elist.Add(exceptionParameter);
      }
      else
      {
        elist.Add(Literal.Null);
      }
      b.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(null, this.FailureMethod), elist)));
      b.Statements.Add(returnBlock);
      body.Statements.Add(b);

      ParameterList pl = new ParameterList(conditionParameter, messageParameter, conditionTextParameter);
      if (kind == ContractFailureKind.PostconditionOnException)
      {
        pl.Add(exceptionParameter);
      }
      Method m = new Method(this.RuntimeContractType, null, Identifier.For(name), pl, SystemTypes.Void, body);
      m.Flags = MethodFlags.Assembly | MethodFlags.Static;
      m.Attributes = new AttributeList();
      this.RuntimeContractType.Members.Add(m);

      Member constructor = null;
      AttributeNode attribute = null;

      #region Add [DebuggerNonUserCodeAttribute]
      if (this.HideFromDebugger) {
        TypeNode debuggerNonUserCode = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Diagnostics"), Identifier.For("DebuggerNonUserCodeAttribute"));
        if (debuggerNonUserCode != null)
        {
          constructor = debuggerNonUserCode.GetConstructor();
          attribute = new AttributeNode(new MemberBinding(null, constructor), null, AttributeTargets.Method);
          m.Attributes.Add(attribute);
        }
      }
      #endregion Add [DebuggerNonUserCodeAttribute]

      TypeNode reliabilityContract = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("ReliabilityContractAttribute"));
      TypeNode consistency = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("Consistency"));
      TypeNode cer = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("Cer"));
      if (reliabilityContract != null && consistency != null && cer != null) {
        constructor = reliabilityContract.GetConstructor(consistency, cer);
        if (constructor != null) {
          attribute = new AttributeNode(
            new MemberBinding(null, constructor),
            new ExpressionList(
              new Literal(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, consistency),
              new Literal(System.Runtime.ConstrainedExecution.Cer.MayFail, cer)),
              AttributeTargets.Method
              );
          m.Attributes.Add(attribute);
        }
      }
      return m;
    }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:85,代码来源:Rewriter.cs

示例10: MakeContractException

    private Class MakeContractException() {
      Class contractExceptionType;

      #region If we're rewriting an assembly for v4 or above and it *isn't* Silverlight (so serialization support is needed), then use new embedded dll as the type
      if (4 <= TargetPlatform.MajorVersion) {
        var iSafeSerializationData = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.Serialization"), Identifier.For("ISafeSerializationData")) as Interface;
        if (iSafeSerializationData != null) {
          // Just much easier to write the C# and have the compiler generate everything than to try and create it all manually
          System.Reflection.Assembly embeddedAssembly;
          Stream embeddedAssemblyStream;
          embeddedAssembly = System.Reflection.Assembly.GetExecutingAssembly();
          embeddedAssemblyStream = embeddedAssembly.GetManifestResourceStream("Microsoft.Contracts.Foxtrot.InternalException.dll");
          byte[] data = new byte[0];
          using (var br = new BinaryReader(embeddedAssemblyStream)) {
            var len = embeddedAssemblyStream.Length;
            if (len < Int32.MaxValue)
              data = br.ReadBytes((int)len);
            AssemblyNode assemblyNode = AssemblyNode.GetAssembly(data, TargetPlatform.StaticAssemblyCache, true, false, true);
            contractExceptionType = assemblyNode.GetType(Identifier.For(""), Identifier.For("ContractException")) as Class;
          }
          if (contractExceptionType == null)
            throw new RewriteException("Tried to create the ContractException type from the embedded dll, but failed");
          var d = new Duplicator(this.targetAssembly, this.RuntimeContractType);
          d.FindTypesToBeDuplicated(new TypeNodeList(contractExceptionType));

          var ct = d.Visit(contractExceptionType);
          contractExceptionType = (Class)ct;
          contractExceptionType.Flags |= TypeFlags.NestedPrivate;
          this.RuntimeContractType.Members.Add(contractExceptionType);
          return contractExceptionType;
        }
      }
      #endregion

      contractExceptionType = new Class(this.targetAssembly, this.RuntimeContractType, new AttributeList(), TypeFlags.Class | TypeFlags.NestedPrivate | TypeFlags.Serializable, null, Identifier.For("ContractException"), SystemTypes.Exception, null, null);

      RewriteHelper.TryAddCompilerGeneratedAttribute(contractExceptionType);

      var kindField = new Field(contractExceptionType, null, FieldFlags.Private, Identifier.For("_Kind"), contractNodes.ContractFailureKind, null);
      var userField = new Field(contractExceptionType, null, FieldFlags.Private, Identifier.For("_UserMessage"), SystemTypes.String, null);
      var condField = new Field(contractExceptionType, null, FieldFlags.Private, Identifier.For("_Condition"), SystemTypes.String, null);
      contractExceptionType.Members.Add(kindField);
      contractExceptionType.Members.Add(userField);
      contractExceptionType.Members.Add(condField);

      #region Constructor for setting the fields
      var parameters = new ParameterList();
      var kindParam = new Parameter(Identifier.For("kind"), this.contractNodes.ContractFailureKind);
      var failureParam = new Parameter(Identifier.For("failure"), SystemTypes.String);
      var usermsgParam = new Parameter(Identifier.For("usermsg"), SystemTypes.String);
      var conditionParam = new Parameter(Identifier.For("condition"), SystemTypes.String);
      var innerParam = new Parameter(Identifier.For("inner"), SystemTypes.Exception);
      parameters.Add(kindParam);
      parameters.Add(failureParam);
      parameters.Add(usermsgParam);
      parameters.Add(conditionParam);
      parameters.Add(innerParam);
      var body = new Block(new StatementList());
      var ctor = new InstanceInitializer(contractExceptionType, null, parameters, body);
      ctor.Flags |= MethodFlags.Public | MethodFlags.HideBySig;
      ctor.CallingConvention = CallingConventionFlags.HasThis;
      body.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(ctor.ThisParameter, contractExceptionType.BaseClass.GetConstructor(SystemTypes.String, SystemTypes.Exception)), new ExpressionList(failureParam, innerParam))));
      body.Statements.Add(new AssignmentStatement(new MemberBinding(ctor.ThisParameter, kindField), kindParam));
      body.Statements.Add(new AssignmentStatement(new MemberBinding(ctor.ThisParameter, userField), usermsgParam));
      body.Statements.Add(new AssignmentStatement(new MemberBinding(ctor.ThisParameter, condField), conditionParam));
      body.Statements.Add(new Return());
      contractExceptionType.Members.Add(ctor);
      #endregion

      if (SystemTypes.SerializationInfo != null && SystemTypes.SerializationInfo.BaseClass != null) {
        // Silverlight (e.g.) is a platform that doesn't support serialization. So check to make sure the type really exists.
        // 
        var baseCtor = SystemTypes.Exception.GetConstructor(SystemTypes.SerializationInfo, SystemTypes.StreamingContext);

        if (baseCtor != null) {
          #region Deserialization Constructor
          parameters = new ParameterList();
          var info = new Parameter(Identifier.For("info"), SystemTypes.SerializationInfo);
          var context = new Parameter(Identifier.For("context"), SystemTypes.StreamingContext);
          parameters.Add(info);
          parameters.Add(context);
          body = new Block(new StatementList());
          ctor = new InstanceInitializer(contractExceptionType, null, parameters, body);
          ctor.Flags |= MethodFlags.Private | MethodFlags.HideBySig;
          ctor.CallingConvention = CallingConventionFlags.HasThis;
          // : base(info, context) 
          body.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(ctor.ThisParameter, baseCtor), new ExpressionList(info, context))));
          // _Kind = (ContractFailureKind)info.GetInt32("Kind");
          var getInt32 = SystemTypes.SerializationInfo.GetMethod(Identifier.For("GetInt32"), SystemTypes.String);
          body.Statements.Add(new AssignmentStatement(
              new MemberBinding(new This(), kindField),
              new MethodCall(new MemberBinding(info, getInt32), new ExpressionList(new Literal("Kind", SystemTypes.String)))
              ));
          // _UserMessage = info.GetString("UserMessage");
          var getString = SystemTypes.SerializationInfo.GetMethod(Identifier.For("GetString"), SystemTypes.String);
          body.Statements.Add(new AssignmentStatement(
              new MemberBinding(new This(), userField),
              new MethodCall(new MemberBinding(info, getString), new ExpressionList(new Literal("UserMessage", SystemTypes.String)))
              ));
          // _Condition = info.GetString("Condition");
//.........这里部分代码省略.........
开发者ID:nbulp,项目名称:CodeContracts,代码行数:101,代码来源:Rewriter.cs

示例11: DefineBlockHoleMethod

    //HS D
    //HACK FIXME: define a BlockHole method so can represent block holes by calls to it
    private void DefineBlockHoleMethod(TypeNode t) {
	if (definedTypeNodes.ContainsKey(t))
	    return;
	definedTypeNodes[t] = true;
	ParameterList parList = new ParameterList();
	TypeNode intTp = CoreSystemTypes.Int32;
	TypeNode strTp = CoreSystemTypes.Object.GetArrayType(1);
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("repeat"), intTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("ifbranches"), intTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("branchops"), intTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("conjunctions"), intTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("ops"), strTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("condvars"), strTp, null, null));
	parList.Add(new Parameter(null, ParameterFlags.None, new Identifier("argvars"), strTp, null, null));
	Method m = new Method(t, null, new Identifier("BlockHole"), parList, this.TypeExpressionFor(Token.Void), new Block());
	m.Flags |= MethodFlags.Static;
	t.Members.Add(m);	
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:20,代码来源:Parser.cs

示例12: CoerceArguments

    public virtual void CoerceArguments(ParameterList parameters, ref ExpressionList arguments, bool doNotVisitArguments, CallingConventionFlags callingConvention) {
      if (arguments == null) arguments = new ExpressionList();
      int n = arguments.Count;
      int m = parameters == null ? 0 : parameters.Count;
      //if fewer arguments than parameters, supply default values
      for (; n < m; n++) {
        Parameter p = parameters[n];
        TypeNode type = p == null ? null : p.Type;
        if (type == null) type = SystemTypes.Object;
        type = TypeNode.StripModifiers(type);
        if (p.DefaultValue != null)
          arguments.Add(p.DefaultValue);
        else {
          //There should already have been a complaint. Just recover.
          TypeNode elementType = parameters[n].GetParamArrayElementType();
          if (elementType != null) break;
          arguments.Add(new UnaryExpression(new Literal(type, SystemTypes.Type), NodeType.DefaultValue, type));
        }
      }
      if (m > 0) {
        TypeNode elementType = TypeNode.StripModifiers(parameters[m-1].GetParamArrayElementType());
        TypeNode lastArgType = null;
        if (elementType != null && (n > m || (n == m - 1) || n == m
          && (lastArgType = TypeNode.StripModifiers(arguments[m-1].Type)) != null && 
              !this.GetTypeView(lastArgType).IsAssignableTo(TypeNode.StripModifiers(parameters[m-1].Type)) &&
          !(arguments[m-1].Type == SystemTypes.Object && arguments[m-1] is Literal && ((Literal)arguments[m-1]).Value == null))) {
          ExpressionList varargs = new ExpressionList(n-m+1);
          for (int i = m-1; i < n; i++)
            varargs.Add(arguments[i]);
          Debug.Assert(m <= n || m == n+1);
          while (m > n++) arguments.Add(null);
          arguments[m-1] = new ConstructArray(parameters[m-1].GetParamArrayElementType(), varargs);
          arguments.Count = m;
          n = m;
        }
      }
      if (n > m) {
        // Handle Varargs
        Debug.Assert(n == m+1);
        Debug.Assert((callingConvention & CallingConventionFlags.VarArg) != 0);
        ArglistArgumentExpression ale = arguments[n-1] as ArglistArgumentExpression;
        if (ale != null) {
          // rewrite nested arguments to one level.
          // otherwise, the method does not match and I expect the Checker to issue a nice message.
          ExpressionList newArgs = new ExpressionList(n - 1 + ale.Operands.Count);
          for (int i=0; i<n-1; i++) {
            newArgs.Add(arguments[i]);
          }
          for (int i=0; i<ale.Operands.Count; i++) {
            newArgs.Add(ale.Operands[i]);
          }
          arguments = newArgs;
          // adjust formal parameters to actuals
          parameters = (ParameterList)parameters.Clone();
          for (int i=0; i<ale.Operands.Count; i++) {
            if (arguments[i+m] != null) {
              TypeNode pType = arguments[i+m].Type;
              Reference r = pType as Reference;
              if (r != null) pType = r.ElementType;
              parameters.Add(new Parameter(null, pType));
            } else {
              parameters.Add(new Parameter(null, SystemTypes.Object));
            }
          }
          m = arguments.Count;
          n = m;
        } else {
          // leave arguments and let type coercion fail
          // adjust formal parameters to actuals
          parameters = (ParameterList)parameters.Clone();
          parameters.Add(Resolver.ArglistDummyParameter);
          n = parameters.Count;
        }
      }
      if (doNotVisitArguments) {
        for (int i = 0; i < n; i++) {
          Parameter p = this.typeSystem.currentParameter = parameters[i];
          Literal lit = arguments[i] as Literal;
          if (lit != null && lit.Value is TypeNode && p.Type == SystemTypes.Type)
            arguments[i] = lit;
          else {
            if (!this.DoNotVisitArguments(p.DeclaringMethod)) {
              Expression e = arguments[i] = this.typeSystem.ImplicitCoercion(arguments[i], p.Type, this.TypeViewer);
              if (e is BinaryExpression && e.NodeType == NodeType.Box) e = arguments[i] = ((BinaryExpression)e).Operand1;
            }
          }
        }
      } else {
        for (int i = 0; i < n; i++) {

          Parameter p = this.typeSystem.currentParameter = parameters[i];

          bool savedMayReferenceThisAndBase = this.MayReferenceThisAndBase;
          if (p.IsOut
            && this.currentMethod is InstanceInitializer) {
            // allow calls "f(out this.x)" before the explicit base ctor call
            this.MayReferenceThisAndBase = true;
          }

          arguments[i] = this.CoerceArgument(this.VisitExpression(arguments[i]), p);
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:Checker.cs

示例13: VisitParameterList

 public virtual Differences VisitParameterList(ParameterList list1, ParameterList list2,
   out ParameterList changes, out ParameterList deletions, out ParameterList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new ParameterList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   //Compare definitions that have matching key attributes
   TrivialHashtable matchingPosFor = new TrivialHashtable();
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     Parameter nd2 = list2[j];
     if (nd2 == null || nd2.Name == null) continue;
     matchingPosFor[nd2.Name.UniqueIdKey] = j;
     insertions.Add(null);
   }
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Parameter nd1 = list1[i];
     if (nd1 == null || nd1.Name == null) continue;
     object pos = matchingPosFor[nd1.Name.UniqueIdKey];
     if (!(pos is int)) continue;
     //^ assert pos != null;
     int j = (int)pos;
     //^ assume list2 != null; //since there was entry int matchingPosFor
     Parameter nd2 = list2[j];
     //^ assume nd2 != null;
     //nd1 and nd2 have the same key attributes and are therefore treated as the same entity
     matchedNodes[nd1.UniqueKey] = nd1;
     matchedNodes[nd2.UniqueKey] = nd2;
     //nd1 and nd2 may still be different, though, so find out how different
     Differences diff = this.VisitParameter(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.NumberOfDifferences != 0){
       changes[i] = diff.Changes as Parameter;
       deletions[i] = diff.Deletions as Parameter;
       insertions[i] = diff.Insertions as Parameter;
       insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
       Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
       differences.NumberOfDifferences += diff.NumberOfDifferences;
       differences.NumberOfSimilarities += diff.NumberOfSimilarities;
       continue;
     }
     changes[i] = null;
     deletions[i] = null;
     insertions[i] = null;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Parameter nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     Parameter nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   return differences;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:76,代码来源:Comparer.cs

示例14: ParseProperty

 private void ParseProperty(TypeNode parentType, AttributeList attributes, TokenList modifierTokens,
   SourceContextList modifierContexts, object sctx, TypeNode type, TypeNode interfaceType, Identifier name, TokenSet followers){
   SourceContext ctx = (SourceContext)sctx;
   ctx.EndPos = this.scanner.endPos;
   bool isIndexer = this.currentToken == Token.This && name.UniqueIdKey == StandardIds.Item.UniqueIdKey;
   Debug.Assert(this.currentToken == Token.LeftBrace || isIndexer);
   this.GetNextToken();
   ParameterList paramList = null;
   if (isIndexer){
     if (interfaceType == null){
       AttributeNode defaultMember = new AttributeNode();
       defaultMember.Constructor = new Literal(TypeExpressionFor("System", "Reflection", "DefaultMemberAttribute"));
       defaultMember.Expressions = new ExpressionList(1);
       defaultMember.Expressions.Add(new Literal("Item"));
       if (parentType.Attributes == null) parentType.Attributes = new AttributeList(1);
       parentType.Attributes.Add(defaultMember);
     }
     paramList = this.ParseParameters(Token.RightBracket, followers|Token.LeftBrace);
     this.Skip(Token.LeftBrace);
   }
   Property p = new Property(parentType, attributes, PropertyFlags.None, name, null, null);
   parentType.Members.Add(p);
   p.SourceContext = ctx;
   p.Documentation = this.LastDocComment;
   p.Type = p.TypeExpression = type;
   MethodFlags mflags;
   if (interfaceType != null){
     p.ImplementedTypeExpressions = p.ImplementedTypes = new TypeNodeList(interfaceType);
     mflags = MethodFlags.Private|MethodFlags.HideBySig|MethodFlags.NewSlot|MethodFlags.Final|MethodFlags.Virtual|MethodFlags.SpecialName;
     for (int i = 0, n = modifierContexts == null ? 0 : modifierContexts.Length; i < n; i++) {
       if (modifierTokens[i] == Token.Extern)
         mflags |= MethodFlags.PInvokeImpl;
       else if (modifierTokens[i] == Token.Unsafe) {
         if (!this.allowUnsafeCode) {
           this.allowUnsafeCode = true;
           this.HandleError(modifierContexts[i], Error.IllegalUnsafe);
         }
         this.inUnsafeCode = true;
       } else
         this.HandleError(modifierContexts[i], Error.InvalidModifier, modifierContexts[i].SourceText);
     }
   }else
     mflags = this.GetMethodFlags(modifierTokens, modifierContexts, parentType, p)|MethodFlags.SpecialName;
   if ((mflags & MethodFlags.Static) != 0 && parentType is Interface){
     this.HandleError(name.SourceContext, Error.InvalidModifier, "static");
     mflags &= ~MethodFlags.Static;
     mflags |= MethodFlags.Abstract;
   }
   TokenSet followersOrRightBrace = followers|Token.RightBrace;
   bool accessorModifiersAlreadySpecified = false;
   MethodFlags accessorFlags = mflags;
   while (Parser.GetOrLeftBracketOrSetOrModifier[this.currentToken]){
     SourceContext sc = this.scanner.CurrentSourceContext;
     AttributeList accessorAttrs = this.ParseAttributes(null, followers|Token.Get|Token.Set|Token.LeftBrace);
     switch (this.currentToken){
       case Token.Get:{
         if (p.Getter != null)
           this.HandleError(Error.DuplicateAccessor);
         SourceContext scntx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         Method m = new Method(parentType, accessorAttrs, new Identifier("get_"+name.ToString()), paramList, type, null);
         m.SourceContext = sc;
         m.ReturnTypeExpression = type;
         m.Name.SourceContext = scntx;
         if ((accessorFlags & MethodFlags.Static) == 0)
           m.CallingConvention = CallingConventionFlags.HasThis;
         parentType.Members.Add(m);
         m.Flags = accessorFlags|MethodFlags.HideBySig;
         if (interfaceType != null)
           m.ImplementedTypeExpressions = m.ImplementedTypes = new TypeNodeList(interfaceType);
         bool swallowedSemicolonAlready = false;
         bool bodyAllowed = true;
         if (this.currentToken == Token.Semicolon){
           m.SourceContext.EndPos = this.scanner.endPos;
           this.GetNextToken();
           bodyAllowed = false;
           swallowedSemicolonAlready = true;
         }
         this.ParseMethodContract(m, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready);
         if (bodyAllowed)
           m.Body = this.ParseBody(m, sc, followersOrRightBrace|Token.Set, swallowedSemicolonAlready);
         else if (!swallowedSemicolonAlready)
           this.SkipSemiColon(followersOrRightBrace|Token.Set);
         p.Getter = m;
         m.DeclaringMember = p;
         accessorFlags = mflags;
         break;}
       case Token.Set:{
         if (p.Setter != null)
           this.HandleError(Error.DuplicateAccessor);
         SourceContext scntx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         ParameterList parList = new ParameterList();
         if (paramList != null)
           for (int i = 0, n = paramList.Count; i < n; i++) parList.Add((Parameter)paramList[i].Clone());
         parList.Add(new Parameter(null, ParameterFlags.None, Identifier.For("value"), type, null, null));
         Method m = new Method(parentType, accessorAttrs, new Identifier("set_"+name.ToString()), parList, this.TypeExpressionFor(Token.Void), null);
         m.SourceContext = sc;
         m.Name.SourceContext = scntx;
         if ((accessorFlags & MethodFlags.Static) == 0)
//.........这里部分代码省略.........
开发者ID:dbremner,项目名称:specsharp,代码行数:101,代码来源:Parser.cs

示例15: TestBasicFunctionality

		public void TestBasicFunctionality ()
		{
			var list = new ParameterList ();
			Parameter parameter;
			string value;
			int index;

			Assert.IsFalse (list.IsReadOnly, "IsReadOnly");
			Assert.AreEqual (0, list.Count);

			list.Add (new Parameter ("abc", "0"));
			list.Add (Encoding.UTF8, "def", "1");
			list.Add ("ghi", "2");

			Assert.AreEqual (3, list.Count, "Count");
			Assert.IsTrue (list.Contains (list[0]));
			Assert.IsTrue (list.Contains ("aBc"));
			Assert.IsTrue (list.Contains ("DEf"));
			Assert.IsTrue (list.Contains ("gHI"));
			Assert.AreEqual (0, list.IndexOf ("aBc"));
			Assert.AreEqual (1, list.IndexOf ("dEF"));
			Assert.AreEqual (2, list.IndexOf ("Ghi"));
			Assert.AreEqual ("abc", list[0].Name);
			Assert.AreEqual ("def", list[1].Name);
			Assert.AreEqual ("ghi", list[2].Name);
			Assert.AreEqual ("0", list["AbC"]);
			Assert.AreEqual ("1", list["dEf"]);
			Assert.AreEqual ("2", list["GHi"]);

			Assert.IsTrue (list.TryGetValue ("Abc", out parameter));
			Assert.AreEqual ("abc", parameter.Name);
			Assert.IsTrue (list.TryGetValue ("Abc", out value));
			Assert.AreEqual ("0", value);

			Assert.IsFalse (list.Remove ("xyz"), "Remove");
			list.Insert (0, new Parameter ("xyz", "3"));
			Assert.IsTrue (list.Remove ("xyz"), "Remove");

			var array = new Parameter[list.Count];
			list.CopyTo (array, 0);
			Assert.AreEqual ("abc", array[0].Name);
			Assert.AreEqual ("def", array[1].Name);
			Assert.AreEqual ("ghi", array[2].Name);

			index = 0;
			foreach (var param in list) {
				Assert.AreEqual (array[index], param);
				index++;
			}

			list.Clear ();
			Assert.AreEqual (0, list.Count, "Clear");

			list.Add ("xyz", "3");
			list.Insert (0, array[2]);
			list.Insert (0, array[1].Name, array[1].Value);
			list.Insert (0, array[0]);

			Assert.AreEqual (4, list.Count);
			Assert.AreEqual ("abc", list[0].Name);
			Assert.AreEqual ("def", list[1].Name);
			Assert.AreEqual ("ghi", list[2].Name);
			Assert.AreEqual ("xyz", list[3].Name);
			Assert.AreEqual ("0", list["AbC"]);
			Assert.AreEqual ("1", list["dEf"]);
			Assert.AreEqual ("2", list["GHi"]);
			Assert.AreEqual ("3", list["XYZ"]);

			list.RemoveAt (3);
			Assert.AreEqual (3, list.Count);

			Assert.AreEqual ("; abc=\"0\"; def=\"1\"; ghi=\"2\"", list.ToString ());
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:73,代码来源:ParameterListTests.cs


注:本文中的ParameterList.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。