当前位置: 首页>>代码示例>>C#>>正文


C# Type.InvokeMember方法代码示例

本文整理汇总了C#中System.Type.InvokeMember方法的典型用法代码示例。如果您正苦于以下问题:C# Type.InvokeMember方法的具体用法?C# Type.InvokeMember怎么用?C# Type.InvokeMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Type的用法示例。


在下文中一共展示了Type.InvokeMember方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PatchResourceManager

        public static void PatchResourceManager(Type resourceManagerType)
        {
            if (resourceManagerType.GetProperty("ResourceManager", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public) != null)
            {
                try
                {
                    var resManager = resourceManagerType.InvokeMember("ResourceManager", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, resourceManagerType, new object[] { });
                    var fileName = resourceManagerType.Name + ".resx";

                    var databaseResourceManager = new DBResourceManager(fileName, resManager as ResourceManager);
                    resourceManagerType.InvokeMember("resourceMan", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField, null, resourceManagerType, new object[] { databaseResourceManager });
                }
                catch (TargetInvocationException e)
                {
                    if (e.InnerException is FileNotFoundException && ((FileNotFoundException)e.InnerException).FileName == "App_GlobalResources")
                    {
                        // ignore
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:25,代码来源:AssemblyWork.cs

示例2: Integrator

        public Integrator(string login, string password, string pathToDb)
        {
            _type1C = Type.GetTypeFromProgID("v77.Application");
            _object1C = Activator.CreateInstance(_type1C);
            object rmtrade = _type1C.InvokeMember("RMTrade", BindingFlags.GetProperty, null, _object1C, null);
            var connectionString = String.Format("/D\"{0}\" /N\"{1}\" /P\"{2}\"", pathToDb, login, password);
            var arguments = new object[] { rmtrade, connectionString, "NO_SPLASH_SHOW" };

            bool res = (bool)_type1C.InvokeMember("Initialize", BindingFlags.InvokeMethod, null, _object1C, arguments);
        }
开发者ID:neoxack,项目名称:IntegrationService,代码行数:10,代码来源:Integrator.cs

示例3: ViewDesignerDoc

    public ViewDesignerDoc(int itemId, DataViewHierarchyAccessor accessor, string viewName)
    {
      _accessor = accessor;
      _connection = accessor.Connection;
      _itemId = itemId;
      InitializeComponent();

      _init = true;
      try
      {
        _typeQB = SQLiteDataAdapterToolboxItem._vsdesigner.GetType("Microsoft.VSDesigner.Data.Design.QueryBuilderControl");

        if (_typeQB != null)
        {
          _queryDesigner = Activator.CreateInstance(_typeQB) as UserControl;
          _typeQB.InvokeMember("Provider", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.NonPublic, null, _queryDesigner, new object[] { SQLiteOptions.GetProviderName() });
          _typeQB.InvokeMember("ConnectionString", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.NonPublic, null, _queryDesigner, new object[] { _connection.ConnectionSupport.ConnectionString });
          _typeQB.InvokeMember("EnableMorphing", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.NonPublic, null, _queryDesigner, new object[] { false });
          Controls.Add(_queryDesigner);
          _queryDesigner.Dock = DockStyle.Fill;
          _queryDesigner.Visible = true;
        }

        StringBuilder tables = new StringBuilder();

        using (DataReader reader = _connection.Command.Execute("SELECT * FROM sqlite_master", 1, null, 30))
        {
          while (reader.Read())
          {
            tables.Append(reader.GetItem(2).ToString());
            tables.Append(",");
          }
        }

        int n = 1;

        if (String.IsNullOrEmpty(viewName))
        {
          string alltables = tables.ToString();

          do
          {
            viewName = String.Format(CultureInfo.InvariantCulture, "View{0}", n);
            n++;
          } while (alltables.IndexOf(viewName + ",", StringComparison.OrdinalIgnoreCase) > -1 || _editingTables.ContainsValue(viewName));

          _editingTables.Add(GetHashCode(), viewName);
        }
        _view = new SQLite.Designer.Design.View(viewName, _connection.ConnectionSupport.ProviderObject as DbConnection, this);
      }
      finally
      {
        _init = false;
      }
    }
开发者ID:xieguigang,项目名称:Reference_SharedLib,代码行数:55,代码来源:ViewDesignerDoc.cs

示例4: ViewableFile

 public ViewableFile(EFEFile File, Type Format, bool CreateNew = false)
 {
     if (!Format.GetInterfaces().Contains(typeof(IViewable))) throw new ArgumentException("This format is not viewable!");
     this.File = File;
     if (CreateNew) FileFormat = Format.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]);
     else FileFormat = Format.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[] { File.Data });
     Dialog = FileFormat.GetDialog();
     Dialog.Tag = this;
     Dialog.Text = File.Name;
     Dialog.FormClosing += new FormClosingEventHandler(Dialog_FormClosing);
 }
开发者ID:Ermelber,项目名称:EveryFileExplorer,代码行数:11,代码来源:ViewableFile.cs

示例5: WordSpellChecker

        private int _languageId = 1033; // English

        public WordSpellChecker(Main main, string languageId)
        {
            _mainHandle = main.Handle;
            SetLanguageId(languageId);

            _wordApplicationType = Type.GetTypeFromProgID("Word.Application");
            _wordApplication = Activator.CreateInstance(_wordApplicationType);

            Application.DoEvents();
            _wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateNormal });
            _wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -5000 }); // hide window - it's a hack
            Application.DoEvents();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:15,代码来源:WordSpellChecker.cs

