随笔-313  评论-12138  文章-1  trackbacks-256

Microsoft AJAX Library Cheat Sheet(5): Number和Error类型的扩展

本文为翻译,英文原版的Cheat Sheet(PDF版本)在此下载:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip

原作版权声明:

Copyright (c) 2004-2006, Milan Negovan 
http://www.AspNetResources.com
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
are met:

    * Redistributions of source code must retain the above copyright 
      notice, this list of conditions and the following disclaimer.
      
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in 
      the documentation and/or other materials provided with the 
      distribution.
      
    * The name of the author may not be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

注:标注有[S]的为静态方法,无须实例化对象即可使用。

 

Number.format (format)

用指定的format格式化数字(区域设定无关)。

 

Number.localeFormat (format)

用指定的format格式化数字(区域设定相关)。

 

支持的格式

  1. p:将数字转为百分比字符串(e.g.: -1,234.56 %)
  2. d:将数字装化为十进制字符串,没有逗号分隔符(e.g.: -1234.56)
  3. c:将数字转化为货币金额形式(e.g.: (¤1,234.56))
  4. n:将数字串化为逗号三位分隔(-d,ddd,ddd.ddd…")形式(e.g.: -1,234.56)

 

[S] Number.parseLocale (value)

从字符串表示的本地数字解析成相应的Number类型。使用Sys.CultureInfo.CurrentCulture得到当前的区域属性。

 

[S] Number.parseInvariant (value)

从字符串表示的本地数字解析成相应的浮点数Number类型。value中可以包含逗号分隔符(,)或是正负(+-)号。

var a = new Number();
a = Number.parseInvariant("4");
var b = new Number(2);
var c = Number.parseInvariant("1.53") + a + b;
// c = 7.53

 

Error相关的方法

  1. [S] Error.argument:根据指定的异常信息和非法的参数创建一个Sys.ArgumentException类型的异常。
  2. [S] Error.argumentNull:根据指定的异常信息和为Null的参数创建一个Sys.ArgumentNullException 类型的异常。
  3. [S] Error.argumentType:根据指定的异常信息、期待参数类型和实际参数类型创建一个Sys.ArgumentTypeException 类型的异常。
  4. [S] Error.argumentUndefined:根据指定的异常信息和为定义的参数创建一个Sys.ArgumentUndefinedException类型的异常。
  5. [S] Error.create:根据指定的异常信息创建一个Error对象。
  6. [S] Error.invalidOperation:根据指定的异常信息和引发该异常的参数创建一个Sys.InvalidOperationException 类型的异常。
  7. [S] Error.notImplemented:根据指定的异常信息创建一个Sys.NotImplementedException类型的异常。
  8. [S] Error.argumentOutOfRange:根据指定的异常信息和引发该异常的参数创建一个Sys.ArgumentOutOfRangeException类型的异常。
  9. [S] Error.parameterCount:根据指定的异常信息创建一个Sys.ParameterCountException 类型的异常。
  10. Error.popstackFrame:将该Error实例的fileName和lineNumber字段更新为该Error被掷出时的位置,而不是该Error被创建时的位置。
// Throw a standard exception type
var err = Error.argumentNull("input", "A parameter was undefined.");
throw err;
// Throw a generic error with a message and associated errorInfo object.
var errorInfoObj = { name: "SomeNamespace.SomeExceptionName",
someErrorID: "436" };
var err = Error.create("A test message", errorInfoObj);
throw err;
posted on 2007-02-09 21:00 Dflying Chen 阅读(2498) 评论(1) 编辑 收藏

评论:
#1楼 2007-05-09 08:16 | fdf[未注册用户]
[url=http://aiguiling.googlepages.com/SBZX.htm]失败造型[/url]
[url=http://aiguiling.googlepages.com/YZQS.htm]中国泳装趋势[/url]
[url=http://aiguiling.googlepages.com/XYQS.htm]校园趣事[/url]
[url=http://aiguiling.googlepages.com/HBHU.htm]婚博会[/url]
[url=http://aiguiling.googlepages.com/ZMCS.htm]著名厕所[/url]
[url=http://aiguiling.googlepages.com/YXHH.htm]游戏祸害[/url]
[url=http://aiguiling.googlepages.com/DMMX.htm]倒霉明星[/url]
[url=http://aiguiling.googlepages.com/YFYH.htm]切腹诱惑丈夫[/url]
[url=http://aiguiling.googlepages.com/YYBL.htm]校园暴力[/url]
[url=http://aiguiling.googlepages.com/YMYD.htm]不要命的运动[/url]
[url=http://aiguiling.googlepages.com/ZYRW.htm]争议人物[/url]
[url=http://aiguiling.googlepages.com/SDLY.htm]十大灵异[/url]
[url=http://aiguiling.googlepages.com/MXXW.htm]明星新闻[/url]
[url=http://aiguiling.googlepages.com/HDJJ.htm]荒诞禁令排行榜[/url]
[url=http://aiguiling.googlepages.com/BYMN.htm]北影美女[/url]
[url=http://aiguiling.googlepages.com/HJNJ.htm]中南海罕见内景[/url]
[url=http://aiguiling.googlepages.com/GUMA.htm]国骂[/url]
[url=http://aiguiling.googlepages.com/HLXX.htm]红楼梦选秀[/url]
[url=http://aiguiling.googlepages.com/WMSC.htm]完美身材排行[/url]

 回复 引用   
除非特别声明,本站内所有资源,包括但不限于文章,代码,图片等,均应用于Dflying版权说明
关于ASP.NET AJAX,您可以:
直接阅读ASP.NET AJAX文章分类
Atlas文章打包下载(截至4/28/2006)
加入ASP.NET AJAX学习团队
询问关于ASP.NET AJAX的问题
加入ASP.NET AJAX讨论群
阅读愚作《ASP.NET AJAX程序设计》
点击阅读
点击阅读


关于Windows Vista,您可以:
加入Windows Vista开发团队!
昵称:Dflying Chen
园龄:5年10个月
粉丝:127
关注:0

搜索

 
 

最新随笔

随笔分类(352)

随笔档案(313)

Blog Roll

Dflying的其他Blog

Online Chat

统计信息

积分与排名

  • 积分 - 2442898
  • 排名 - 7

最新评论

阅读排行榜

评论排行榜