public override DaylightTime GetDaylightChanges(int year) { if (year < 1 || year > 9999) { throw new ArgumentOutOfRangeException("year", String.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, 9999)); } Object objYear = (Object)year; if (!m_CachedDaylightChanges.Contains(objYear)) { BCLDebug.Log("Getting TimeZone information for: " + objYear); lock (typeof(CurrentSystemTimeZone)) { if (!m_CachedDaylightChanges.Contains(objYear)) { // // rawData is an array of 17 short (16 bit) numbers. // The first 8 numbers contains the // year/month/day/dayOfWeek/hour/minute/second/millisecond for the starting time of daylight saving time. // The next 8 numbers contains the // year/month/day/dayOfWeek/hour/minute/second/millisecond for the ending time of daylight saving time. // The last short number is the delta to the standard offset in minutes. // short[] rawData = nativeGetDaylightChanges(); if (rawData == null) { // // If rawData is null, it means that daylight saving time is not used // in this timezone. So keep currentDaylightChanges as the empty array. // m_CachedDaylightChanges.Add(objYear, new DaylightTime(DateTime.MinValue, DateTime.MinValue, TimeSpan.Zero)); } else { DateTime start; DateTime end; TimeSpan delta; // // Store the start of daylight saving time. // start = GetDayOfWeek(year, rawData[1], rawData[2], rawData[3], rawData[4], rawData[5], rawData[6], rawData[7]); // // Store the end of daylight saving time. // end = GetDayOfWeek(year, rawData[9], rawData[10], rawData[11], rawData[12], rawData[13], rawData[14], rawData[15]); delta = new TimeSpan(rawData[16] * TicksPerMinute); DaylightTime currentDaylightChanges = new DaylightTime(start, end, delta); m_CachedDaylightChanges.Add(objYear, currentDaylightChanges); } } } } DaylightTime result = (DaylightTime)m_CachedDaylightChanges[objYear]; return(result); }
// GetRealObject uses the data we have in m_data and m_unityType to do a lookup on the correct // object to return. We have specific code here to handle the different types which we support. // The reflection types (Assembly, Module, and Type) have to be looked up through their static // accessors by name. public virtual Object GetRealObject(StreamingContext context) { Assembly assem; BCLDebug.Trace("SER", "[GetRealObject] UnityType:", m_unityType); switch (m_unityType) { case EmptyUnity: BCLDebug.Trace("SER", "[GetRealObject]Returning Empty.Value"); BCLDebug.Trace("SER", "[GetRealObject]Empty's value is: ", Empty.Value, "||"); return(Empty.Value); case NullUnity: return(DBNull.Value); case MissingUnity: return(Missing.Value); case RuntimeTypeUnity: if (m_data == null || m_data.Length == 0 || m_assemName == null) { BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Type. Data is: ", m_data); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } if (m_assemName.Length == 0) { return(RuntimeType.GetTypeInternal(m_data, false, false, false)); } assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName); if (assem == null) { BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Type. AssemblyName is: ", m_assemName, " but we can't load it."); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } Type t = assem.GetTypeInternal(m_data, false, false, false); return(t); case ModuleUnity: if (m_data == null || m_data.Length == 0 || m_assemName == null) { BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. Data is: ", m_data); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName); if (assem == null) { BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. AssemblyName is: ", m_assemName, " but we can't load it."); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } Module namedModule = assem.GetModule(m_data); if (namedModule == null) { throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFindModule")); } return(namedModule); case AssemblyUnity: if (m_data == null || m_data.Length == 0 || m_assemName == null) { BCLDebug.Log("UnitySerializationHolder.GetRealObject. Assembly. Data is: " + ((m_data == null)?"<null>":m_data)); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } assem = FormatterServices.LoadAssemblyFromStringNoThrow(m_assemName); if (assem == null) { BCLDebug.Trace("SER", "UnitySerializationHolder.GetRealObject Module. AssemblyName is: ", m_assemName, " but we can't load it."); throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientDeserializationState")); } return(assem); default: //This should never happen because we only use the class internally. throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUnity")); } }