Example #1
0
 public object GetValue(System.Reflection.FieldInfo field)
 {
     if (field.DeclaringType == typeof(B))
     {
         return(field.GetValue(this));
     }
     else
     {
         return(base.GetValue(field));
     }
 }
Example #2
0
        public TimeoutMonitor SendMsg(object msg, bool handoverRelibility = false, ICipherPolicy cipherPolicy = null)
        {
            if (null == _endpoint)
            {
                Debug.LogError("[Session.SendMsg] invalid destination address");
                return(null);
            }
            if (true == handoverRelibility)
            {
                if (Application.internetReachability != _networkReachability)
                {
                    _networkReachability = Application.internetReachability;
                    Disconnect();
                    _disconnectState = DisconnectState.Handover;
                }
            }
            try
            {
                System.IO.MemoryStream ms   = new System.IO.MemoryStream();
                System.Type            type = msg.GetType();
                type.GetMethod("Store").Invoke(msg, new object[] { ms });
                System.Reflection.FieldInfo fi = type.GetField("MSG_ID");

                if (null != cipherPolicy)
                {
                    ms = cipherPolicy.Encrypt(ms);
                }

                uint   msgID        = (uint)(int)fi.GetValue(msg);
                ushort packetLength = (ushort)(Packet.HEADER_SIZE + (int)ms.Length);

                if (packetLength > Gamnet.Buffer.BUFFER_SIZE)
                {
                    throw new System.Exception(string.Format("Overflow the send buffer max size : {0}", packetLength));
                }

                Reconnect();

                Gamnet.Packet packet = new Gamnet.Packet();
                packet.length = packetLength;
                packet.msg_id = msgID;
                packet.Append(ms);
                packet.msg_seq  = ++_send_seq;
                packet.reliable = handoverRelibility;

                SendMsg(packet);
                return(_timeout_monitor);
            }
            catch (System.Exception e) {
                Debug.LogError("[Session.SendMsg] exception:" + e.ToString());
                Error(new Gamnet.Exception(ErrorCode.SendMsgFailError, e.ToString()));
            }
            return(null);
        }
Example #3
0
        public static OpenTK.GameWindow GetForm(this GameWindow gameWindow)
        {
            Type type = typeof(OpenTKGameWindow);

            System.Reflection.FieldInfo field = type.GetField("window", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            if (field != null)
            {
                return(field.GetValue(gameWindow) as OpenTK.GameWindow);
            }
            return(null);
        }
Example #4
0
        // Gets the value specified in the variant on the field
        //
        private void FieldGetter(String typeName, String fieldName, ref Object val)
        {
            Contract.Requires(typeName != null);
            Contract.Requires(fieldName != null);

            // Extract the field info object
            FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);

            // Get the value
            val = fldInfo.GetValue(this);
        }
Example #5
0
        static public void RescaleFloatRange(PartModule pm, string name, float factor)
        {
            System.Reflection.FieldInfo field = pm.GetType().GetField(name);
            float         oldValue            = (float)field.GetValue(pm);
            UI_FloatRange fr = (UI_FloatRange)pm.Fields[name].uiControlEditor;

            fr.maxValue      *= factor;
            fr.minValue      *= factor;
            fr.stepIncrement *= factor;
            field.SetValue(pm, oldValue * factor);
        }
Example #6
0
        private Estensione GetEst(Form f)
        {
            System.Reflection.FieldInfo pi = f.GetType().GetField("est");
            object propValue = pi.GetValue(f);

            return((Estensione)propValue);



            //System.Reflection.TypeAttributes a = mei.DeclaringType.Attributes;
        }
Example #7
0
        // Gets the value specified in the variant on the field
        //
        private void FieldGetter(string typeName, string fieldName, ref object val)
        {
            Debug.Assert(typeName != null);
            Debug.Assert(fieldName != null);

            // Extract the field info object
            FieldInfo fldInfo = GetFieldInfo(typeName, fieldName);

            // Get the value
            val = fldInfo.GetValue(this);
        }
