You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
It is possible to specify a [ConditionalAttribute] on an attribute type to indicate that the attribute should only be present in the compiled assembly if a certain symbol is defined when the attribute is instantiated. I need access to this information, so how can we represent it?
I suggest a bool IsConditionallyExcluded flag on IAttribute. What do you think?
The text was updated successfully, but these errors were encountered:
The IsConditionallyExcluded property in the type system is a good idea.
In SharpDevelop, we currently use this method in the semantic highlighter:
bool IsInactiveConditional(IList<IAttribute> attributes)
{
bool hasConditionalAttribute = false;
foreach (var attr in attributes) {
if (attr.AttributeType.Name == "ConditionalAttribute" && attr.AttributeType.Namespace == "System.Diagnostics" && attr.PositionalArguments.Count == 1) {
string symbol = attr.PositionalArguments[0].ConstantValue as string;
if (symbol != null) {
hasConditionalAttribute = true;
var cu = this.resolver.RootNode as SyntaxTree;
if (cu != null) {
if (cu.ConditionalSymbols.Contains(symbol))
return false; // conditional is active
}
}
}
}
return hasConditionalAttribute;
}
public override void VisitAttribute(ICSharpCode.NRefactory.CSharp.Attribute attribute)
{
ITypeDefinition attrDef = resolver.Resolve(attribute.Type).Type.GetDefinition();
if (attrDef != null && IsInactiveConditional(attrDef.Attributes)) {
Colorize(attribute, inactiveCodeColor);
return;
}
VisitChildren(attribute);
}
To implement IsConditionallyExcluded, we'd just need to add a IList<string> reference to CSharpAttribute (+maybe cache the property value in CSharpResolvedAttribute).
I don't understand 100% what you mean with the IList<string>. Do you mean that the list should contain the list of defined symbols at the point of the attribute instantiation?
I'm thinking about starting to implement this feature.
What do you think about also adding members called ConditionalSymbols to ITypeDefinition and IMethod, and also IsConditionallyRemoved to InvocationResolveResult?
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It is possible to specify a
[ConditionalAttribute]
on an attribute type to indicate that the attribute should only be present in the compiled assembly if a certain symbol is defined when the attribute is instantiated. I need access to this information, so how can we represent it?I suggest a
bool IsConditionallyExcluded
flag onIAttribute
. What do you think?The text was updated successfully, but these errors were encountered: