BN089-BS开发框架MVC4版/source20131023/Zephyr.Net/Zephyr.Utils/Reflection/ZGeneric.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
namespace Zephyr.Utils
{
public class ZGeneric
{
public static bool IsDynamicType(Type type)
{
return type.Equals(typeof(ExpandoObject)) || type.Equals(typeof(object));
}
public static bool IsNullableType(Type theType)
{
return (theType.IsGenericType && theType.
GetGenericTypeDefinition().Equals
(typeof(Nullable<>)));
}
public static Type GetGenericType(object list)
{
return list.GetType().GetGenericArguments()[0];
}
public static bool IsTypeIgoreNullable<T>(object value)
{
if (null == value) return false;
Type type = value.GetType();
if (type.IsGenericType)
type = type.GetGenericArguments()[0];
return type.Equals(typeof(T));
}
public static T CreateNew<T>()
{
if (IsDynamicType(typeof(T)))
return (T)(IDictionary<string, object>)new ExpandoObject();
return Activator.CreateInstance<T>();
}
public static object GetValue(object item, string name)
{
if (IsDynamicType(item.GetType()))
return ZReflection.GetPropertyValueDynamic(item, name);
return ZReflection.GetPropertyValue(item, name);
}
public static void SetValue(object item,string name,object value)
{
Type type = item.GetType();
if (IsDynamicType(type))
((IDictionary<string, object>)item).Add(name, value);
后面还有 37 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。