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


C# Type.GetEvents方法代码示例

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


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

示例1: GetFilteredEvents

 internal string[] GetFilteredEvents(Type type, BindingFlags bindingFlags)
 {
     EventInfo[] events = type.GetEvents(bindingFlags);
     if (this._targetFrameworkProvider == null)
     {
         return this.GetMemberNames(events);
     }
     EventInfo[] infoArray2 = this._targetFrameworkProvider.GetReflectionType(type).GetEvents(bindingFlags);
     IEnumerable<string> reflectionEventNames = from e in infoArray2 select e.Name;
     return (from e in events
         where reflectionEventNames.Contains<string>(e.Name)
         select e.Name).ToArray<string>();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs

示例2: AddMembersNode

        static XmlElement AddMembersNode (XmlDocument document, Type t)
        {
                XmlElement members = document.CreateElement ("Members");
                BindingFlags static_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Static;
                BindingFlags  instance_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Instance;

                foreach (FieldInfo fi in t.GetFields (static_flag))
                        AddField (members, fi);

                foreach (FieldInfo fi in t.GetFields (instance_flag))
                        AddField (members, fi);

                foreach (MethodInfo mi in t.GetMethods (static_flag))
                        AddMethod (members, mi);

                foreach (MethodInfo mi in t.GetMethods (instance_flag))
                        AddMethod (members, mi);

                foreach (ConstructorInfo ci in t.GetConstructors (static_flag))
                        AddConstructor (members, ci);

                foreach (ConstructorInfo ci in t.GetConstructors (instance_flag))
                        AddConstructor (members, ci);

                foreach (PropertyInfo pi in t.GetProperties (static_flag))
                        AddProperty (members, pi);

                foreach (PropertyInfo pi in t.GetProperties (instance_flag))
                        AddProperty (members, pi);

                foreach (EventInfo ei in t.GetEvents (static_flag))
                        AddEvent (members, ei);

                foreach (EventInfo ei in t.GetEvents (instance_flag))
                        AddEvent (members, ei);

                return members;
        }
开发者ID:emtees,项目名称:old-code,代码行数:38,代码来源:updater.cs

示例3: GetAllEvents

        static EventInfo [] GetAllEvents (Type t)
        {
                BindingFlags static_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Static;
                BindingFlags instance_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Instance;

                EventInfo [] static_members = t.GetEvents (static_flag);
                EventInfo [] instance_members = t.GetEvents (instance_flag);

                if (static_members == null && instance_members == null)
                        return null;

                EventInfo [] all_members = new EventInfo [static_members.Length + instance_members.Length];
                static_members.CopyTo (all_members, 0); // copy all static members
                instance_members.CopyTo (all_members, static_members.Length); // copy all instance members

                return all_members;
        }
开发者ID:emtees,项目名称:old-code,代码行数:17,代码来源:updater.cs

示例4: ClassGen

	static void ClassGen (Type t)
	{
		//TODO: what flags do we want for GetEvents and GetConstructors?

		//events as signals
		EventInfo[] events;
		events = t.GetEvents (BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);

		//events as signals
		MethodInfo[] methods;
		methods = t.GetMethods (BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);

		Type[] ifaces;
		ifaces = t.GetInterfaces ();

		H.WriteLine ("G_BEGIN_DECLS");
		H.WriteLine ();

		{
			string NS = NsToC (ns).ToUpper ();
			string T = CamelToC (t.Name).ToUpper ();
			string NST = NS + "_" + T;
			string NSTT = NS + "_TYPE_" + T;

			H.WriteLine ("#define " + NSTT + " (" + cur_type + "_get_type ())");
			H.WriteLine ("#define " + NST + "(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), " + NSTT + ", " + CurType + "))");
			if (!t.IsInterface)
				H.WriteLine ("#define " + NST + "_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), " + NSTT + ", " + CurTypeClass + "))");
			H.WriteLine ("#define " + NS + "_IS_" + T + "(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), " + NSTT + "))");
			if (!t.IsInterface)
				H.WriteLine ("#define " + NS + "_IS_" + T + "_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), " + NSTT + "))");
			if (t.IsInterface)
				H.WriteLine ("#define " + NST + "_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), " + NSTT + ", " + CurTypeClass + "))");
			else
				H.WriteLine ("#define " + NST + "_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), " + NSTT + ", " + CurTypeClass + "))");
		}

		if (!C.IsDuplicate) {
			Hdecls.WriteLine ("typedef struct _" + CurType + " " + CurType + ";");
			Hdecls.WriteLine ("typedef struct _" + CurTypeClass + " " + CurTypeClass + ";");
			Hdecls.WriteLine ();
		}

		H.WriteLine ();

		string ParentName;
		string ParentNameClass;

		if (t.BaseType != null) {
			ParentName = CsTypeToG (t.BaseType);
			ParentNameClass = GToGC (ParentName);
		} else {
			ParentName = "GType";
			if (t.IsInterface)
				ParentNameClass = ParentName + "Interface";
			else
				ParentNameClass = ParentName + "Class";
		}

		//H.WriteLine ("typedef struct _" + CurType + " " + CurType + ";");

		//H.WriteLine ();
		//H.WriteLine ("typedef struct _" + CurType + "Class " + CurType + "Class;");
		if (!t.IsInterface) {
			H.WriteLine ("typedef struct _" + CurType + "Private " + CurType + "Private;");
			H.WriteLine ();
			H.WriteLine ("struct _" + CurType);
			H.WriteLine ("{");

			H.WriteLine (ParentName + " parent_instance;");
			H.WriteLine (CurType + "Private *priv;");
			H.WriteLine ("};");
			H.WriteLine ();
		}

		H.WriteLine ("struct _" + CurTypeClass);
		H.WriteLine ("{");
		//H.WriteLine (ParentNameClass + " parent_class;");
		H.WriteLine (ParentNameClass + " parent;");
		if (t.BaseType != null)
			H.WriteLine ("/* inherits " + t.BaseType.Namespace + " " + t.BaseType.Name + " */");

		if (events.Length != 0) {
			H.WriteLine ();
			H.WriteLine ("/* signals */");

			//FIXME: event arguments
			foreach (EventInfo ei in events)
				H.WriteLine ("void (* " + CamelToC (ei.Name) + ") (" + CurType + " *thiz" + ");");
		}

		if (t.IsInterface) {
			if (methods.Length != 0) {
				H.WriteLine ();
				H.WriteLine ("/* vtable */");

				//FIXME: method arguments
				//string funcname = ToValidFuncName (CamelToC (imi.Name));
				foreach (MethodInfo mi in methods)
					H.WriteLine ("void (* " + CamelToC (mi.Name) + ") (" + CurType + " *thiz" + ");");
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:cilc.cs

示例5: GetEvents

 public static EventInfo[] GetEvents(Type type, BindingFlags bindingAttr)
 {
     Requires.NotNull(type, "type");
     return type.GetEvents(bindingAttr);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:5,代码来源:TypeExtensions.CoreCLR.cs

示例6: ListTypeInfo

 // private void ListTypeInfo(Type type) {{{2
 private void ListTypeInfo(Type type)
 {
     Info.AppendFormat("Type: {0}\n", type); // Type name
     bool list = false;
     // List only public types {{{3
     if (OTIsPublic) {
         if (type.IsPublic)
             list = true;
     }
     else // List not only public types {{{3
         list = true;
     // If not list then exit {{{3
     if (!list)
         return;
     // Various statistics about the type {{{3
     if (OTTypeStats || OTAll) {
         Info.AppendFormat("\tBase class: {0}\n", type.BaseType);
         Info.AppendFormat("\tpublic: {0}\n", type.IsPublic);
         Info.AppendFormat("\tabstract: {0}\n", type.IsAbstract);
         Info.AppendFormat("\tsealed: {0}\n", type.IsSealed);
         Info.AppendFormat("\tgeneric: {0}\n", type.IsGenericTypeDefinition);
         Info.AppendFormat("\tclass type: {0}\n", type.IsClass);
     }
     // Fields {{{3
     if (OTFields || OTAll)
         foreach(FieldInfo i in type.GetFields()) Info.AppendFormat("\t[FI] {0}\n", i.ToString());
     // Properties {{{3
     if (OTProperties || OTAll)
         foreach(PropertyInfo i in type.GetProperties()) Info.AppendFormat("\t[PR] {0}\n", i.ToString());
     // Methods {{{3
     if (OTMethods || OTAll) {
        foreach(MethodInfo i in type.GetMethods()) {
             string retVal = i.ReturnType.FullName;
             StringBuilder paramInfo = new StringBuilder("(");
             // Get parameters
             foreach (ParameterInfo pi in i.GetParameters()) {
                  paramInfo.AppendFormat("{0} {1}, ", pi.ParameterType, pi.Name);
            }
            if (paramInfo.Length > 2)
                paramInfo.Remove(paramInfo.Length - 2, 2); // Remove trailing ", "
            paramInfo.Append(")");
            Info.AppendFormat("\t[ME] {0} {1}{2}\n", retVal, i.Name, paramInfo.ToString());
        }
     }
     // Interfaces {{{3
     if (OTInterfaces || OTAll)
         foreach(Type i in type.GetInterfaces()) Info.AppendFormat("\t[IN] {0}\n", i.ToString());
     // Events {{{3
     if (OTEvents || OTAll)
         foreach(EventInfo i in type.GetEvents()) Info.AppendFormat("\t[EV] {0}\n", i.ToString());
 }
开发者ID:viaa,项目名称:ObjectBrowser,代码行数:52,代码来源:ObjectBrowser.cs

示例7: GetFilteredEvents

    internal string[] GetFilteredEvents(Type type, BindingFlags bindingFlags) {
        EventInfo[] runtimeEvents= type.GetEvents(bindingFlags);

        if (_targetFrameworkProvider == null) {
            return GetMemberNames(runtimeEvents);
        }

        Type reflectionType = _targetFrameworkProvider.GetReflectionType(type);
        EventInfo[] reflectionEvents= reflectionType.GetEvents(bindingFlags);

        var reflectionEventNames = from e in reflectionEvents select e.Name;
        return (from e in runtimeEvents where reflectionEventNames.Contains(e.Name) select e.Name).ToArray();
    }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:13,代码来源:ClientBuildManagerTypeDescriptionProviderBridge.cs

示例8: PrintType

    // print out typeinfo
    void PrintType(Type t, bool IsExtern)
    {
        try
        {
            sw.Write(".class ");
            if (IsExtern)
                sw.Write("extern ");
            sw.Write(t.FullName);
            if (t.IsGenericTypeDefinition)
            {
                Type[] ts = t.GetGenericArguments(); // we must have at least one generic argument
                sw.Write("<");
                for (int i = 0; i < ts.Length; i++)
                {
                    sw.Write("("); // we should always have some generic constrains
                    Type[] cts = ts[i].GetGenericParameterConstraints();
                    Array.Sort(cts, sc);
                    for (int j = 0; j < cts.Length; j++)
                    {
                        sw.Write(PrintTypeWithAssem(cts[j]));
                        if (j < cts.Length - 1)
                            sw.Write(", ");
                    }
                    sw.Write(") ");
                    sw.Write(ts[i]);
                    if (i < (ts.Length - 1))
                        sw.Write(", ");
                }
                sw.Write(">");
            }
            sw.Write(" (");
            if (t.IsInterface)
                sw.Write("Interface ");
            sw.WriteLine(ProcessAttributeString(t.Attributes.ToString()) + ")");
            if (t.BaseType != null)
            {
                sw.Write(".extends [" + t.BaseType.Assembly.GetName().Name + "]" + t.BaseType);
            }
            Array infs = t.GetInterfaces();

            if (infs.Length != 0)
            {
                sw.Write(Environment.NewLine + ".implements ");
                Array.Sort(infs, sc);
            }
            foreach (Type inf in t.GetInterfaces())
            {
                sw.Write(inf + ", ");
            }
            sw.WriteLine();

            sw.WriteLine("{");
            PrintCustomAttributes(CustomAttributeData.GetCustomAttributes(t));
            ConstructorInfo[] CList = t.GetConstructors(bf);
            Array.Sort(CList, sc);
            foreach (ConstructorInfo ci in CList)
                PrintMethod(ci);

            FieldInfo[] FList = t.GetFields(bf);
            Array.Sort(FList, sc);
            foreach (FieldInfo fi in FList)
                PrintField(fi);

            MethodInfo[] MList = t.GetMethods(bf);
            Array.Sort(MList, sc);
            foreach (MethodInfo mi in MList)
                PrintMethod(mi);

            PropertyInfo[] PList = t.GetProperties(bf);
            Array.Sort(PList, sc);
            foreach (PropertyInfo pi in PList)
                PrintProperty(pi);

            EventInfo[] EList = t.GetEvents(bf);
            Array.Sort(EList, sc);
            foreach (EventInfo ei in EList)
                PrintEvent(ei);

            sw.WriteLine(@"} //end of class " + t);
        }
        catch (Exception e)
        {
            Console.WriteLine("UnExpected Exception thrown at type : " + t);
            Console.WriteLine(e);
        }
    }
开发者ID:dbremner,项目名称:clrinterop,代码行数:87,代码来源:AssemPrinter.cs

示例9: DumpEvents

 // Dumps the public events directly contained in the specified type   
 private void DumpEvents(Type aType)
 {
   if ( !ShowEvents )
     return;
        
   EventInfo[] eInfo = aType.GetEvents( );
        
   myWriter.WriteLine("Events:");
   bool found = false;
     
   if ( eInfo.Length != 0 )
   {                                                    
     for ( int i=0; i < eInfo.Length; i++ )
     {        
       //
       // Only display events declared in this type.
       //          
       if ( eInfo[i].DeclaringType == aType )
       {
         found = true;
         myWriter.WriteLine("  {0}", eInfo[i]);
       }
     }
   }
     
   if ( !found )
   {
     myWriter.WriteLine("  (none)");
   }    
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:31,代码来源:typefinder.cs

示例10: CreatePropertyItems

    private static JArray CreatePropertyItems(Type type, string parentPropertyName, Dictionary<string, object> defaultValues)
    {
        var array = new JArray();
        var obj = type.GetConstructor(new Type[] { }).Invoke(null);
        if (defaultValues != null)
        {
            foreach (var defaultValue in defaultValues)
            {
                var property = type.GetProperty(defaultValue.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                if (property != null && property.CanWrite)
                {
                    if (property.PropertyType.IsEnum)
                    {
                        property.SetValue(obj, Enum.Parse(property.PropertyType, defaultValue.Value.ToString()), null);
                    }
                    else
                    {
                        property.SetValue(obj, Convert.ChangeType(defaultValue.Value, property.PropertyType), null);
                    }
                }
            }
        }
        if (string.IsNullOrEmpty(parentPropertyName))
        {
            array.Add(GetIDObject());
        }
        foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
        {
            if (CanEdit(property))
            {
                var propertyObj = new JObject();
                propertyObj["name"] = property.Name;
                propertyObj["value"] = GetDefaultValue(obj, property);
                propertyObj["group"] = GetGroup(property);
                propertyObj["editor"] = GetEditor(property, parentPropertyName);
                array.Add(propertyObj);
            }
        }
        if (string.IsNullOrEmpty(parentPropertyName))
        {
            if (typeof(System.Web.UI.WebControls.WebControl).IsAssignableFrom(type))
            {
                var webControlProperties = new string[] { "Width", "Height" };
                foreach (var webControlProperty in webControlProperties)
                {
                    var property = type.GetProperty(webControlProperty, BindingFlags.Instance | BindingFlags.Public);
                    var overrideProperty = type.GetProperty(webControlProperty, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                    if (property != null && overrideProperty == null)
                    {
                        var propertyObj = new JObject();
                        propertyObj["name"] = property.Name;
                        propertyObj["value"] = GetDefaultValue(obj, property);
                        propertyObj["group"] = GetGroup(property);
                        propertyObj["editor"] = GetEditor(property, parentPropertyName);
                        array.Add(propertyObj);
                    }
                }
            }
        }

        if (type.BaseType != null && type.BaseType.Namespace == type.Namespace)
        {
            foreach (var property in type.BaseType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                var overrideProperty = type.GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                if (CanEdit(property) && overrideProperty == null)
                {
                    var propertyObj = new JObject();
                    propertyObj["name"] = property.Name;
                    propertyObj["value"] = GetDefaultValue(obj, property);
                    propertyObj["group"] = GetGroup(property);
                    propertyObj["editor"] = GetEditor(property, parentPropertyName);
                    array.Add(propertyObj);
                }
            }
        }

        foreach (var eventInfo in type.GetEvents(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
        {
            var propertyObj = new JObject();
            propertyObj["name"] = eventInfo.Name;
            propertyObj["value"] = new JValue("");
            propertyObj["group"] = GetGroup(eventInfo);
            propertyObj["editor"] = GetEventEditor(eventInfo);
            array.Add(propertyObj);
        }
        return array;
    }
开发者ID:san90279,项目名称:UK_OAS,代码行数:88,代码来源:JsonHelper.cs

示例11: IsScriptable

		public static bool IsScriptable (Type t)
		{
			if (t.IsDefined (typeof(ScriptableTypeAttribute), true))
				return true;

			foreach (MethodInfo mi in t.GetMethods ())
				if (mi.IsDefined (typeof(ScriptableMemberAttribute), true))
					return true;

			foreach (PropertyInfo pi in t.GetProperties ())
				if (pi.IsDefined (typeof(ScriptableMemberAttribute), true))
					return true;

			foreach (EventInfo ei in t.GetEvents ())
				if (ei.IsDefined (typeof(ScriptableMemberAttribute), true))
					return true;

			return false;
		}
开发者ID:shana,项目名称:moon,代码行数:19,代码来源:ManagedObject.cs


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