Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Update the generator to help fix 24078 by ignoring certain tagged methods. #43

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,15 @@ public DefaultValueFromArgumentAttribute (string s){
public class NoDefaultValueAttribute : Attribute {
}

// Attribute used to mark those methods that will be ignored when
// generating C# events, there are several situations in which using
// this attribute makes sense:
// 1. when there are overloaded methods. This means that we can mark
// the default overload to be used in the events.
// 2. whe some of the methods should not be exposed as events.
public class IgnoredInDelegateAttribute : Attribute {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is fairly clear but please add a few comments where/why that attribute is being used (self-documentation).

}

// Apply to strings parameters that are merely retained or assigned,
// not copied this is an exception as it is advised in the coding
// standard for Objective-C to avoid this, but a few properties do use
Expand Down Expand Up @@ -2711,7 +2720,7 @@ public void Go ()
} else if (attr is AlphaAttribute) {
continue;
#endif
} else if (attr is SealedAttribute || attr is EventArgsAttribute || attr is DelegateNameAttribute || attr is EventNameAttribute || attr is ObsoleteAttribute || attr is NewAttribute || attr is PostGetAttribute || attr is NullAllowedAttribute || attr is CheckDisposedAttribute || attr is SnippetAttribute || attr is AppearanceAttribute || attr is ThreadSafeAttribute || attr is AutoreleaseAttribute || attr is EditorBrowsableAttribute || attr is AdviceAttribute || attr is OverrideAttribute)
} else if (attr is SealedAttribute || attr is EventArgsAttribute || attr is DelegateNameAttribute || attr is EventNameAttribute || attr is IgnoredInDelegateAttribute || attr is ObsoleteAttribute || attr is NewAttribute || attr is PostGetAttribute || attr is NullAllowedAttribute || attr is CheckDisposedAttribute || attr is SnippetAttribute || attr is AppearanceAttribute || attr is ThreadSafeAttribute || attr is AutoreleaseAttribute || attr is EditorBrowsableAttribute || attr is AdviceAttribute || attr is OverrideAttribute)
continue;
else if (attr is MarshalNativeExceptionsAttribute)
continue;
Expand Down Expand Up @@ -6543,7 +6552,7 @@ public void Generate (Type type)
string shouldOverrideDelegateString = isProtocolizedEventBacked ? "" : "override ";

foreach (var mi in dtype.GatherMethods ().OrderBy (m => m.Name)) {
if (ShouldSkipGeneration (mi))
if (ShouldSkipEventGeneration (mi))
continue;

var pars = mi.GetParameters ();
Expand Down Expand Up @@ -6716,7 +6725,7 @@ public void Generate (Type type)
// Now add the instance vars and event handlers
foreach (var dtype in bta.Events.OrderBy (d => d.Name)) {
foreach (var mi in dtype.GatherMethods ().OrderBy (m => m.Name)) {
if (ShouldSkipGeneration (mi))
if (ShouldSkipEventGeneration (mi))
continue;

string ensureArg = bta.KeepRefUntil == null ? "" : "this";
Expand Down Expand Up @@ -7069,7 +7078,7 @@ string GenerateInterfaceTypeName (BaseTypeAttribute bta, string delName, string
return currentTypeName;
}

bool ShouldSkipGeneration (MethodInfo mi)
bool ShouldSkipEventGeneration (MethodInfo mi)
{
// Skip property getter/setters
if (mi.IsSpecialName && (mi.Name.StartsWith ("get_") || mi.Name.StartsWith ("set_")))
Expand All @@ -7078,8 +7087,12 @@ bool ShouldSkipGeneration (MethodInfo mi)
if (mi.IsUnavailable ())
return true;

// Skip those methods marked to be ignored by the developer
var customAttrs = mi.GetCustomAttributes (true);
if (customAttrs.OfType<IgnoredInDelegateAttribute> ().Any ())
return true;
#if !XAMCORE_2_0
if (mi.GetCustomAttributes (true).OfType<AlphaAttribute> ().Any ())
if (customAttrs.OfType<AlphaAttribute> ().Any ())
return true;
#endif

Expand Down