private static bool Prefix(ref StorySystem __instance) { if (!Main.enabled || !Main.settings.basicUISettings[10]) { return(true); } ReflectionMethod.SetValue(__instance, "weatherNumber", 0); return(true); }
public void FindAttribute() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var attr = reflect.FindAttribute <DecoratorAttribute>(); assert.NotNull(attr); }
public void FindAttributes() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var attrs = reflect.FindAttributes <DecoratorAttribute>(); assert.NotNull(attrs); assert.Equal(1, attrs.Count); }
public void Invoke() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var data = new ReflectData(); var result = reflect.Invoke(data, "first", "last", DateTime.UtcNow); assert.NotNull(result); assert.IsType <string>(result); assert.Equal("Mike Tyson", result.ToString()); }
public void Ctor_ThrowsArgumentNull() { assert.Throws <ArgumentNullException>(() => { _ = new ReflectionMethod(null, null); }); assert.Throws <ArgumentNullException>(() => { var method = ReflectData.GetMethod(); _ = new ReflectionMethod(method, null); }); }
private void SetupReflection(Assembly Assembly) { try { m_startupArgsField = new ReflectionField("CommandLineArgs", ClassName, m_classType); m_startupMethod = new ReflectionMethod(InitMethod, ClassName, m_classType); m_stopMethod = new ReflectionMethod(StopMethod, ClassName, m_classType); } catch (ArgumentException ex) { mainLog.Error(ex.ToString()); } }
static EntityMapperCacheItem GetEntityMapperCacheItem(string key, System.Reflection.Assembly assembly, IEnumerable <Type> types) { foreach (var t in types) { var et = t.BaseType.GetGenericArguments().SingleOrDefault(); var entityName = et.Name; if (entityName == key) { var e = new EntityMapperCacheItem(entityName) { Value = ReflectionMethod.CreateObject(assembly, t), Expire = DateTime.MaxValue, Type = CacheType.Application }; return(e); } } return(null); }
static async void TaskAsyncLoad(EntityMapperCacheManager cache, IEnumerable <Type> types) => await Task.Run(() => { foreach (var t in types) { var et = t.BaseType.GetGenericArguments().SingleOrDefault(); if (et != null) { var entityName = et.Name; if (!cache.ContainsKey(entityName)) { var e = new EntityMapperCacheItem(entityName) { Value = ReflectionMethod.CreateObject(cache._assembly, t), Expire = DateTime.MaxValue, Type = CacheType.Application }; cache.Add(e.Key, e); } } } });
public void Ctor() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod( first, new ReflectionFactory()); assert.Equal(first.Name, reflect.Name); assert.Equal(first.DeclaringType, reflect.ClrType); assert.Equal(first.ReturnParameter, reflect.ReturnParameter.ParameterInfo); assert.Equal(false, reflect.IsGenericMethodDefinition); assert.Equal(0, reflect.GenericArguments.Count); var mods = reflect.ModifierAccess; assert.Equal(true, mods.IsPublic); assert.Equal(false, mods.IsPrivate); assert.Equal(false, mods.IsInternal); assert.Equal(false, mods.IsVirtual); assert.Equal(false, mods.IsStatic); assert.Equal(true, mods.IsInstance); }
private static bool Prefix(SaveDateFile __instance) { if (!Main.Enabled || UIDate.instance == null) { return(true); } if (__instance.saveSaveDate) { if (Main.ForceSave) { Main.ForceSave = false; UIDate.instance.trunSaveText.text = "手动存档"; } else if (Main.settings.blockAutoSave) { UIDate.instance.trunSaveText.text = "由于您的MOD设置,游戏未保存"; __instance.saveSaveDate = false; return(true); } // 写入date.json WriteSaveSummary(); } if (ReflectionMethod.GetValue <SaveDateFile, bool>(__instance, "saveSaveDateOK1") && ReflectionMethod.GetValue <SaveDateFile, bool>(__instance, "saveSaveDateOK2") && ReflectionMethod.GetValue <SaveDateFile, bool>(__instance, "saveSaveDateOK3")) { ReflectionMethod.SetValue(__instance, "saveSaveDateOK1", false); ReflectionMethod.SetValue(__instance, "saveSaveDateOK2", false); ReflectionMethod.SetValue(__instance, "saveSaveDateOK3", false); Task.Run(new Action(EnsureFiles)); return(false); } return(true); }
public static string GetDescription <T>(this T item) { var attr = ReflectionMethod.GetFieldInfoAttribute <DescriptionAttribute>(item); return(attr == null ? string.Empty : attr.Description); }
/// <summary> /// 获取动作的自定义特性列表。 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public override IEnumerable <T> GetCustomAttributes <T>() { return(ReflectionMethod.GetCustomAttributes <T>()); }
/// <summary> /// 判断是否定义了自定义特性。 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public override bool IsDefined <T>() { return(ReflectionMethod.IsDefined <T>()); }
/// <summary> /// 获取动作的过滤器特性列表。 /// </summary> /// <returns></returns> public override IEnumerable <FilterAttribute> GetFilters() { return(ReflectionMethod.GetCustomAttributes <FilterAttribute>(false)); }
internal CommonMethod(CommonAttribute[] attributes, MonoCecilMethod monoCecilMethod, ReflectionMethod reflectionMethod) { Attributes = attributes; MonoCecilMethod = monoCecilMethod; ReflectionMethod = reflectionMethod; }