Example #8
0
            void SubmitChoice(On.RoR2.PickupPickerController.orig_SubmitChoice orig, RoR2.PickupPickerController pickupPickerController, int integer)
            {
                if (Data.modEnabled)
                {
                    if (Data.mode == DataShop.mode)
                    {
                        System.Type type = typeof(RoR2.PickupPickerController);
                        System.Reflection.FieldInfo info = type.GetField("options", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        ICollection collection           = info.GetValue(pickupPickerController) as ICollection;
                        int         index = 0;
                        foreach (object item in collection)
                        {
                            if (index == integer)
                            {
                                RoR2.PickupPickerController.Option option = (RoR2.PickupPickerController.Option)item;
                                ItemIndex itemIndex = RoR2.PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex;

                                RoR2.NetworkUIPromptController promptController = pickupPickerController.GetComponent <RoR2.NetworkUIPromptController>();
                                type = typeof(RoR2.NetworkUIPromptController);
                                info = type.GetField("_currentLocalParticipant", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                                RoR2.LocalUser localUser = (RoR2.LocalUser)info.GetValue(promptController);
                                foreach (NetworkUser networkUser in RoR2.NetworkUser.readOnlyInstancesList)
                                {
                                    if (localUser.currentNetworkUser.netId == networkUser.netId)
                                    {
                                        if (networkUser.isLocalPlayer)
                                        {
                                            DataShop.RemoveScrap(Data.GetItemTier(Data.allItemsIndexes[itemIndex]), Mathf.Min(DataShop.purchaseCost, networkUser.GetCurrentBody().inventory.GetItemCount(itemIndex)));
                                        }
                                        break;
                                    }
                                }
                                break;
                            }
                            index += 1;
                        }
                    }
                    orig(pickupPickerController, integer);
                }
                ;
            }
Example #9
0
        static IntPtr getRegistryKeyHandle(RegistryKey registryKey)
        {
            Type registryKeyType = typeof(RegistryKey);

            System.Reflection.FieldInfo fieldInfo =
                registryKeyType.GetField("hkey", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            SafeHandle handle          = (SafeHandle)fieldInfo.GetValue(registryKey);
            IntPtr     dangerousHandle = handle.DangerousGetHandle();

            return(dangerousHandle);
        }
 void _FieldSetValue(System.Reflection.FieldInfo field, ref object ins, ref object value)
 {
     if (PropertyProvider != null)
     {
         var fieldIns = field.GetValue(ins);
         PropertyProvider.SetValue(fieldIns, value);
     }
     else
     {
         field.SetValue(ins, value);
     }
 }
        System.Collections.IList GetListField(System.Reflection.FieldInfo fi)
        {
            object obj = fi.GetValue(this);

            if (obj != null)
            {
                return((System.Collections.IList)obj);
            }
            System.Collections.IList result = (System.Collections.IList)fi.FieldType.GetConstructor(new Type[] { }).Invoke(new object[] { });
            fi.SetValue(this, result);
            return(result);
        }
Example #12
0
 object GetCtrlByName(string Name)
 {
     System.Reflection.FieldInfo Ctrl = this.GetType().GetField(Name);
     if (Ctrl == null)
     {
         return(null);
     }
     //if (!typeof(Label).IsAssignableFrom(Ctrl.FieldType)) return null;
     //Label L =  (Label) Ctrl.GetValue(this);
     //return L;
     return(Ctrl.GetValue(this));
 }
 public object getValue(object obj)
 {
     if (fieldInfo != null)
     {
         return(fieldInfo.GetValue(obj));
     }
     if (propertyInfo != null)
     {
         return(propertyInfo.GetValue(obj, null));
     }
     return(null);
 }
Example #14
0
        public void SetUp()
        {
            var settings = (ExportSettings)s_InstanceField.GetValue(null);

            m_originalSettings = settings;

            // Clear out the current instance and create a new one (but keep the original around).
            s_InstanceField.SetValue(null, null);
            s_InstanceField.SetValue(null, ScriptableObject.CreateInstance <ExportSettings> ());

            // keep track of any existing default presets to reset them once tests finish
            var exportPresetType  = new PresetType(ExportSettings.instance.ExportModelSettings);
            var convertPresetType = new PresetType(ExportSettings.instance.ConvertToPrefabSettings);

            m_exportSettingsDefaultPresets  = Preset.GetDefaultPresetsForType(exportPresetType);
            m_convertSettingsDefaultPresets = Preset.GetDefaultPresetsForType(convertPresetType);

            // clear default presets
            Preset.SetDefaultPresetsForType(exportPresetType, new DefaultPreset[] { });
            Preset.SetDefaultPresetsForType(convertPresetType, new DefaultPreset[] { });
        }
Example #15
0
        /// <summary>
        /// 对象自拷贝
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object SelfCopy(this object obj)
        {
            Object targetDeepCopyObj;
            Type   targetType = obj.GetType();

            //值类型
            if (targetType.IsValueType == true)
            {
                targetDeepCopyObj = obj;
            }
            //引用类型
            else
            {
                targetDeepCopyObj = System.Activator.CreateInstance(targetType);   //创建引用对象
                System.Reflection.MemberInfo[] memberCollection = obj.GetType().GetMembers();

                foreach (System.Reflection.MemberInfo member in memberCollection)
                {
                    if (member.MemberType == System.Reflection.MemberTypes.Field)
                    {
                        System.Reflection.FieldInfo field = (System.Reflection.FieldInfo)member;
                        Object fieldValue = field.GetValue(obj);
                        if (fieldValue is ICloneable)
                        {
                            field.SetValue(targetDeepCopyObj, (fieldValue as ICloneable).Clone());
                        }
                        else
                        {
                            field.SetValue(targetDeepCopyObj, SelfCopy(fieldValue));
                        }
                    }
                    else if (member.MemberType == System.Reflection.MemberTypes.Property)
                    {
                        System.Reflection.PropertyInfo myProperty = (System.Reflection.PropertyInfo)member;
                        System.Reflection.MethodInfo   info       = myProperty.GetSetMethod(false);
                        if (info != null)
                        {
                            object propertyValue = myProperty.GetValue(obj, null);
                            if (propertyValue is ICloneable)
                            {
                                myProperty.SetValue(targetDeepCopyObj, (propertyValue as ICloneable).Clone(), null);
                            }
                            else
                            {
                                myProperty.SetValue(targetDeepCopyObj, SelfCopy(propertyValue), null);
                            }
                        }
                    }
                }
            }
            return(targetDeepCopyObj);
        }
Example #16
0
        internal CILFieldImpl(
            CILReflectionContextImpl ctx,
            Int32 anID,
            System.Reflection.FieldInfo field
            )
            : base(ctx, anID, CILElementKind.Field, () => new CustomAttributeDataEventArgs(ctx, field))
        {
            ArgumentValidator.ValidateNotNull("Field", field);
            if (field.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericType&& !field.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericTypeDefinition)
            {
                throw new ArgumentException("This constructor may be used only on fields declared in genericless types or generic type definitions.");
            }
            Byte[] rvaValue = null;
            if (((FieldAttributes)field.Attributes).HasRVA())
            {
                rvaValue = BitUtils.ObjectToByteArray(field.GetValue(null));
            }

            InitFields(
                ref this.fieldAttributes,
                ref this.name,
                ref this.declaringType,
                ref this.fieldType,
                ref this.constValue,
                ref this.initialValue,
                ref this.customModifiers,
                ref this.fieldOffset,
                ref this.marshalInfo,
                new SettableValueForEnums <FieldAttributes>((FieldAttributes)field.Attributes),
                new SettableValueForClasses <String>(field.Name),
                () => (CILType)ctx.Cache.GetOrAdd(field.DeclaringType),
                () => ctx.Cache.GetOrAdd(field.FieldType),
                new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(field))),
                new SettableValueForClasses <Byte[]>(rvaValue),
                ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(field)),
                new SettableLazy <Int32>(() =>
            {
                var offset = field.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.FieldOffsetAttribute>().FirstOrDefault();
                return(offset == null ? -1 : offset.Value);
            }),
                new SettableLazy <MarshalingInfo>(() => MarshalingInfo.FromAttribute(field.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.MarshalAsAttribute>().FirstOrDefault(), ctx)),
                true
                );
        }
