static public bool AllPropertiesEquals <T>(this T obj1, T obj2) { var typeCache = TypeResolver.ByType(typeof(T)); var props = typeCache.GetProperties(); return(props.Any(p => !p.GetValue(obj1).Equals(p.GetValue(obj2)))); }
/// <summary> /// Convert CodeProperty2 to PropertyInfo. Cached /// </summary> /// <param name="prop"></param> /// <returns></returns> /// <remarks></remarks> public static PropertyInfo ToPropertyInfo(this CodeProperty2 prop) { var t = prop.Parent.ToType(); var classType = TypeResolver.ByType(t); return(classType.TypeInfo.GetProperty(prop.Name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)); }
/// <summary> /// Convert CodeAttribute into an actual Attribute instance /// </summary> /// <typeparam name="TAttr"></typeparam> /// <param name="codeAttr"></param> /// <returns></returns> public static TAttr ToAttribute <TAttr>(this CodeAttribute2 codeAttr) where TAttr : Attribute, new() { var typeCache = TypeResolver.ByType <TAttr>(); var attr = new TAttr(); foreach (var arg in codeAttr.GetArguments()) { var propInfo = (PropertyInfo)typeCache[arg.Name]; propInfo.SetValue(attr, ParseAttributeProperty(propInfo.PropertyType, arg.Value)); } return(attr); }
static EnumConverter() { TypeCache typeCache = TypeResolver.ByType <StringEnumConverter>(); EnumMemberNamesPerType = ((FieldInfo) typeCache.TypeInfo .GetMember("EnumMemberNamesPerType", BindingFlags.NonPublic | BindingFlags.Static) .Single() ).GetValue(null); EnumMemberNamesPerType_Get = (MethodInfo)EnumMemberNamesPerType.GetType().GetMember("Get").Single(); Map_TryGetByFirst = (MethodInfo)EnumMemberNamesPerType_Get.ReturnType.GetMember("TryGetByFirst").Single(); // ReSharper disable once PossibleNullReferenceException StringUtils_ToCamelCase = (MethodInfo)typeof(StringEnumConverter).Assembly .GetType("Newtonsoft.Json.Utilities.StringUtils") .GetMember("ToCamelCase").Single(); }