示例6: RegisterDefinitionEditor

        /// <summary>
        /// 定義エディタをコントローラへ登録し、開く。
        /// </summary>
        /// <param name="editorType">登録する定義エディタの型。</param>
        /// <param name="definition">対象定義のインスタンス。</param>
        /// <param name="parameters">固有パラメータ。</param>
        private void RegisterDefinitionEditor(
            Type editorType,
            dynamic definition = null,
            KeyValueMap parameters = null)
        {
            DefinitionEditorTab tab = null;
            tab = FindDefinitionEditor(definition);

            if (tab != null)
            {
                tab.Activate();

                return;
            }

            tab = (DefinitionEditorTab)editorType.InvokeMember(
                null,
                BindingFlags.CreateInstance,
                null, null, null
            );

            tab.Definition = definition;
            tab.Parameters = parameters;
            tab.FormClosed += DefinitionEditor_FormClosed;
            tab.Apply += DefinitionEditor_Apply;

            MainForm.ShowContent(tab, DockState.Document);
        }
开发者ID:RaTTiE,项目名称:Warlock,代码行数:34,代码来源:WarlockApplication.DefinitionEditor.Methods.cs

示例7: CreateDataSource

        /// <summary>
        /// Создает источник данных, на основе типа инициалайзера и его параметров, Источник добавляется в глобальный список
        /// </summary>
        /// <param name="initializerType">Тип инициализатора, наследуется от IInitializer</param>
        /// <param name="initializerProperties">Обязательные для заполнения поля инициализатора</param>
        /// <returns>Новый источник данных</returns>
        public static DataSource CreateDataSource(Type initializerType, Dictionary<string, object> initializerProperties)
        {
            DataSource dataSource = null;

            if (initializerType != null &&
                initializerType.BaseType != null &&
                initializerType.BaseType.Name == "Initializer")
            {
                dataSource = new DataSource(Activator.CreateInstance(initializerType) as Abstract.Initializer);

                if (initializerProperties != null)
                {
                    foreach (var currProperty in initializerProperties)
                    {
                        initializerType.InvokeMember("SetProperty", BindingFlags.Public |
                                                                    BindingFlags.NonPublic |
                                                                    BindingFlags.Instance |
                                                                    BindingFlags.InvokeMethod, null, dataSource.Initializer, new[] { currProperty.Key, currProperty.Value });
                    }
                }
            }

            if (dataSource == null)
            {
                dataSource = new DataSource();
            }

            DataSources.Add(dataSource);
            return dataSource;
        }
开发者ID:ivukovi4,项目名称:SqlGenerator,代码行数:36,代码来源:DataSourceManager.cs

示例8: InvokeMemberOnType

        private static object InvokeMemberOnType(Type type, object target, string name, object[] args)
        {
            BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            try
            {
                // Try to invokethe method
                return type.InvokeMember(
                    name,
                    BindingFlags.InvokeMethod | bindingFlags,
                    null,
                    target,
                    args);
            }
            catch (MissingMethodException)
            {
                // If we couldn't find the method, try on the base class
                if (type.GetTypeInfo().BaseType != null)
                {
                    return InvokeMemberOnType(type.GetTypeInfo().BaseType, target, name, args);
                }
                //Don't care if the method don't exist.
                return null;
            }
        }
开发者ID:henningst,项目名称:coreclrplayground,代码行数:25,代码来源:Program.cs

示例9: InvokeMethod

 public static object InvokeMethod(Type type, string methodName, object[] args)
 {
     object objResult = null;
     object obj = Activator.CreateInstance(type);
     objResult = type.InvokeMember(methodName, bindingFlags | BindingFlags.InvokeMethod, null, obj, args);
     return objResult;
 }
开发者ID:xiaolin8,项目名称:AMS,代码行数:7,代码来源:ReflectionHelper.cs