Example #17
0
        public short StatWithSynergy(string stat, bool hasSynergy)
        {
            string statToUse = hasSynergy ? "Series" + stat : stat;

            System.Reflection.FieldInfo statField = typeof(DataEquipmentInformation).GetField(statToUse);
            short statValue = (short)statField.GetValue(this);

            if (AugmentStat != null && AugmentStat == stat)
            {
                statValue = (short)Math.Ceiling((hasSynergy ? Augment * 1.5 : (double)Augment) + statValue);
            }
            return(statValue);
        }
Example #18
0
 public static Solver CreateSolver(String name, String type)
 {
     System.Reflection.FieldInfo fieldInfo =
         typeof(Solver).GetField(type);
     if (fieldInfo != null)
     {
         return(new Solver(name, (int)fieldInfo.GetValue(null)));
     }
     else
     {
         return(null);
     }
 }
Example #19
0
        /// <summary>
        /// 初始化自定义服务
        /// </summary>
        private void InitService()
        {
            this.mkService = new MarkService(this);

            System.Type propertyGridType          = typeof(System.Windows.Forms.PropertyGrid);
            System.Reflection.FieldInfo gridField = propertyGridType.GetField("gridView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            //获取gridView实例
            object gridViewRef = gridField.GetValue(this);

            System.Reflection.FieldInfo spInfo = gridField.FieldType.GetField("serviceProvider", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            //设置字段值
            spInfo.SetValue(gridViewRef, this.mkService);
        }
Example #20
0
 public static object FindControlByFieldName(Form frm, string name)
 {
     System.Type t = frm.GetType();
     System.Reflection.FieldInfo fi = t.GetField(name, System.Reflection.BindingFlags.Public |
                                                 System.Reflection.BindingFlags.NonPublic |
                                                 System.Reflection.BindingFlags.Instance |
                                                 System.Reflection.BindingFlags.DeclaredOnly);
     if (fi == null)
     {
         return(null);
     }
     return(fi.GetValue(frm));
 }
        protected override string GetPrimitiveValue(System.Reflection.FieldInfo fi)
        {
            // make coordinates relative
            Tile   anchor = Objects.SelectionManager.Instance.Anchor;
            string xName  = Objects.SelectionManager.Instance.XAnchorName;
            string yName  = Objects.SelectionManager.Instance.YAnchorName;

            if (anchor != null)
            {
                int x = int.Parse(fi.GetValue(this).ToString());
                int y = int.Parse(fi.GetValue(this).ToString());
                if (fi.Name.EndsWith("X"))
                {
                    if (x > anchor.TileKey.X)
                    {
                        return(xName + "+" + (x - anchor.TileKey.X));
                    }
                    else
                    {
                        return(xName + "-" + (anchor.TileKey.X - x));
                    }
                }
                else //if (fi.Name.EndsWith("Y"))
                {
                    if (y > anchor.TileKey.Y)
                    {
                        return(yName + "+" + (y - anchor.TileKey.Y));
                    }
                    else
                    {
                        return(yName + "-" + (anchor.TileKey.Y - y));
                    }
                }
            }
            else
            {
                return(base.GetPrimitiveValue(fi));
            }
        }
Example #22
0
 public static int GetSolverEnum(String solverType)
 {
     System.Reflection.FieldInfo fieldInfo =
         typeof(Solver).GetField(solverType);
     if (fieldInfo != null)
     {
         return((int)fieldInfo.GetValue(null));
     }
     else
     {
         throw new System.ApplicationException("Solver not supported");
     }
 }
 public static bool IsDisposed(this Image image)
 {
     System.Reflection.FieldInfo nativeImageIntPtr = image.GetType().GetField("nativeImage", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
     if (nativeImageIntPtr != null)
     {
         IntPtr ptr = (IntPtr)nativeImageIntPtr.GetValue(image);
         if (ptr == IntPtr.Zero)
         {
             return(true);
         }
     }
     return(false);
 }
Example #24
0
 /// <summary>Get a field</summary>
 /// <param name="pFieldName"></param>
 /// <returns></returns>
 public System.Object GetField(string pFieldName)
 {
     try{
         System.Reflection.FieldInfo lField = this.lType.GetField(pFieldName);
         if (lField == null)
         {
             throw new ApplicationException("Field <" + pFieldName + "> not found! ");
         }
         return(lField.GetValue(this.CurrentInstance));
     }catch (ApplicationException e) {
         throw new ApplicationException("Field <" + pFieldName + "> failed! \r\n" + e.Message);
     }
 }
Example #25
0
 /// <summary>
 /// Hack to set compression level for stream
 /// </summary>
 private void SetStreamCompressionLevel()
 {
     if (_zipCompressionInfoField != null)
     {
         try
         {
             var compInstance = _zipCompressionInfoField.GetValue(m_writer);
             var prop         = compInstance.GetType().GetProperty("DeflateCompressionLevel", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
             prop.SetValue(compInstance, m_compressionInfo.DeflateCompressionLevel);
         }
         catch { }
     }
 }
 private IEnumerable <DbParameter> GetInputParams(object input)
 {
     if (input != null)
     {
         // result of the properties
         InputParams result     = new InputParams();
         Type        objectType = input.GetType();
         if (objectType.IsDefined(typeof(DataContractAttribute), false))
         {
             result.Set(GetInputParams(input, objectType));
             return(result);
         }
         foreach (var property in objectType.GetProperties())
         {
             var propertyType = property.PropertyType;
             var value        = property.GetValue(input);
             if (propertyType.IsValueType)
             {
                 if (propertyType.IsPrimitive || propertyType.IsEnum == false)
                 {
                     result[property.Name] = impl.GetInputParameter(value, property.Name, propertyType.FullName);
                 }
                 else
                 {
                     System.Reflection.FieldInfo field = propertyType.GetField(EnumValue, InstantPublic);
                     result[property.Name] = impl.GetInputParameter(field.GetValue(value), property.Name, field.FieldType.FullName);
                 }
             }
             else if (propertyType.IsSerializable)
             {
                 //if generic type for dictionary
                 if (propertyType.IsGenericType)
                 {
                     //Check whether Dictionary Value
                     if (typeof(IDictionary).IsAssignableFrom(propertyType))
                     {
                         result.Set(GetDictionaryParameter(value));
                         continue;
                     }
                 }
                 result[property.Name] = GetSerializableParameter(value, property.Name, propertyType.FullName);
             }
             else if (propertyType.IsClass && value != null)
             {
                 result.Set(GetInputParams(value, propertyType));
             }
         }
         return(result);
     }
     return(new DbParameter[0]);
 }
Example #27
0
        /// <summary>
        /// handles the "cheater" way of installing without a config file
        /// </summary>
        /// <param name="pluginTypeAssemblyQualifiedName"></param>
        private static void RegisterPlugin(string pluginTypeAssemblyQualifiedName)
        {
            Type t = typeof(MySqlAuthenticationPlugin);
            Type pluginManagerType = t.Assembly.GetType("MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager");

            System.Reflection.FieldInfo plugins = pluginManagerType.GetField("Plugins", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            object obj = plugins.GetValue(null);

            System.Reflection.PropertyInfo piItem = obj.GetType().GetProperty("Item");
            Type   pluginType = t.Assembly.GetType("MySql.Data.MySqlClient.Authentication.PluginInfo");
            object pluginInfo = Activator.CreateInstance(pluginType, pluginTypeAssemblyQualifiedName);

            piItem.SetValue(obj, pluginInfo, new object[] { "mysql_clear_password" });
        }
Example #28
0
        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.IsFullScreen              = false;
            graphics.PreferredBackBufferWidth  = 1270;
            graphics.PreferredBackBufferHeight = 600;

            //Changes the settings that you just applied
            graphics.ApplyChanges();
            ScreenWidth  = this.graphics.PreferredBackBufferWidth;
            ScreenHeight = this.graphics.PreferredBackBufferHeight;

            // Additional code to reposition the game window
            Type type = typeof(OpenTKGameWindow);

            System.Reflection.FieldInfo field = type.GetField("window", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            (field.GetValue(Window) as OpenTK.GameWindow).X = 0;
            (field.GetValue(Window) as OpenTK.GameWindow).Y = 0;
        }
Example #29
0
        protected DBManager getDBManager()
        {
            Type type = this.GetType();

            System.Reflection.FieldInfo fieldInfo = type.GetField("db", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
            if (fieldInfo != null)
            {
                return((DBManager)fieldInfo.GetValue(null));
            }
            else
            {
                return(null);
            }
        }
        public void TestRecordEvent()
        {
            // Need to make sure that background runner does not attempt to deliver events during
            // test (and consequently delete them from local storage). Restart Background runner
            // and sleep until after it checks for events to send.
            BackgroundRunner.AbortBackgroundThread();
            System.Reflection.FieldInfo fieldInfo        = typeof(MobileAnalyticsManager).GetField("_backgroundRunner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            BackgroundRunner            backgroundRunner = fieldInfo.GetValue(null) as BackgroundRunner;

            backgroundRunner.StartWork();
            Thread.Sleep(1000);

            string appID = Guid.NewGuid().ToString();
            MobileAnalyticsManager manager    = MobileAnalyticsManager.GetOrCreateInstance(appID, TestRunner.Credentials, RegionEndpoint.USEast1);
            SQLiteEventStore       eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());

            try
            {
                CustomEvent customEvent = new CustomEvent("TestRecordEvent");
                customEvent.AddAttribute("LevelName", "Level5");
                customEvent.AddAttribute("Successful", "True");
                customEvent.AddMetric("Score", 12345);
                customEvent.AddMetric("TimeInLevel", 64);
                manager.RecordEvent(customEvent);

                MonetizationEvent monetizationEvent = new MonetizationEvent();
                monetizationEvent.Quantity           = 10.0;
                monetizationEvent.ItemPrice          = 2.00;
                monetizationEvent.ProductId          = "ProductId123";
                monetizationEvent.ItemPriceFormatted = "$2.00";
                monetizationEvent.Store         = "Amazon";
                monetizationEvent.TransactionId = "TransactionId123";
                monetizationEvent.Currency      = "USD";
                manager.RecordEvent(monetizationEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine("Catch exception: " + e.ToString());
                Assert.Fail();
            }

            // sleep a while to make sure event is stored
            Thread.Sleep(TimeSpan.FromSeconds(1));

            // Event store should have one custom event, one monetization event and one session start event.
            Assert.AreEqual(3, eventStore.NumberOfEvents(appID));


            eventStore.Dispose();
        }
Example #31
0
 private bool GetFieldValue(FieldInfo fi, PropertyLookupParams paramBag, ref object @value)
 {
     try
     {
         @value = fi.GetValue(paramBag.instance);
         return true;
     }
     catch(Exception ex)
     {
         paramBag.self.Error("Can't get property " + fi.Name
             + " using direct field access from " + paramBag.prototype.FullName
             + " instance", ex
             );
     }
     return false;
 }