2013-08-29 6 views
10

.NETポータブルクラスライブラリに.ToShortDateStringが存在しないのはなぜですか?私は、同じコードを使用する2つのプロジェクト(Silverlightと通常の.NETクラスライブラリ)を持っており、コードはDateTimeオブジェクトで.ToShortDateString()を呼び出します。 2つの場所で同じコードをコピーするのではなく、同じコードを再利用するために、移植可能なクラスライブラリを作成して、Silverlightと.NETクラスライブラリの両方でインポートできるようにしました。残念ながら、クラスライブラリを使用しているときは.ToShortDateString()が利用可能ではないようです。私は移植可能なクラスライブラリメソッドで文字列パラメータを受け入れて、.ToShortDateString()の値をsilverlightとclassライブラリプロジェクトの両方から渡すことができますが、なぜこのメソッドが移植可能なライブラリのネイティブではないのだろうと思います。それは文化の問題ですか?.NETで.ToShortDateStringに何が起こったのですか。ポータブルクラスライブラリ

+5

私の推測では、PCLを小さく保ち、 'ToString(" d ")'を行うことができるからです。 – cadrell0

+0

ありがとうございました! – Misha

答えて

4

System名前空間で定義された型に属するメソッド/プロパティのほとんどはPCLで使用できますが、いくつかの例外があり、ToShortDateStringもその1つです。以下は、移植可能なDateTimeメンバの一覧です。私はいくつかの文字列変換メソッドの除外の理由は何だったのか分からないが、これは冗長性によるものだと思う。 cadrell0が指摘しているように、パラメーターを指定してToStringを使用することで、常に同じことを達成できます。

T:System.DateTime 
M:System.DateTime.ToString(System.String) 
M:System.DateTime.op_GreaterThan(System.DateTime,System.DateTime) 
M:System.DateTime.ParseExact(System.String,System.String[],System.IFormatProvider,System.Globalization.DateTimeStyles) 
M:System.DateTime.get_Month 
M:System.DateTime.FromFileTimeUtc(System.Int64) 
M:System.DateTime.get_Date 
M:System.DateTime.get_TimeOfDay 
M:System.DateTime.get_Kind 
M:System.DateTime.ToUniversalTime 
M:System.DateTime.get_Year 
M:System.DateTime.op_Subtraction(System.DateTime,System.TimeSpan) 
M:System.DateTime.get_Second 
M:System.DateTime.get_DayOfWeek 
M:System.DateTime.TryParse(System.String,System.IFormatProvider,System.Globalization.DateTimeStyles,[email protected]) 
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32) 
M:System.DateTime.get_Day 
P:System.DateTime.Date 
M:System.DateTime.op_Addition(System.DateTime,System.TimeSpan) 
M:System.DateTime.IsDaylightSavingTime 
M:System.DateTime.get_DayOfYear 
M:System.DateTime.ToFileTime 
M:System.DateTime.Subtract(System.DateTime) 
M:System.DateTime.IsLeapYear(System.Int32) 
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.DateTimeKind) 
M:System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider,System.Globalization.DateTimeStyles) 
P:System.DateTime.Day 
M:System.DateTime.get_Hour 
M:System.DateTime.Equals(System.DateTime) 
M:System.DateTime.get_UtcNow 
M:System.DateTime.get_Today 
M:System.DateTime.TryParse(System.String,[email protected]) 
P:System.DateTime.Kind 
M:System.DateTime.System#IComparable#CompareTo(System.Object) 
P:System.DateTime.UtcNow 
P:System.DateTime.Hour 
P:System.DateTime.Millisecond 
M:System.DateTime.Parse(System.String) 
F:System.DateTime.MinValue 
M:System.DateTime.op_GreaterThanOrEqual(System.DateTime,System.DateTime) 
M:System.DateTime.#ctor(System.Int64,System.DateTimeKind) 
M:System.DateTime.GetHashCode 
P:System.DateTime.Year 
M:System.DateTime.Add(System.TimeSpan) 
M:System.DateTime.Equals(System.DateTime,System.DateTime) 
M:System.DateTime.ToString(System.IFormatProvider) 
M:System.DateTime.get_Now 
P:System.DateTime.Month 
M:System.DateTime.DaysInMonth(System.Int32,System.Int32) 
M:System.DateTime.AddMinutes(System.Double) 
M:System.DateTime.get_Minute 
M:System.DateTime.#ctor(System.Int64) 
M:System.DateTime.op_LessThanOrEqual(System.DateTime,System.DateTime) 
M:System.DateTime.ToString(System.String,System.IFormatProvider) 
P:System.DateTime.DayOfYear 
M:System.DateTime.AddMilliseconds(System.Double) 
P:System.DateTime.Second 
P:System.DateTime.DayOfWeek 
M:System.DateTime.op_Equality(System.DateTime,System.DateTime) 
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32) 
M:System.DateTime.TryParseExact(System.String,System.String,System.IFormatProvider,System.Globalization.DateTimeStyles,[email protected]) 
M:System.DateTime.ToFileTimeUtc 
P:System.DateTime.Today 
M:System.DateTime.op_LessThan(System.DateTime,System.DateTime) 
M:System.DateTime.get_Millisecond 
M:System.DateTime.op_Subtraction(System.DateTime,System.DateTime) 
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32) 
M:System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) 
M:System.DateTime.AddSeconds(System.Double) 
M:System.DateTime.AddMonths(System.Int32) 
M:System.DateTime.AddYears(System.Int32) 
M:System.DateTime.Parse(System.String,System.IFormatProvider,System.Globalization.DateTimeStyles) 
M:System.DateTime.get_Ticks 
P:System.DateTime.Ticks 
M:System.DateTime.TryParseExact(System.String,System.String[],System.IFormatProvider,System.Globalization.DateTimeStyles,[email protected]) 
M:System.DateTime.ToLocalTime 
M:System.DateTime.op_Inequality(System.DateTime,System.DateTime) 
M:System.DateTime.SpecifyKind(System.DateTime,System.DateTimeKind) 
M:System.DateTime.AddHours(System.Double) 
P:System.DateTime.Minute 
M:System.DateTime.Subtract(System.TimeSpan) 
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.DateTimeKind) 
F:System.DateTime.MaxValue 
M:System.DateTime.ToString 
M:System.DateTime.FromFileTime(System.Int64) 
P:System.DateTime.TimeOfDay 
M:System.DateTime.Compare(System.DateTime,System.DateTime) 
M:System.DateTime.CompareTo(System.DateTime) 
M:System.DateTime.Parse(System.String,System.IFormatProvider) 
M:System.DateTime.AddDays(System.Double) 
P:System.DateTime.Now 
M:System.DateTime.Equals(System.Object) 
M:System.DateTime.AddTicks(System.Int64) 
6

私たちは、私が(What is .NET Portable Subset (Legacy)?)ここでのヒント「現代」表面積を、考えるものからその使用をdeemphasizeして除去しました。つまり、新しいプラットフォーム(Windows Storeアプリなど)は表示されず、ポータブルライブラリには表示されません。

"d"をDateTime.ToString()に渡すだけで、その動作を模倣できます。

これは、Windows OSレベルで表現されていない唯一の.NET Frameworkの日付形式であるため、その使用を除外したいと考えました。これにより、ユーザーが行った書式の変更が反映されず/尊重されなくなります。特定の組織や政府では、これらの設定を尊重することが重要です。

+1

削除されたのが唯一のものだった場合、 'ToShortTimeString'が削除された理由は何ですか? (そして文字列は何ですか?それを置き換えるために使用する形式ですか?) – BrainSlugs83

関連する問題