コード例 #1
0
 private static bool Prefix(ref StorySystem __instance)
 {
     if (!Main.enabled || !Main.settings.basicUISettings[10])
     {
         return(true);
     }
     ReflectionMethod.SetValue(__instance, "weatherNumber", 0);
     return(true);
 }
コード例 #2
0
    public void FindAttribute()
    {
        var first   = ReflectData.GetMethod();
        var reflect = new ReflectionMethod(first, new ReflectionFactory());

        var attr = reflect.FindAttribute <DecoratorAttribute>();

        assert.NotNull(attr);
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    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());
    }
コード例 #5
0
    public void Ctor_ThrowsArgumentNull()
    {
        assert.Throws <ArgumentNullException>(() =>
        {
            _ = new ReflectionMethod(null, null);
        });

        assert.Throws <ArgumentNullException>(() =>
        {
            var method = ReflectData.GetMethod();
            _          = new ReflectionMethod(method, null);
        });
    }
コード例 #6
0
 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());
     }
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 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);
             }
         }
     }
 });
コード例 #9
0
    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);
    }
コード例 #10
0
ファイル: Patch.cs プロジェクト: zhishu233/Taiwu_mods
        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);
        }
コード例 #11
0
ファイル: EnumExtension.cs プロジェクト: gangbs/YYGRepository
        public static string GetDescription <T>(this T item)
        {
            var attr = ReflectionMethod.GetFieldInfoAttribute <DescriptionAttribute>(item);

            return(attr == null ? string.Empty : attr.Description);
        }
コード例 #12
0
 /// <summary>
 /// 获取动作的自定义特性列表。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public override IEnumerable <T> GetCustomAttributes <T>()
 {
     return(ReflectionMethod.GetCustomAttributes <T>());
 }
コード例 #13
0
 /// <summary>
 /// 判断是否定义了自定义特性。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public override bool IsDefined <T>()
 {
     return(ReflectionMethod.IsDefined <T>());
 }
コード例 #14
0
 /// <summary>
 /// 获取动作的过滤器特性列表。
 /// </summary>
 /// <returns></returns>
 public override IEnumerable <FilterAttribute> GetFilters()
 {
     return(ReflectionMethod.GetCustomAttributes <FilterAttribute>(false));
 }
コード例 #15
0
 internal CommonMethod(CommonAttribute[] attributes, MonoCecilMethod monoCecilMethod, ReflectionMethod reflectionMethod)
 {
     Attributes       = attributes;
     MonoCecilMethod  = monoCecilMethod;
     ReflectionMethod = reflectionMethod;
 }