GMap.NET.Core/GMap.NET/Extensions.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace GMap.NET
{
using System;
using System.Runtime.Serialization;
using System.Diagnostics;
public static class Extensions
{
/// <summary>
/// Retrieves a value from the SerializationInfo of the given type.
/// </summary>
/// <typeparam name="T">The Type that we are attempting to de-serialize.</typeparam>
/// <param name="info">The SerializationInfo.</param>
/// <param name="key">The key of the value we wish to retrieve.</param>
/// <returns>The value if found, otherwise null.</returns>
public static T GetValue<T>(SerializationInfo info, string key) where T : class
{
try
{
// Return the value from the SerializationInfo, casting it to type T.
return info.GetValue(key, typeof(T)) as T;
}
catch(Exception ex)
{
Debug.WriteLine("Extensions.GetValue: " + ex.Message);
return null;
}
}
/// <summary>
/// Retrieves a value from the SerializationInfo of the given type.
/// </summary>
/// <typeparam name="T">The Type that we are attempting to de-serialize.</typeparam>
/// <param name="info">The SerializationInfo.</param>
/// <param name="key">The key of the value we wish to retrieve.</param>
/// <param name="defaultValue">The default value if the de-serialized value was null.</param>
/// <returns>The value if found, otherwise the default value.</returns>
public static T GetValue<T>(SerializationInfo info, string key, T defaultValue) where T : class
{
T deserializedValue = GetValue<T>(info, key);
if(deserializedValue != null)
{
return deserializedValue;
}
return defaultValue;
}
/// <summary>
/// Retrieves a value from the SerializationInfo of the given type for structs.
/// </summary>
/// <typeparam name="T">The Type that we are attempting to de-serialize.</typeparam>
/// <param name="info">The SerializationInfo.</param>
/// <param name="key">The key of the value we wish to retrieve.</param>
/// <param name="defaultValue">The default value if the de-serialized value was null.</param>
/// <returns>The value if found, otherwise the default value.</returns>
public static T GetStruct<T>(SerializationInfo info, string key, T defaultValue) where T : struct
{
try
后面还有 32 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
