本文整理匯總了C#中System.DateTimeRawInfo.Init方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeRawInfo.Init方法的具體用法?C# DateTimeRawInfo.Init怎麽用?C# DateTimeRawInfo.Init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTimeRawInfo
的用法示例。
在下文中一共展示了DateTimeRawInfo.Init方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TryParse
internal static unsafe bool TryParse(string s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
{
DateTime time;
if (s == null)
{
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (s.Length == 0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
DS bEGIN = DS.BEGIN;
bool flag = false;
DateTimeToken dtok = new DateTimeToken {
suffix = TokenType.SEP_Unk
};
DateTimeRawInfo raw = new DateTimeRawInfo();
int* numberBuffer = stackalloc int[3];
raw.Init(numberBuffer);
result.calendar = dtfi.Calendar;
result.era = 0;
__DTString str = new __DTString(s, dtfi);
str.GetNext();
do
{
if (!Lex(bEGIN, ref str, ref dtok, ref raw, ref result, ref dtfi))
{
return false;
}
if (dtok.dtt != DTT.Unk)
{
if (dtok.suffix != TokenType.SEP_Unk)
{
if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
dtok.suffix = TokenType.SEP_Unk;
}
if (dtok.dtt == DTT.NumLocalTimeMark)
{
switch (bEGIN)
{
case DS.D_YNd:
case DS.D_YN:
return ParseISO8601(ref raw, ref str, styles, ref result);
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
bEGIN = dateParsingStates[(int) bEGIN][(int) dtok.dtt];
if (bEGIN == DS.ERROR)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (bEGIN > DS.ERROR)
{
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != DateTimeFormatFlags.None)
{
if (!ProcessHebrewTerminalState(bEGIN, ref result, ref styles, ref raw, dtfi))
{
return false;
}
}
else if (!ProcessTerminaltState(bEGIN, ref result, ref styles, ref raw, dtfi))
{
return false;
}
flag = true;
bEGIN = DS.BEGIN;
}
}
}
while (((dtok.dtt != DTT.End) && (dtok.dtt != DTT.NumEnd)) && (dtok.dtt != DTT.MonthEnd));
if (!flag)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
AdjustTimeMark(dtfi, ref raw);
if (!AdjustHour(ref result.Hour, raw.timeMark))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
bool bTimeOnly = ((result.Year == -1) && (result.Month == -1)) && (result.Day == -1);
if (!CheckDefaultDateTime(ref result, ref result.calendar, styles))
{
return false;
}
if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out time))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (raw.fraction > 0.0)
//.........這裏部分代碼省略.........
示例2: TryParse
[System.Security.SecuritySafeCritical] // auto-generated
internal static bool TryParse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result) {
if (s == null) {
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (s.Length == 0) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
Contract.Assert(dtfi != null, "dtfi == null");
#if _LOGGING
DTFITrace(dtfi);
#endif
DateTime time;
//
// First try the predefined format.
//
DS dps = DS.BEGIN; // Date Parsing State.
bool reachTerminalState = false;
DateTimeToken dtok = new DateTimeToken(); // The buffer to store the parsing token.
dtok.suffix = TokenType.SEP_Unk;
DateTimeRawInfo raw = new DateTimeRawInfo(); // The buffer to store temporary parsing information.
unsafe {
Int32 * numberPointer = stackalloc Int32[3];
raw.Init(numberPointer);
}
raw.hasSameDateAndTimeSeparators = dtfi.DateSeparator.Equals(dtfi.TimeSeparator, StringComparison.Ordinal);
result.calendar = dtfi.Calendar;
result.era = Calendar.CurrentEra;
//
// The string to be parsed. Use a __DTString wrapper so that we can trace the index which
// indicates the begining of next token.
//
__DTString str = new __DTString(s, dtfi);
str.GetNext();
//
// The following loop will break out when we reach the end of the str.
//
do {
//
// Call the lexer to get the next token.
//
// If we find a era in Lex(), the era value will be in raw.era.
if (!Lex(dps, ref str, ref dtok, ref raw, ref result, ref dtfi, styles))
{
TPTraceExit("0000", dps);
return false;
}
//
// If the token is not unknown, process it.
// Otherwise, just discard it.
//
if (dtok.dtt != DTT.Unk)
{
//
// Check if we got any CJK Date/Time suffix.
// Since the Date/Time suffix tells us the number belongs to year/month/day/hour/minute/second,
// store the number in the appropriate field in the result.
//
if (dtok.suffix != TokenType.SEP_Unk)
{
if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
TPTraceExit("0010", dps);
return false;
}
dtok.suffix = TokenType.SEP_Unk; // Reset suffix to SEP_Unk;
}
if (dtok.dtt == DTT.NumLocalTimeMark) {
if (dps == DS.D_YNd || dps == DS.D_YN) {
// Consider this as ISO 8601 format:
// "yyyy-MM-dd'T'HH:mm:ss" 1999-10-31T02:00:00
TPTraceExit("0020", dps);
return (ParseISO8601(ref raw, ref str, styles, ref result));
}
else {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
TPTraceExit("0030", dps);
return false;
}
}
if (raw.hasSameDateAndTimeSeparators)
{
if (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep)
{
// When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized
//.........這裏部分代碼省略.........
示例3: TryParse
//
// This is the real method to do the parsing work.
//
internal static bool TryParse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result) {
if (s == null) {
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (s.Length == 0) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
BCLDebug.Assert(dtfi != null, "dtfi == null");
DateTime time;
//
// First try the predefined format.
//
DS dps = DS.BEGIN; // Date Parsing State.
bool reachTerminalState = false;
DateTimeToken dtok = new DateTimeToken(); // The buffer to store the parsing token.
dtok.suffix = TokenType.SEP_Unk;
DateTimeRawInfo raw = new DateTimeRawInfo(); // The buffer to store temporary parsing information.
unsafe {
Int32 * numberPointer = stackalloc Int32[3];
raw.Init(numberPointer);
}
result.calendar = dtfi.Calendar;
result.era = Calendar.CurrentEra;
//
// The string to be parsed. Use a __DTString wrapper so that we can trace the index which
// indicates the begining of next token.
//
__DTString str = new __DTString(s, dtfi);
str.GetNext();
//
// The following loop will break out when we reach the end of the str.
//
do {
//
// Call the lexer to get the next token.
//
// If we find a era in Lex(), the era value will be in raw.era.
if (!Lex(dps, ref str, ref dtok, ref raw, ref result, ref dtfi)) {
return false;
}
//
// If the token is not unknown, process it.
// Otherwise, just discard it.
//
if (dtok.dtt != DTT.Unk)
{
//
// Check if we got any CJK Date/Time suffix.
// Since the Date/Time suffix tells us the number belongs to year/month/day/hour/minute/second,
// store the number in the appropriate field in the result.
//
if (dtok.suffix != TokenType.SEP_Unk)
{
if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
dtok.suffix = TokenType.SEP_Unk; // Reset suffix to SEP_Unk;
}
if (dtok.dtt == DTT.NumLocalTimeMark) {
if (dps == DS.D_YNd || dps == DS.D_YN) {
return (ParseISO8601(ref raw, ref str, styles, ref result));
}
else {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
//
// Advance to the next state, and continue
//
dps = dateParsingStates[(int)dps][(int)dtok.dtt];
if (dps == DS.ERROR)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
else if (dps > DS.ERROR)
{
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != 0) {
if (!ProcessHebrewTerminalState(dps, ref result, ref raw, dtfi)) {
return false;
}
//.........這裏部分代碼省略.........