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


C# Result.GetType方法代码示例

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


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

示例1: CopyValueTo

		public void CopyValueTo (Result r)
		{
		    if (!GetType ().Equals (r.GetType ()))
			throw ExHelp.Argument ("r", "Argument type {0} doesn't match self type {1}",
					       r.GetType (), GetType ());

		    CloneTo (r);
		}
开发者ID:emtees,项目名称:old-code,代码行数:8,代码来源:Result.cs

示例2: ProvideFault

        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var errType = error.GetType();
            var rmp = new HttpResponseMessageProperty();
            var fe = error as FaultException<int>;
            if (fe != null)
            {
                //Detail for the returned value
                var faultCode = fe.Detail;
                var cause = fe.Message;

                //The json serializable object
                var msErrObject = new Result { errorType = errType.Name, install_status = faultCode, message = cause};

                //The fault to be returned
                fault = Message.CreateMessage(version, "", msErrObject, new DataContractJsonSerializer(msErrObject.GetType()));

                //fault = Message.CreateMessage(version, new FaultCode(errType.Name), error.Message, "");
                var wbf = new WebBodyFormatMessageProperty(WebContentFormat.Json);

                // Add the formatter to the fault
                fault.Properties.Add(WebBodyFormatMessageProperty.Name, wbf);
                // return custom error code, 400.
                rmp.StatusCode = HttpStatusCode.BadRequest;
                rmp.StatusDescription = "Bad request";
            }
            else
            {
                //Arbitraty error
                var msErrObject = new Result { errorType = errType.Name, install_status = 0, message = error.Message };
                // create a fault message containing our FaultContract object
                fault = Message.CreateMessage(version, "", msErrObject, new DataContractJsonSerializer(msErrObject.GetType()));
                // tell WCF to use JSON encoding rather than default XML
                var wbf = new WebBodyFormatMessageProperty(WebContentFormat.Json);
                fault.Properties.Add(WebBodyFormatMessageProperty.Name, wbf);
                //Internal server error with exception mesasage as status.
                bool isForbidden = false;
                var webEx = error as WebException;
                if (webEx != null)
                {
                    var httpResp = (HttpWebResponse) webEx.Response;
                    if (httpResp != null)
                        isForbidden = httpResp.StatusCode == HttpStatusCode.Forbidden;
                }
                if ((error is AuthenticationException) || isForbidden)
                    rmp.StatusCode = HttpStatusCode.Forbidden;
                else
                    rmp.StatusCode = HttpStatusCode.InternalServerError;
                rmp.StatusDescription = error.Message;
            }
            //Mark the jsonerror and json content
            rmp.Headers[HttpResponseHeader.ContentType] = "application/json";
            rmp.Headers["jsonerror"] = "true";

            //Add to fault
            fault.Properties.Add(HttpResponseMessageProperty.Name, rmp);
        }
开发者ID:siarheimilkevich,项目名称:VSSync,代码行数:57,代码来源:ErrorHandler.cs

示例3: Add

	public bool Add (Result r, Fingerprint fp, IWarningLogger logger) 
	{
	    if (r == null)
		throw new ArgumentNullException ();
	    
	    Type t = r.GetType ();
	    List<int> possible_args = new List<int> ();
	    Type best_match = typeof (Result);
	    
	    for (int i = 0; i < args.Length; i++) {
		Type atype = args[i].Type;
		
		// Cannot add an unnamed arg to an ordered arg
		if ((args[i].Flags & ArgFlags.Ordered) != 0)
		    continue;
		
		// Prune out the egregiously wrong arguments (not even a superclass of the result)
		if (! TypeIs (t, atype))
		    continue;
		
		// Prune out those that have been bettered
		if (! TypeIs (atype, best_match))
		    continue;
		
		// If we've narrowed the type further, we don't want any of the
		// previous vaguer matches.
		if (atype.IsSubclassOf (best_match)) {
		    possible_args.Clear ();
		    best_match = atype;
		}
		     
		possible_args.Add (i);
	    }
	    
	    //Console.WriteLine ("Finished with {0} possible arguments", possible_args.Count);
	    
	    if (possible_args.Count == 1) {
		args[possible_args[0]].AddResult (r, fp, -1);
		return false;
	    }
	    
	    if (possible_args.Count > 0) {
		
		// Several possible choices. Check for a default
		foreach (int aid in possible_args) {
		    if ((args[aid].Flags & ArgFlags.Default) != 0) {
			args[aid].AddResult (r, fp, -1);
			return false;
		    }
		}
		
		// No dice. Ambiguity not tolerated. Ah, computers.
		
		StringBuilder sb = new StringBuilder ();
		sb.AppendFormat ("Ambiguous dependency of type {0} could " +
				 "be one of these arguments:", t);
		foreach (int aid in possible_args)
		    sb.AppendFormat (" {0}", args[aid].Name);
		
		logger.Error (2035, sb.ToString (), r.ToString ());
		return true;
	    }

	    // Maybe this is a composite result, and it has a default?
	    // We recurse here, so we tunnel through the composites
	    // sequentially. It's correct to check at every step, rather
	    // than calling FindCompatible, since we don't know what 
	    // type we're looking for.
	    
	    if (r is CompositeResult) {
		CompositeResult cr = (CompositeResult) r;
		
		if (cr.HasDefault) {
		    // See note above about losing FP info in composite results.
		    // this case happens when we are guessing the arg; te 
		    //logger.Warning (9999, "LOSING FINGERPRINT INFO in AC (2)", r.ToString ());
		    
		    if (Add (cr.Default, null, logger) == false)
			return false;
		    
		    // if that didn't work, continue
		    // and give a warning about the container
		    // Result, not the default.
		}
	    }
	    
	    // Bummer.
	    
	    string s = String.Format ("Dependency {0} of type {1} isn't compatible " +
				      "with any defined arguments.", r, t);
	    logger.Error (2034, s, null);
	    return true;
	}
开发者ID:emtees,项目名称:old-code,代码行数:93,代码来源:ArgCollector.cs

示例4: AddNamed

	bool AddNamed (int aid, Result r, Fingerprint fp, 
		       int index_into_values, IWarningLogger logger) 
	{
	    if (aid < 0 || aid >= args.Length) {
		string s = String.Format ("Trying to add {0} to nonexistant " +
					  "argument ID {1}.", r, aid);
		logger.Error (2042, s, r.ToString ());
		return true;
	    }

	    Result subres = CompositeResult.FindCompatible (r, args[aid].Type);

	    if (subres == null) {
		string err = String.Format ("Argument value should be of type {0}, but " +
					    "its type is {1}", args[aid].Type, r.GetType ());
		logger.Error (2036, err, r.ToString ());
		return true;
	    }

	    if (subres == r)
		args[aid].AddResult (r, fp, index_into_values);
	    else
		// FIXME: the FP is really invalid, right?
		args[aid].AddResult (r, null, index_into_values);

	    return false;
	}
开发者ID:emtees,项目名称:old-code,代码行数:27,代码来源:ArgCollector.cs


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