示例10: AddToCollection

		/// <summary>
		/// Adds a value to the end of a collection.
		/// </summary>
		public static void AddToCollection(Type collectionType, object collectionInstance, XamlPropertyValue newElement)
		{
			IAddChild addChild = collectionInstance as IAddChild;
			if (addChild != null) {
				if (newElement is XamlTextValue) {
					addChild.AddText((string)newElement.GetValueFor(null));
				} else {
					addChild.AddChild(newElement.GetValueFor(null));
				}
			} else if (collectionInstance is ResourceDictionary) {
				object val = newElement.GetValueFor(null);
				object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
				if (key == null) {
					if (val is Style)
						key = ((Style)val).TargetType;
				}
				((ResourceDictionary)collectionInstance).Add(key, val);
			} else {
				collectionType.InvokeMember(
					"Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
					null, collectionInstance,
					new object[] { newElement.GetValueFor(null) },
					CultureInfo.InvariantCulture);
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:28,代码来源:CollectionSupport.cs

示例11: GetNVCFromEnumValue

 /// <summary>  
 /// 根据枚举类型得到其所有的 值 与 枚举定义Description属性 的集合  
 /// </summary>  
 /// <param name="enumType"></param>  
 /// <returns></returns>  
 public static NameValueCollection GetNVCFromEnumValue(Type enumType)
 {
     var nvc = new NameValueCollection();
     Type typeDescription = typeof(DescriptionAttribute);
     FieldInfo[] fields = enumType.GetFields();
     foreach (FieldInfo field in fields)
     {
         if (field.FieldType.IsEnum)
         {
             string strValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null)).ToString(CultureInfo.InvariantCulture);
             object[] arr = field.GetCustomAttributes(typeDescription, true);
             string strText;
             if (arr.Length > 0)
             {
                 var aa = (DescriptionAttribute)arr[0];
                 strText = aa.Description;
             }
             else
             {
                 strText = "";
             }
             nvc.Add(strValue, strText);
         }
     }
     return nvc;
 }
开发者ID:chanzig,项目名称:MVCProjectDemo,代码行数:31,代码来源:EnumHelper.cs

示例12: LoadControl

		private static Control LoadControl(Manager manager, XmlNode node, Type type, Control parent) {
			Control c = null;

			Object[] args = new Object[] { manager };

			c = (Control)type.InvokeMember(null, BindingFlags.CreateInstance, null, null, args);
			if (parent != null)
				c.Parent = parent;
			c.Name = node.Attributes["Name"].Value;

			if (node != null && node["Properties"] != null && node["Properties"].HasChildNodes) {
				LoadProperties(node["Properties"].GetElementsByTagName("Property"), c);
			}

			if (node != null && node["Controls"] != null && node["Controls"].HasChildNodes) {
				foreach (XmlElement e in node["Controls"].GetElementsByTagName("Control")) {
					string cls = e.Attributes["Class"].Value;
					Type t = Type.GetType(cls);

					if (t == null) {
						cls = "GodLesZ.Library.Xna.WindowLibrary.Controls." + cls;
						t = Type.GetType(cls);
					}
					LoadControl(manager, e, t, c);
				}
			}

			return c;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:29,代码来源:Layout.cs

示例13: GetAttrValue

 string GetAttrValue(System.Reflection.Assembly assy, Type attrType, string field)
 {
     object[] ary = assy.GetCustomAttributes(attrType, false);
     if (ary == null || ary.Length != 1) return "(not set)";
     object value = attrType.InvokeMember(field, System.Reflection.BindingFlags.GetProperty, null, ary[0], new object[] { });
     return value == null ? "(not set)" : (string)value;
 }
开发者ID:dwalternatio,项目名称:Sims4Tools,代码行数:7,代码来源:ManageWrappersDialog.cs

示例14: GetNameValueCollectionFromEnumValue

        /// <summary>
        /// 从枚举类型和它的特性读出并返回一个键值对
        /// </summary>
        /// <param name="enumType">Type,该参数的格式为typeof(需要读的枚举类型)</param>
        /// <returns>键值对</returns>
        public static NameValueCollection GetNameValueCollectionFromEnumValue(Type enumType)
        {
            var nvc = new NameValueCollection();
            var typeDescription = typeof(DescriptionAttribute);
            var fields = enumType.GetFields();

            foreach (var field in fields)
            {
                if (field.FieldType.IsEnum)
                {
                    var strValue = Convert.ToInt32(enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null));
                    var arr = field.GetCustomAttributes(typeDescription, true);
                    string strText;
                    if (arr.Length > 0)
                    {
                        var aa = (DescriptionAttribute)arr[0];
                        strText = aa.Description;
                    }
                    else
                    {
                        strText = field.Name;
                    }

                    nvc.Add(strValue.ToString(), strText);
                }
            }

            return nvc;
        }
开发者ID:GavinHome,项目名称:REVOLUTION,代码行数:34,代码来源:EnumUtility.cs

示例15: CreateModuleByType

        //IModule instance = null;
        //{if (type == null || type.GetInterface("IModule") == null) continue;
        //instance = (IModule)type.InvokeMember(String.Empty, BindingFlags.CreateInstance, null, null, null);
        //CurrentModules.Add(instance.ModuleId.ToString(), instance);
        //instance.Initializer();}
        #endregion

        private IModule CreateModuleByType(Type type)
        {
            if (type == null || type.GetInterface("IModule") == null) return null;
            var instance = (IModule)type.InvokeMember(String.Empty, BindingFlags.CreateInstance, null, null, null);
            CurrentModules.Add(instance.ModuleId, instance);
            instance.Initializer();
            return instance;
        }
开发者ID:rkvtsn,项目名称:wpfmodulizer,代码行数:15,代码来源:Modulizer.cs


注:本文中的System.Type.InvokeMember方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。