本文整理汇总了C#中EventAttributes类的典型用法代码示例。如果您正苦于以下问题:C# EventAttributes类的具体用法?C# EventAttributes怎么用?C# EventAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventAttributes类属于命名空间,在下文中一共展示了EventAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneralNegativeTest
public void GeneralNegativeTest(string name, EventAttributes attrs, Type eventType, Type expected)
{
AssemblyName myAsmName =
new AssemblyName("TypeBuilderGetFieldTest");
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(
myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");
TypeBuilder myType = myModule.DefineType("Sample",
TypeAttributes.Class | TypeAttributes.Public);
string[] typeParamNames = { "T" };
GenericTypeParameterBuilder[] typeParams =
myType.DefineGenericParameters(typeParamNames);
if (expected != null)
{
Action test = () =>
{
myType.DefineEvent(name, attrs, eventType);
Type t = myType.CreateTypeInfo().AsType();
};
Assert.Throws(expected, test);
}
else
{
Type t1 = myType.CreateTypeInfo().AsType();
}
}
示例2: EventBuilder
// Constructor.
internal EventBuilder(TypeBuilder type, String name,
EventAttributes attributes, Type eventType)
{
// Validate the parameters.
if(name == null)
{
throw new ArgumentNullException("name");
}
else if(eventType == null)
{
throw new ArgumentNullException("eventType");
}
// Register this item to be detached later.
type.module.assembly.AddDetach(this);
// Create the event.
lock(typeof(AssemblyBuilder))
{
this.type = type;
this.privateData = ClrEventCreate
(((IClrProgramItem)type).ClrHandle, name,
SignatureHelper.CSToILType(type.module, eventType),
attributes);
}
}
示例3: EventToGenerate
/// <summary>
/// Initializes a new instance of the <see cref="EventToGenerate"/> class.
/// </summary>
/// <param name="emitter">The emitter.</param>
/// <param name="addMethod">The add method.</param>
/// <param name="removeMethod">The remove method.</param>
/// <param name="attributes">The attributes.</param>
public EventToGenerate(EventEmitter emitter, MethodInfo addMethod, MethodInfo removeMethod, EventAttributes attributes)
{
this.addMethod = addMethod;
this.removeMethod = removeMethod;
this.emitter = emitter;
this.attributes = attributes;
}
示例4: DefineEvent
public void DefineEvent(string name, EventAttributes attributes, Type eventType, string expectedName, EventAttributes expectedAttributes)
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
type.DefineGenericParameters("T");
EventBuilder eventBuilder = type.DefineEvent(name, attributes, eventType);
MethodBuilder addOnMethod = type.DefineMethod("addOnMethod", MethodAttributes.Public);
addOnMethod.GetILGenerator().Emit(OpCodes.Ret);
MethodBuilder removeOnMethod = type.DefineMethod("removeOnMethod", MethodAttributes.Public);
removeOnMethod.GetILGenerator().Emit(OpCodes.Ret);
eventBuilder.SetAddOnMethod(addOnMethod);
eventBuilder.SetRemoveOnMethod(removeOnMethod);
Type createdType = type.CreateTypeInfo().AsType();
Assert.Equal(type.AsType().GetEvents(Helpers.AllFlags), createdType.GetEvents(Helpers.AllFlags));
Assert.Equal(type.AsType().GetEvent(expectedName, Helpers.AllFlags), createdType.GetEvent(expectedName, Helpers.AllFlags));
EventInfo eventInfo = createdType.GetEvent(expectedName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.Equal(expectedName, eventInfo.Name);
Assert.Equal(createdType, eventInfo.DeclaringType);
Assert.Equal(expectedAttributes, eventInfo.Attributes);
Assert.Equal((expectedAttributes & EventAttributes.SpecialName) != 0, eventInfo.IsSpecialName);
Assert.Null(eventInfo.EventHandlerType);
}
示例5: EventBuilder
#pragma warning restore 169, 414
internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
name = eventName;
attrs = eventAttrs;
type = eventType;
typeb = tb;
table_idx = get_next_table_index (this, 0x14, true);
}
示例6: EventBuilder
internal EventBuilder(TypeBuilder typeBuilder, string name, EventAttributes attributes, Type eventtype)
{
this.typeBuilder = typeBuilder;
this.name = name;
this.attributes = attributes;
this.eventtype = typeBuilder.ModuleBuilder.GetTypeTokenForMemberRef(eventtype);
}
示例7: EventEmitter
public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
{
this.typeEmitter = typeEmitter;
this.type = type;
this.name = name;
eventBuilder = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
}
示例8: EventDefinition
public EventDefinition(string name, TypeReference eventType,
EventAttributes attrs)
: base(name)
{
m_eventType = eventType;
m_attributes = attrs;
}
示例9: EventEmitter
public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
{
if (name == null) throw new ArgumentNullException("name");
if (type == null) throw new ArgumentNullException("type");
this.typeEmitter = typeEmitter;
this.type = type;
eventBuilder = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
}
示例10: EventBuilder
internal EventBuilder(ModuleBuilder mod, string name, EventAttributes attr, TypeBuilder type, EventToken evToken)
{
this.m_name = name;
this.m_module = mod;
this.m_attributes = attr;
this.m_evToken = evToken;
this.m_type = type;
}
示例11: EventBuilder
// Constructs a EventBuilder.
//
internal EventBuilder(
Module mod, // the module containing this EventBuilder
String name, // Event name
EventAttributes attr, // event attribute such as Public, Private, and Protected defined above
int eventType, // event type
TypeBuilder type, // containing type
EventToken evToken)
{
m_name = name;
m_module = mod;
m_attributes = attr;
m_evToken = evToken;
m_type = type;
}
示例12: SetCustomAttribute
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
Universe u = typeBuilder.ModuleBuilder.universe;
if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
{
attributes |= EventAttributes.SpecialName;
}
else
{
if (lazyPseudoToken == 0)
{
lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
}
typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
}
}
示例13: Event
public ApiTypeBuilder Event(string name, Type eventType, EventAttributes attributes = EventAttributes.None, bool @static = false)
{
EventBuilder eventBuilder = _typeBuilder.DefineEvent(name, attributes, eventType);
MethodBuilder addMethodBuilder = _typeBuilder.DefineMethod(string.Format("add_{0}", name),
@static ? MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Static :
MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Virtual
, null, new[] { eventType });
addMethodBuilder.GetILGenerator().Emit(OpCodes.Ret);
MethodBuilder removeMethodBuilder = _typeBuilder.DefineMethod(string.Format("remove_{0}", name),
@static ? MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Static :
MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Virtual
, null, new[] { eventType });
removeMethodBuilder.GetILGenerator().Emit(OpCodes.Ret);
eventBuilder.SetAddOnMethod(addMethodBuilder);
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
return this;
}
示例14: DefineEvent
[System.Security.SecuritySafeCritical] // auto-generated
public EventBuilder DefineEvent(String name, EventAttributes attributes, Type eventtype)
{
lock(SyncRoot)
{
return DefineEventNoLock(name, attributes, eventtype);
}
}
示例15: DefineEventNoLock
[System.Security.SecurityCritical] // auto-generated
private EventBuilder DefineEventNoLock(String name, EventAttributes attributes, Type eventtype)
{
if (name == null)
throw new ArgumentNullException("name");
if (name.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
if (name[0] == '\0')
throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
Contract.EndContractBlock();
int tkType;
EventToken evToken;
CheckContext(eventtype);
ThrowIfCreated();
tkType = m_module.GetTypeTokenInternal( eventtype ).Token;
// Internal helpers to define property records
evToken = new EventToken(DefineEvent(
m_module.GetNativeHandle(),
m_tdType.Token,
name,
attributes,
tkType));
// create the property builder now.
return new EventBuilder(
m_module,
name,
attributes,
//tkType,
this,
evToken);
}