Skip to content

Commit

Permalink
Merge pull request #43 from mandel-macaque/generator-ignore-methods
Browse files Browse the repository at this point in the history
[Fix] Update the generator to help fix 24078 by ignoring certain tagged methods.
  • Loading branch information
mandel-macaque committed May 12, 2016
2 parents 746164e + fc472cc commit 96a596f
Showing 1 changed file with 18 additions and 5 deletions.
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 {
}

// 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

0 comments on commit 96a596f

Please sign in to comment.