public static bool IsAnimalPlacementMode(this PurchaseAnimalsMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <bool>(menu, "onFarm").GetValue() &&
                   !reflector.GetField <bool>(menu, "namingAnimal").GetValue());
        }
        static RepoDbQueryGroupProxy()
        {
            var repoDbAssembly = typeof(QueryGroup).Assembly;

            //BBernard
            //Safely try to resolve a Proxy for 'GetDataReaderToDataEntityFunction' which is the method in RepoDb v1.12.4
            //Find the method via Reflection and compile into a local Expression Delegate for performance!
            _mapToQueryGroupTypeMapProxy = StaticReflectionHelper.FindStaticMethod(
                repoDbAssembly.GetType("RepoDb.Extensions.QueryGroupExtension"),
                "MapTo",
                //Types Stubbed for matching with object placeholder for internal unknown type...
                //Signature: QueryGroupTypeMap MapTo(this QueryGroup queryGroup, Type entityType)
                new Type[] { typeof(QueryGroup), typeof(Type) }
                )?.CreateDynamicDelegate();

            _asMappedParamObjectProxy = StaticReflectionHelper.FindStaticMethod(
                repoDbAssembly.GetType("RepoDb.QueryGroup"),
                "AsMappedObject",
                //Types Stubbed for matching with object placeholder for internal unknown type...
                //Signature: AsMappedObject(QueryGroupTypeMap[] queryGroupTypeMaps, bool fixParameters = true)
                //NOTE: QueryGroupTypeMap is an internal type so we can't use it directly.
                new Type[] { typeof(object), typeof(bool) }
                )?.CreateDynamicDelegate();

            //Now Validate that we have at least one Proxy... or else throw an Exception Early
            if (_mapToQueryGroupTypeMapProxy == null || _asMappedParamObjectProxy == null)
            {
                throw new Exception(
                          $"Could not initialize the [{nameof(RepoDbQueryGroupProxy)}];" +
                          $" the methods to be proxied for [{nameof(GetMappedParamsObject)}] is null and/or could not be found." +
                          $" This could be related to change in RepoDb version (source code has changed); please verify the version or update" +
                          $" this method to account for any differences."
                          );
            }
        }
        private void OnGUI()
        {
            GUILayout.Label("Members");

            if (GUILayout.Button("Get TestClass field name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName <TestClass>(c => c.testField);
                Debug.Log(memberName);
            }

            if (GUILayout.Button("Get TestClass property name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName <TestClass>(c => c.testProperty);
                Debug.Log(memberName);
            }

            if (GUILayout.Button("Get TestClass static field name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName(() => TestClass.staticTestField);
                Debug.Log(memberName);
            }

            if (GUILayout.Button("Get TestClass static property name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName(() => TestClass.staticTestProperty);
                Debug.Log(memberName);
            }

            GUILayout.Label("Methods");

            if (GUILayout.Button("Get TestClass method name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName <TestClass>(c => c.TestMethod());
                var    methodInfo = StaticReflectionHelper.GetMethod <TestClass>(c => c.TestMethod());
                Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name);
            }

            if (GUILayout.Button("Get TestClass no return method name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName <TestClass>(c => c.TestMethodNoReturn());
                var    methodInfo = StaticReflectionHelper.GetMethod <TestClass>(c => c.TestMethodNoReturn());
                Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name);
            }

            if (GUILayout.Button("Get TestClass static methods name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName(() => TestClass.StaticTestMethod());
                var    methodInfo = StaticReflectionHelper.GetMethod(() => TestClass.StaticTestMethod());
                Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name);
            }

            if (GUILayout.Button("Get TestClass no return static methods name"))
            {
                string memberName = StaticReflectionHelper.GetMemberName(() => TestClass.StaticTestMethodNoReturn());
                var    methodInfo = StaticReflectionHelper.GetMethod(() => TestClass.StaticTestMethodNoReturn());
                Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name);
            }
        }
        public virtual void ProcessModel(IKernel kernel, ComponentModel model)
        {
            if (model.Configuration == null)
            {
                return;
            }

            IConfiguration parameters = model.Configuration.Children["parameters"];

            if (parameters == null)
            {
                return;
            }

            foreach (IConfiguration parameter in parameters.Children)
            {
                String name  = parameter.Name;
                String value = parameter.Value;

                if (value == null && parameter.Children.Count != 0)
                {
                    IConfiguration parameterValue = parameter.Children[0];
                    model.Parameters.Add(name, parameterValue);
                }
                else
                {
                    if (parameter.Attributes["type"] == "static")
                    {
                        value = StaticReflectionHelper.GetStaticValue <string>(parameter.Value);
                    }

                    model.Parameters.Add(name, value);
                }
            }

            foreach (ParameterModel parameter in model.Parameters)
            {
                if (parameter.Value == null || !ReferenceExpressionUtil.IsReference(parameter.Value))
                {
                    continue;
                }

                String newKey = ReferenceExpressionUtil.ExtractComponentKey(parameter.Value);

                model.Dependencies.Add(new DependencyModel(DependencyType.ServiceOverride, newKey, null, false));
            }
        }
예제 #5
0
        public override void Entry(IModHelper helper)
        {
            Config = helper.ReadConfig <ModConfig>();
            Keys   = Config.Controls.ParseControls(Monitor);

            helper.Events.Input.ButtonPressed += OnButtonPressed;

            SmoothPanningHelper.Initialize(helper);
            StaticReflectionHelper.Initialize(helper);

            _inputHelper = helper.Input;
            _keyHandlers = new IKeyHandler[]
            {
                new ChestKeyHandler(Keys.AddToExistingStacks),
                new PanScreenHandler(Keys.PanScreenScrollLeft, Keys.PanScreenScrollRight, Keys.PanScreenScrollUp, Keys.PanScreenScrollDown, Keys.PanScreenPreviousBuilding,
                                     Keys.PanScreenNextBuilding)
            };
        }
예제 #6
0
        /// <summary>
        /// BBernard
        /// This Static initializer ensures that the Delegate is created as a SINGLETON for each and every
        /// Generic type of this class that is intialized.  Therefore for each Generic type, this initialization
        /// will only every run one time in the thread safe Static Initializer for each type improving performance
        /// for ALL future calls of that Generic Type.
        /// </summary>
        static RepoDbFunctionCacheProxy()
        {
            var repoDbAssembly    = typeof(DbConnectionExtension).Assembly;
            var functionCacheType = repoDbAssembly.GetType("RepoDb.FunctionCache");

            //BBernard
            //Safely try to resolve a Proxy for 'GetDataReaderToDataEntityFunction' which is the method in RepoDb v1.12.4
            //Find the method via Reflection and compile into a local Expression Delegate for performance!
            _getDataReaderToDataEntityFunctionProxy = StaticReflectionHelper.FindStaticMethodForDelegate(
                functionCacheType,
                "GetDataReaderToDataEntityFunction",
                _getDataReaderToDataEntityFunctionProxy
                )?.CreateDynamicDelegate(
                _getDataReaderToDataEntityFunctionProxy,
                typeof(TEntity)
                );

            //BBernard
            //Safely try to resolve a Proxy for 'GetDataReaderToTypeCompiledFunction' which is the method in RepoDb v1.12.4
            //Find the method via Reflection and compile into a local Expression Delegate for performance!
            _getDataReaderToTypeCompiledFunctionProxy = StaticReflectionHelper.FindStaticMethodForDelegate(
                functionCacheType,
                "GetDataReaderToTypeCompiledFunction",
                _getDataReaderToTypeCompiledFunctionProxy
                )?.CreateDynamicDelegate(
                _getDataReaderToTypeCompiledFunctionProxy,
                typeof(TEntity)
                );

            //Now Validate that we have at least one Proxy... or else throw an Exception Early
            if (_getDataReaderToTypeCompiledFunctionProxy == null && _getDataReaderToDataEntityFunctionProxy == null)
            {
                throw new Exception(
                          $"Could not initialize the [{nameof(RepoDbFunctionCacheProxy<TEntity>)}];" +
                          $" the method to be proxied for [{nameof(GetDataReaderToDataEntityFunctionCompatible)}] is null and/or could not be found." +
                          $" This could be related to change in RepoDb version (source code has changed); please verify the version or update" +
                          $" this method to account for any differences."
                          );
            }
        }
        /// <summary>
        /// Returns the animal currently being purchased
        /// </summary>
        /// <param name="menu"></param>
        /// <returns>The animal</returns>
        public static FarmAnimal GetAnimalBeingPurchased(this PurchaseAnimalsMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <FarmAnimal>(menu, "animalBeingPurchased").GetValue());
        }
예제 #8
0
        public static bool IsUpgradingPlacementMode(this CarpenterMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <bool>(menu, "upgrading").GetValue() && menu.InPlacementMode());
        }
예제 #9
0
        public static bool InPlacementMode(this CarpenterMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <bool>(menu, "onFarm").GetValue());
        }
        /// <summary>
        /// Returns if the animal is currently being placed or not
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public static bool IsAnimalPlacementMode(this AnimalQueryMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <bool>(menu, "movingAnimal").GetValue());
        }
        /// <summary>
        /// Gets the animal associated with the menu
        /// </summary>
        /// <param name="menu"></param>
        /// <returns>The animal</returns>
        public static FarmAnimal GetAnimal(this AnimalQueryMenu menu)
        {
            var reflector = StaticReflectionHelper.GetInstance().GetReflector();

            return(reflector.GetField <FarmAnimal>(menu, "animal").GetValue());
        }
        private void OnGUI()
        {
            GUILayout.Label("Members");

            if (GUILayout.Button("Get TestClass field name"))
            {
                string memberName;
                if (StaticReflectionHelper.GetMemberName <TestClass>(c => c.testField).TryGet(out memberName))
                {
                    Debug.Log(memberName);
                }
            }

            if (GUILayout.Button("Get TestClass property name"))
            {
                string memberName;
                if (StaticReflectionHelper.GetMemberName <TestClass>(c => c.testProperty).TryGet(out memberName))
                {
                    Debug.Log(memberName);
                }
            }

            if (GUILayout.Button("Get TestClass static field name"))
            {
                string memberName;
                if (StaticReflectionHelper.GetMemberName(() => TestClass.staticTestField).TryGet(out memberName))
                {
                    Debug.Log(memberName);
                }
            }

            if (GUILayout.Button("Get TestClass static property name"))
            {
                string memberName;
                if (StaticReflectionHelper.GetMemberName(() => TestClass.staticTestProperty).TryGet(out memberName))
                {
                    Debug.Log(memberName);
                }
            }

            GUILayout.Label("Methods");

            if (GUILayout.Button("Get TestClass method name"))
            {
                Functional.Ignore =
                    from memberName in StaticReflectionHelper.GetMemberName <TestClass>(c => c.TestMethod())
                    from methodInfo in StaticReflectionHelper.GetMethod <TestClass>(c => c.TestMethod())
                    select Functional.Do(() => Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name));
            }

            if (GUILayout.Button("Get TestClass no return method name"))
            {
                Functional.Ignore =
                    from memberName in StaticReflectionHelper.GetMemberName <TestClass>(c => c.TestMethodNoReturn())
                    from methodInfo in StaticReflectionHelper.GetMethod <TestClass>(c => c.TestMethodNoReturn())
                    select Functional.Do(() => Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name));
            }

            if (GUILayout.Button("Get TestClass static methods name"))
            {
                Functional.Ignore =
                    from memberName in StaticReflectionHelper.GetMemberName(() => TestClass.StaticTestMethod())
                    from methodInfo in StaticReflectionHelper.GetMethod(() => TestClass.StaticTestMethod())
                    select Functional.Do(() => Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name));
            }

            if (GUILayout.Button("Get TestClass no return static methods name"))
            {
                Functional.Ignore =
                    from memberName in StaticReflectionHelper.GetMemberName(() => TestClass.StaticTestMethodNoReturn())
                    from methodInfo in StaticReflectionHelper.GetMethod(() => TestClass.StaticTestMethodNoReturn())
                    select Functional.Do(() => Debug.Log(memberName + ", MethodInfo.Name: " + methodInfo.Name));
            }
        }
예제 #13
0
 public void GetStaticValue_FromStaticClassInAssembly()
 {
     Assert.AreEqual(StaticValueHolder.TheValue,
                     StaticReflectionHelper.GetStaticValue <string>("DevDefined.Common.Tests.Reflection.StaticValueHolder.TheValue, DevDefined.Common.Tests"));
 }