本文整理汇总了C#中IType.GetEvents方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetEvents方法的具体用法?C# IType.GetEvents怎么用?C# IType.GetEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.GetEvents方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseMinimalFields
internal static void ParseMinimalFields(SDType sdType, IType type)
{
var events = type.GetEvents(null, GetMemberOptions.IgnoreInheritedMembers);
foreach (var eve in events)
{
var parsedEvent = GetMinimalParsedEvent(eve);
if (sdType.Events.SingleOrDefault(f => f.Name == parsedEvent.Name) == null)
{
sdType.Events.Add(parsedEvent);
}
}
}
示例2: CollectMembersToImplement
public static List<IMember> CollectMembersToImplement(ITypeDefinition implementingType, IType abstractType)
{
// var def = abstractType.GetDefinition();
var toImplement = new List<IMember>();
bool alreadyImplemented;
// Stub out non-implemented events defined by @iface
foreach (var ev in abstractType.GetEvents (e => !e.IsSynthetic && e.IsAbstract)) {
alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
);
if (!alreadyImplemented)
toImplement.Add(ev);
}
// Stub out non-implemented methods defined by @iface
foreach (var method in abstractType.GetMethods (d => !d.IsSynthetic && d.IsAbstract)) {
alreadyImplemented = false;
var allBaseTypes = method.DeclaringType.GetAllBaseTypes().ToList ();
foreach (var cmet in implementingType.GetMethods (d => !d.IsAbstract && d.Name == method.Name)) {
if (allBaseTypes.Contains(cmet.DeclaringType))
continue;
if (ImplementInterfaceAction.CompareMethods(method, cmet)) {
alreadyImplemented = true;
break;
}
}
if (!alreadyImplemented)
toImplement.Add(method);
}
// Stub out non-implemented properties defined by @iface
foreach (var prop in abstractType.GetProperties (p => !p.IsSynthetic && p.IsAbstract)) {
alreadyImplemented = false;
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface)
continue;
foreach (IProperty cprop in t.Properties) {
if (!cprop.IsAbstract && cprop.Name == prop.Name) {
alreadyImplemented = true;
}
}
}
if (!alreadyImplemented)
toImplement.Add(prop);
}
return toImplement;
}
示例3: ParseEvents
internal void ParseEvents(SDType sdType, IType type)
{
var events = type.GetEvents(null, GetMemberOptions.IgnoreInheritedMembers);
foreach (var eve in events)
{
if (!IsMemberExcluded(eve.GetIdentifier(), eve.Accessibility.ToString()))
{
var parsedEvent = GetParsedEvent(eve);
if (sdType.Events.SingleOrDefault(f => f.Name == parsedEvent.Name) == null)
{
sdType.Events.Add(parsedEvent);
}
}
}
}
示例4: CollectMembersToImplement
public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly)
{
var def = interfaceType.GetDefinition();
List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
bool alreadyImplemented;
// Stub out non-implemented events defined by @iface
foreach (var ev in interfaceType.GetEvents (e => !e.IsSynthetic && e.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
);
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
}
// Stub out non-implemented methods defined by @iface
foreach (var method in interfaceType.GetMethods (d => !d.IsSynthetic && d.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var cmet in implementingType.GetMethods ()) {
if (CompareMethods(method, cmet)) {
if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
}
}
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
}
// Stub out non-implemented properties defined by @iface
foreach (var prop in interfaceType.GetProperties (p => !p.IsSynthetic && p.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface)
continue;
foreach (IProperty cprop in t.Properties) {
if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
}
}
}
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
}
return toImplement;
}
示例5: Lookup
/// <summary>
/// Performs a member lookup.
/// </summary>
public ResolveResult Lookup(IType type, string name, IList<IType> typeArguments, bool isInvocation)
{
int typeArgumentCount = typeArguments.Count;
List<IType> types = new List<IType>();
List<IMember> members = new List<IMember>();
if (!isInvocation) {
// Consider nested types only if it's not an invocation. The type parameter count must match in this case.
Predicate<ITypeDefinition> typeFilter = delegate (ITypeDefinition d) {
return d.TypeParameterCount == typeArgumentCount && d.Name == name && IsAccessible(d, true);
};
types.AddRange(type.GetNestedTypes(context, typeFilter));
}
bool allowProtectedAccess = IsProtectedAccessAllowed(type);
if (typeArgumentCount == 0) {
Predicate<IMember> memberFilter = delegate(IMember member) {
return !member.IsOverride && member.Name == name && IsAccessible(member, allowProtectedAccess);
};
members.AddRange(type.GetMethods(context, memberFilter.SafeCast<IMember, IMethod>()).SafeCast<IMethod, IMember>());
members.AddRange(type.GetProperties(context, memberFilter.SafeCast<IMember, IProperty>()).SafeCast<IProperty, IMember>());
members.AddRange(type.GetFields(context, memberFilter.SafeCast<IMember, IField>()).SafeCast<IField, IMember>());
members.AddRange(type.GetEvents(context, memberFilter.SafeCast<IMember, IEvent>()).SafeCast<IEvent, IMember>());
if (isInvocation)
members.RemoveAll(m => !IsInvocable(m, context));
} else {
// No need to check for isInvocation/isInvocable here:
// we filter out all non-methods
Predicate<IMethod> memberFilter = delegate(IMethod method) {
return method.TypeParameters.Count == typeArgumentCount
&& !method.IsOverride && method.Name == name && IsAccessible(method, allowProtectedAccess);
};
members.AddRange(type.GetMethods(context, memberFilter).SafeCast<IMethod, IMember>());
}
// TODO: can't members also hide types?
RemoveTypesHiddenByOtherTypes(types);
// remove members hidden by types
for (int i = 0; i < types.Count; i++) {
ITypeDefinition d = GetDeclaringTypeDef(types[i]);
if (d != null)
members.RemoveAll(m => d.IsDerivedFrom(m.DeclaringTypeDefinition, context));
}
// remove members hidden by other members
for (int i = members.Count - 1; i >= 0; i--) {
ITypeDefinition d = members[i].DeclaringTypeDefinition;
IMethod mi = members[i] as IMethod;
// nested loop depends on the fact that the members of more derived classes appear later in the list
for (int j = i + 1; j < members.Count; j++) {
if (mi != null) {
IMethod mj = members[j] as IMethod;
if (mj != null && !ParameterListComparer.Instance.Equals(mi, mj))
continue;
}
ITypeDefinition s = members[j].DeclaringTypeDefinition;
if (s != null && s != d && s.IsDerivedFrom(d, context)) {
// members[j] hides members[i]
members.RemoveAt(i);
break;
}
}
}
// remove interface members hidden by class members
if (type is ITypeParameter) {
// this can happen only with type parameters
for (int i = members.Count - 1; i >= 0; i--) {
ITypeDefinition d = members[i].DeclaringTypeDefinition;
if (d.ClassType != ClassType.Interface)
continue;
IMethod mi = members[i] as IMethod;
for (int j = 0; j < members.Count; j++) {
if (mi != null) {
IMethod mj = members[j] as IMethod;
if (mj != null && !ParameterListComparer.Instance.Equals(mi, mj))
continue;
}
ITypeDefinition s = members[j].DeclaringTypeDefinition;
if (s != null && IsNonInterfaceType(s)) {
// members[j] hides members[i]
members.RemoveAt(i);
break;
}
}
}
}
if (types.Count > 0) {
bool isAmbiguous = !(types.Count == 1 && members.Count == 0);
return CreateTypeResolveResult(types[0], isAmbiguous, typeArguments);
}
if (members.Count == 0)
return new UnknownMemberResolveResult(type, name, typeArguments);
IMember firstNonMethod = members.FirstOrDefault(m => !(m is IMethod));
if (members.Count == 1 && firstNonMethod != null)
return new MemberResolveResult(firstNonMethod, context);
//.........这里部分代码省略.........
示例6: AddAttributes
void AddAttributes(IType type, IList<ICompletionItem> list, bool includeEvents)
{
if (type.Kind == TypeKind.Unknown)
return;
foreach (IProperty p in type.GetProperties(up => up.IsPublic)) {
if ((p.CanSet && p.Setter.IsPublic) || p.ReturnType.IsCollectionType())
list.Add(new XamlCompletionItem(p));
}
if (includeEvents) {
foreach (IEvent e in type.GetEvents(ue => ue.IsPublic)) {
list.Add(new XamlCompletionItem(e));
}
}
}
示例7: AddImplementation
static void AddImplementation(RefactoringContext context, TypeDeclaration result, IType guessedType)
{
foreach (var property in guessedType.GetProperties ()) {
if (!property.IsAbstract)
continue;
if (property.IsIndexer) {
var indexerDecl = new IndexerDeclaration {
ReturnType = context.CreateShortType(property.ReturnType),
Modifiers = GetModifiers(property),
Name = property.Name
};
indexerDecl.Parameters.AddRange(ConvertParameters(context, property.Parameters));
if (property.CanGet)
indexerDecl.Getter = new Accessor();
if (property.CanSet)
indexerDecl.Setter = new Accessor();
result.AddChild(indexerDecl, Roles.TypeMemberRole);
continue;
}
var propDecl = new PropertyDeclaration {
ReturnType = context.CreateShortType(property.ReturnType),
Modifiers = GetModifiers (property),
Name = property.Name
};
if (property.CanGet)
propDecl.Getter = new Accessor();
if (property.CanSet)
propDecl.Setter = new Accessor();
result.AddChild(propDecl, Roles.TypeMemberRole);
}
foreach (var method in guessedType.GetMethods ()) {
if (!method.IsAbstract)
continue;
var decl = new MethodDeclaration {
ReturnType = context.CreateShortType(method.ReturnType),
Modifiers = GetModifiers (method),
Name = method.Name,
Body = new BlockStatement {
new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
}
};
decl.Parameters.AddRange(ConvertParameters(context, method.Parameters));
result.AddChild(decl, Roles.TypeMemberRole);
}
foreach (var evt in guessedType.GetEvents ()) {
if (!evt.IsAbstract)
continue;
var decl = new EventDeclaration {
ReturnType = context.CreateShortType(evt.ReturnType),
Modifiers = GetModifiers (evt),
Variables = {
new VariableInitializer {
Name = evt.Name
}
}
};
decl.Variables.Add(new VariableInitializer(evt.Name));
result.AddChild(decl, Roles.TypeMemberRole);
}
}
示例8: FindMember
IMember FindMember(IType type, string propertyName)
{
IMember member = type.GetProperties(p => p.Name == propertyName).FirstOrDefault();
if (member != null)
return member;
return type.GetEvents(e => e.Name == propertyName).FirstOrDefault();
}
示例9: CollectMembersToImplement
public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly, out bool interfaceMissing)
{
//var def = interfaceType.GetDefinition();
List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
bool alreadyImplemented;
interfaceMissing = true;
// Stub out non-implemented events defined by @iface
foreach (var evGroup in interfaceType.GetEvents (e => !e.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var ev in evGroup) {
if (ev.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, ev)));
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
} else {
interfaceMissing = false;
}
}
// Stub out non-implemented methods defined by @iface
foreach (var methodGroup in interfaceType.GetMethods (d => !d.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var method in methodGroup) {
if (method.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var cmet in implementingType.GetMethods ()) {
alreadyImplemented |= cmet.ImplementedInterfaceMembers.Any(m => IsImplementation (m, method));
if (CompareMembers(method, cmet)) {
if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
}
}
if (toImplement.Where(t => t.Item1 is IMethod).Any(t => CompareMembers(method, (IMethod)t.Item1)))
needsExplicitly = true;
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
} else {
interfaceMissing = false;
}
}
// Stub out non-implemented properties defined by @iface
foreach (var propGroup in interfaceType.GetProperties (p => !p.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var prop in propGroup) {
if (prop.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, prop)));
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface) {
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name && cprop.IsShadowing) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
}
}
continue;
}
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
}
}
}
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
} else {
interfaceMissing = false;
}
}
return toImplement;
}
示例10: GetEventsImpl
static IEnumerable<IEvent> GetEventsImpl(IType baseType, Predicate<IUnresolvedEvent> filter, GetMemberOptions options)
{
IEnumerable<IEvent> declaredEvents = baseType.GetEvents(filter, options | declaredMembers);
if ((options & GetMemberOptions.ReturnMemberDefinitions) == GetMemberOptions.ReturnMemberDefinitions) {
return declaredEvents;
}
ParameterizedType pt = baseType as ParameterizedType;
if (pt != null) {
var substitution = pt.GetSubstitution();
return declaredEvents.Select(m => new SpecializedEvent(m, substitution) { DeclaringType = pt });
} else {
return declaredEvents;
}
}