本文整理汇总了C#中TypeDeclaration.HasModifier方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDeclaration.HasModifier方法的具体用法?C# TypeDeclaration.HasModifier怎么用?C# TypeDeclaration.HasModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeDeclaration
的用法示例。
在下文中一共展示了TypeDeclaration.HasModifier方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTypeDeclaration
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
if (!typeDeclaration.HasModifier(Modifiers.Public))
{
base.VisitTypeDeclaration(typeDeclaration);
return;
}
this.m_TotalClasses++;
if (this.m_TotalClasses > 1)
{
this.Results.Issues.Add(new LintIssue(typeDeclaration)
{
Index = LintIssueIndex.MoreThanOneClassInFile,
Parameters = new[]
{
typeDeclaration.Name,
this.m_FirstClassName
}
});
}
else
{
this.m_FirstClassName = typeDeclaration.Name;
}
base.VisitTypeDeclaration(typeDeclaration);
}
示例2: VisitTypeDeclaration
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
if (!typeDeclaration.HasModifier(Modifiers.Public))
{
base.VisitTypeDeclaration(typeDeclaration);
return;
}
var idx = this.Results.BaseName.LastIndexOf('.');
var filename = this.Results.BaseName;
if (idx != -1)
filename = filename.Substring(0, idx);
if (typeDeclaration.Name != filename)
{
this.Results.Issues.Add(new LintIssue(typeDeclaration)
{
Index = LintIssueIndex.ClassNameDoesNotMatchFileName,
Parameters = new[]
{
typeDeclaration.Name,
filename
}
});
}
base.VisitTypeDeclaration(typeDeclaration);
}
示例3: CreateEventInvocator
public static MethodDeclaration CreateEventInvocator (RefactoringContext context, TypeDeclaration declaringType, EventDeclaration eventDeclaration, VariableInitializer initializer, IMethod invokeMethod, bool useExplictType)
{
bool hasSenderParam = false;
IEnumerable<IParameter> pars = invokeMethod.Parameters;
if (invokeMethod.Parameters.Any()) {
var first = invokeMethod.Parameters [0];
if (first.Name == "sender" /*&& first.Type == "System.Object"*/) {
hasSenderParam = true;
pars = invokeMethod.Parameters.Skip(1);
}
}
const string handlerName = "handler";
var arguments = new List<Expression>();
if (hasSenderParam)
arguments.Add(eventDeclaration.HasModifier (Modifiers.Static) ? (Expression)new PrimitiveExpression (null) : new ThisReferenceExpression());
bool useThisMemberReference = false;
foreach (var par in pars) {
arguments.Add(new IdentifierExpression(par.Name));
useThisMemberReference |= par.Name == initializer.Name;
}
var proposedHandlerName = GetNameProposal(initializer);
var modifiers = eventDeclaration.HasModifier(Modifiers.Static) ? Modifiers.Static : Modifiers.Protected | Modifiers.Virtual;
if (declaringType.HasModifier (Modifiers.Sealed)) {
modifiers = Modifiers.None;
}
var methodDeclaration = new MethodDeclaration {
Name = proposedHandlerName,
ReturnType = new PrimitiveType ("void"),
Modifiers = modifiers,
Body = new BlockStatement {
new VariableDeclarationStatement (
useExplictType ? eventDeclaration.ReturnType.Clone () : new PrimitiveType ("var"), handlerName,
useThisMemberReference ?
(Expression)new MemberReferenceExpression (new ThisReferenceExpression (), initializer.Name)
: new IdentifierExpression (initializer.Name)
),
new IfElseStatement {
Condition = new BinaryOperatorExpression (new IdentifierExpression (handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)),
TrueStatement = new InvocationExpression (new IdentifierExpression (handlerName), arguments)
}
}
};
foreach (var par in pars) {
var typeName = context.CreateShortType(par.Type);
var decl = new ParameterDeclaration(typeName, par.Name);
methodDeclaration.Parameters.Add(decl);
}
return methodDeclaration;
}
示例4: VisitTypeDeclaration
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
if (!typeDeclaration.HasModifier(Modifiers.Public))
{
base.VisitTypeDeclaration(typeDeclaration);
return;
}
var parent = typeDeclaration.GetParent<TypeDeclaration>();
if (parent != null && typeDeclaration.HasModifier(Modifiers.Public))
{
this.Results.Issues.Add(new LintIssue(typeDeclaration)
{
Index = LintIssueIndex.PublicNestedClassDefined,
Parameters = new[]
{
typeDeclaration.Name
}
});
}
base.VisitTypeDeclaration(typeDeclaration);
}
示例5: VisitTypeDeclaration
public override void VisitTypeDeclaration (TypeDeclaration typeDeclaration)
{
if (typeDeclaration.HasModifier (Modifiers.Abstract))
return;
var result = resolver.Resolve (typeDeclaration);
if (result == null || result.Type.GetDefinition () == null)
return;
UnitTestLocation unitTest = null;
bool isIgnored = false;
foreach (var attr in result.Type.GetDefinition ().GetAttributes ()) {
if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestFixtureAttribute") {
unitTest = new UnitTestLocation (typeDeclaration.NameToken.StartLocation.Line);
unitTest.IsFixture = true;
unitTest.UnitTestIdentifier = GetFullName (typeDeclaration);
foundTests.Add (unitTest);
} else
isIgnored |= attr.AttributeType.ReflectionName == "NUnit.Framework.IgnoreAttribute";
}
if (unitTest != null) {
unitTest.IsIgnored = isIgnored;
base.VisitTypeDeclaration (typeDeclaration);
}
}
示例6: VisitTypeDeclaration
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
bool outerTypeIsPartial = currentTypeIsPartial;
currentTypeIsPartial = typeDeclaration.HasModifier(Modifiers.Partial);
base.VisitTypeDeclaration(typeDeclaration);
currentTypeIsPartial = outerTypeIsPartial;
}
示例7: VisitTypeDeclaration
public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
if (this.CurrentType != null)
{
this.NestedTypes = this.NestedTypes ?? new List<Tuple<TypeDeclaration, ITypeInfo>>();
this.NestedTypes.Add(new Tuple<TypeDeclaration, ITypeInfo>(typeDeclaration, this.CurrentType));
return;
}
ValidateNamespace(typeDeclaration);
if (this.HasIgnore(typeDeclaration))
{
return;
}
var rr = this.Resolver.ResolveNode(typeDeclaration, null);
var fullName = rr.Type.ReflectionName;
var partialType = this.Types.FirstOrDefault(t => t.Key == fullName);
var add = true;
if (partialType == null)
{
ITypeInfo parentTypeInfo = null;
var parentTypeDeclaration = typeDeclaration.GetParent<TypeDeclaration>();
if (parentTypeDeclaration != null)
{
var rr1 = this.Resolver.ResolveNode(parentTypeDeclaration, null);
var parentName = rr1.Type.ReflectionName;
parentTypeInfo = this.Types.FirstOrDefault(t => t.Key == parentName);
}
this.CurrentType = new TypeInfo()
{
Key = rr.Type.ReflectionName,
TypeDeclaration = typeDeclaration,
ParentType = parentTypeInfo,
Name = typeDeclaration.Name,
ClassType = typeDeclaration.ClassType,
Namespace = this.Namespace,
Usings = new HashSet<string>(Usings),
IsEnum = typeDeclaration.ClassType == ClassType.Enum,
IsStatic = typeDeclaration.ClassType == ClassType.Enum || typeDeclaration.HasModifier(Modifiers.Static),
IsObjectLiteral = this.IsObjectLiteral(typeDeclaration),
Type = rr.Type
};
if (parentTypeInfo != null && Emitter.reservedStaticNames.Any(n => String.Equals(this.CurrentType.Name, n, StringComparison.InvariantCultureIgnoreCase)))
{
throw new EmitterException(typeDeclaration, "Nested class cannot have such name: " + this.CurrentType.Name + ". Please rename it.");
}
}
else
{
this.CurrentType = partialType;
add = false;
}
if (typeDeclaration.ClassType != ClassType.Interface)
{
typeDeclaration.AcceptChildren(this);
}
else
{
typeDeclaration.AcceptChildren(this);
}
if (add)
{
this.Types.Add(this.CurrentType);
}
this.CurrentType = null;
while (this.NestedTypes != null && this.NestedTypes.Count > 0)
{
var types = this.NestedTypes;
this.NestedTypes = null;
foreach (var nestedType in types)
{
this.VisitTypeDeclaration(nestedType.Item1);
}
}
}