本文整理汇总了C#中TypeNode类的典型用法代码示例。如果您正苦于以下问题:C# TypeNode类的具体用法?C# TypeNode怎么用?C# TypeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeNode类属于命名空间,在下文中一共展示了TypeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
public override ProblemCollection Check(TypeNode type)
{
Type runtimeType = type.GetRuntimeType();
if ( IsTestFixture( runtimeType ) )
{
System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly );
// Note that if an method with an invalid signature is marked as a setup method, then
// it will be considered as not marked and hence setupMethod will be null.
// Same applies for tearDownMethod.
System.Reflection.MethodInfo setupMethod = Reflect.GetSetUpMethod( runtimeType );
System.Reflection.MethodInfo tearDownMethod = Reflect.GetTearDownMethod( runtimeType );
System.Reflection.MethodInfo fixtureSetupMethod = Reflect.GetFixtureSetUpMethod( runtimeType );
System.Reflection.MethodInfo fixtureTearDownMethod = Reflect.GetFixtureTearDownMethod( runtimeType );
foreach( System.Reflection.MethodInfo methodInfo in methods )
{
if ( !IsTestCaseMethod( methodInfo ) &&
( methodInfo != setupMethod ) &&
( methodInfo != tearDownMethod ) &&
( methodInfo != fixtureSetupMethod ) &&
( methodInfo != fixtureTearDownMethod ) )
{
Resolution resolution = GetResolution( methodInfo.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
}
}
if ( base.Problems.Count > 0 )
return base.Problems;
}
return base.Check (type);
}
示例2: Check
/// <summary>
/// Checks the specified type.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public override ProblemCollection Check(TypeNode type)
{
AttributeNode attribute = SemanticRulesUtilities.GetAttribute(type, ServiceContractAttribute);
if (SemanticRulesUtilities.HasAttribute<ServiceContractAttribute>(attribute))
{
List<string> duplicated = new List<string>();
foreach (Member member in type.Members)
{
if (SemanticRulesUtilities.GetAttribute(member, OperationContractAttribute) != null)
{
if (duplicated.Contains(member.Name.Name))
{
Resolution resolution = base.GetResolution(member.FullName);
Problem problem = new Problem(resolution, type.SourceContext);
base.Problems.Add(problem);
}
else
{
duplicated.Add(member.Name.Name);
}
}
}
}
return base.Problems;
}
示例3: Check
public override ProblemCollection Check(TypeNode type)
{
Type runtimeType = type.GetRuntimeType();
if ( IsTestFixture( runtimeType ) )
{
PropertyInfo[] properties;
// check for instance public properties
properties = runtimeType.GetProperties( BindingFlags.Instance | BindingFlags.Public );
foreach( PropertyInfo instanceProperty in properties )
{
Resolution resolution = GetResolution( instanceProperty.DeclaringType.Name, instanceProperty.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
}
// check for static public properties, whether declared in the class
// or one of its base classes.
properties = runtimeType.GetProperties( BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy );
foreach( PropertyInfo staticProperty in properties )
{
Resolution resolution = GetResolution( staticProperty.DeclaringType.Name, staticProperty.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
}
}
if ( base.Problems.Count > 0 )
return base.Problems;
return base.Check (type);
}
开发者ID:BackupTheBerlios,项目名称:fxcop4nunit-svn,代码行数:32,代码来源:TestFixturesShouldNotContainPublicPropertiesRule.cs
示例4: IsTypeSafe
/// <summary>
/// Numeric, bool, DateTime, etc. types are safe from SQL/XSS injection. User-defined types composed entirely of safe types are also safe.
/// </summary>
protected bool IsTypeSafe(TypeNode t, HashSet<string> checkedTypes = null)
{
if (t == null)
return true;
if (checkedTypes == null)
checkedTypes = new HashSet<string>();
else if (checkedTypes.Contains(t.FullName)) //don't recurse infinitely into self-referencing types
return true;
checkedTypes.Add(t.FullName);
if (IsStringIsh(t) || (t.TemplateArguments != null && t.TemplateArguments.Any(a => IsStringIsh(a))))
return false;
if (t.IsPrimitiveNumeric || t is EnumNode)
return true;
if (_maybeSafeGenericTypes.Any(a => t.IsDerivedFrom(a)) && t.TemplateArguments != null && t.TemplateArguments.All(a => IsTypeSafe(a, checkedTypes)))
return true;
if (_safeTypes.Contains(t.FullName))
return true;
return t.Members.Where(w => w.Name.Name != "ToString").All(a => IsTypeSafe(a, checkedTypes));
}
示例5: ProcessChildNode
void ProcessChildNode(TypeNode node, MethodReference changedInvokerMethod)
{
var childEventInvoker = FindEventInvokerMethodRef(node.TypeDefinition);
if (childEventInvoker == null)
{
if (changedInvokerMethod != null)
{
if (node.TypeDefinition.BaseType.IsGenericInstance)
{
var methodReference = MakeGeneric(node.TypeDefinition.BaseType, changedInvokerMethod);
changedInvokerMethod = methodReference;
}
}
}
else
{
changedInvokerMethod = childEventInvoker;
}
node.IsChangedInvoker = changedInvokerMethod;
foreach (var childNode in node.Nodes)
{
ProcessChildNode(childNode, changedInvokerMethod);
}
}
示例6: Check
public override ProblemCollection Check(TypeNode type)
{
Type runtimeType = type.GetRuntimeType();
if ( IsTestFixture( runtimeType ) )
{
// if more than one setup, trigger error.
if ( GetTestSetupMethodsCount( runtimeType ) > 1 )
{
Resolution resolution = GetNamedResolution( "SetUp", type.Name.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
return base.Problems;
}
// if more than one setup, trigger error.
if ( GetFixtureSetupMethodsCount( runtimeType ) > 1 )
{
Resolution resolution = GetNamedResolution( "TestFixtureSetUp", type.Name.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
return base.Problems;
}
}
return base.Check (type);
}
示例7: GetOnChangedMethods
IEnumerable<OnChangedMethod> GetOnChangedMethods(TypeNode notifyNode)
{
var methods = notifyNode.TypeDefinition.Methods;
var onChangedMethods = methods.Where(x => !x.IsStatic &&
!x.IsAbstract &&
//(IsNoArgOnChangedMethod(x) ||
//IsBeforeAfterOnChangedMethod(x)) &&
x.Name.StartsWith("On") &&
x.Name.EndsWith("Changed"));
foreach (var methodDefinition in onChangedMethods)
{
var typeDefinitions = new Stack<TypeDefinition>();
typeDefinitions.Push(notifyNode.TypeDefinition);
if (IsNoArgOnChangedMethod(methodDefinition))
{
yield return new OnChangedMethod
{
OnChangedType = OnChangedTypes.NoArg,
MethodReference = GetMethodReference(typeDefinitions, methodDefinition)
};
}
else if (IsBeforeAfterOnChangedMethod(methodDefinition))
{
yield return new OnChangedMethod
{
OnChangedType = OnChangedTypes.BeforeAfter,
MethodReference = GetMethodReference(typeDefinitions, methodDefinition)
};
}
}
}
示例8: TypeCache
public TypeCache (string fullName)
{
this.cache_is_valid = false;
this.have_type = false;
this.cache = default(TypeNode);
this.full_name = fullName;
}
示例9: Duplicator
/// <param name="module">The module into which the duplicate IR will be grafted.</param>
/// <param name="type">The type into which the duplicate Member will be grafted. Ignored if entire type, or larger unit is duplicated.</param>
public Duplicator(Module/*!*/ module, TypeNode type) {
this.TargetModule = module;
this.TargetType = this.OriginalTargetType = type;
this.DuplicateFor = new TrivialHashtable();
this.TypesToBeDuplicated = new TrivialHashtable();
//^ base();
}
示例10: Check
public override ProblemCollection Check(TypeNode type)
{
Type runtimeType = type.GetRuntimeType();
if ( IsTestFixture( runtimeType ) && !runtimeType.IsAbstract && type.IsVisibleOutsideAssembly )
{
MemberList constructors = type.GetConstructors();
for ( int i = 0; i < constructors.Length; ++i )
{
Member constructor = constructors[i];
// only examine non-static constructors
Microsoft.Cci.InstanceInitializer instanceConstructor =
constructor as Microsoft.Cci.InstanceInitializer;
if ( instanceConstructor == null )
continue;
// trigger errors for non-default constructors.
if ( ( instanceConstructor.Parameters.Length != 0 ) &&
( !instanceConstructor.IsPrivate ) )
{
Resolution resolution = GetResolution( runtimeType.Name );
Problem problem = new Problem( resolution );
base.Problems.Add( problem );
}
}
if ( base.Problems.Count > 0 )
return base.Problems;
}
return base.Check (type);
}
示例11: ExistingTypeNodeUpdater
public ExistingTypeNodeUpdater(Lazy<IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, MergedImportedType type) {
targetType = type.TargetType;
ownerModule = targetType.Module;
origTypeDefOptions = new TypeDefOptions(targetType);
newTypeDefOptions = type.NewTypeDefOptions;
typeNode = modNode.Context.DocumentTreeView.FindNode(targetType);
if (typeNode == null)
throw new InvalidOperationException();
nestedTypes1 = type.NewOrExistingNestedTypes.OfType<MergedImportedType>().Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray();
nestedTypes2 = type.NewOrExistingNestedTypes.OfType<NewImportedType>().Select(a => new NestedTypeNodeCreator(modNode, typeNode, a.TargetType)).ToArray();
if (nestedTypes1.Length + nestedTypes2.Length != type.NewOrExistingNestedTypes.Count)
throw new InvalidOperationException();
fields = type.NewFields.Select(a => new FieldNodeCreator(modNode, typeNode, a)).ToArray();
var specialMethods = GetSpecialMethods(type);
methods = type.NewMethods.Where(a => !specialMethods.Contains(a)).Select(a => new MethodNodeCreator(modNode, typeNode, a)).ToArray();
events = type.NewEvents.Select(a => new EventNodeCreator(modNode, typeNode, a)).ToArray();
properties = type.NewProperties.Select(a => new PropertyNodeCreator(modNode, typeNode, a)).ToArray();
editedFields = type.EditedFields.Select(a => new EditedFieldUpdater(modNode, a.OriginalField, a.FieldDefOptions)).ToArray();
editedMethods = type.EditedMethods.Select(a => new EditedMethodUpdater(methodAnnotations, modNode, a.OriginalMethod, a.NewBody, a.MethodDefOptions)).ToArray();
editedProperties = type.EditedProperties.Select(a => new EditedPropertyUpdater(modNode, a.OriginalProperty, a.PropertyDefOptions)).ToArray();
editedEvents = type.EditedEvents.Select(a => new EditedEventUpdater(modNode, a.OriginalEvent, a.EventDefOptions)).ToArray();
deletedTypes = type.DeletedNestedTypes.Select(a => new DeletedTypeUpdater(modNode, a)).ToArray();
deletedFields = type.DeletedFields.Select(a => new DeletedFieldUpdater(modNode, a)).ToArray();
deletedMethods = type.DeletedMethods.Select(a => new DeletedMethodUpdater(modNode, a)).ToArray();
deletedProperties = type.DeletedProperties.Select(a => new DeletedPropertyUpdater(modNode, a)).ToArray();
deletedEvents = type.DeletedEvents.Select(a => new DeletedEventUpdater(modNode, a)).ToArray();
}
示例12: ProcessChildNode
void ProcessChildNode(TypeNode node, EventInvokerMethod eventInvoker)
{
var childEventInvoker = FindEventInvokerMethod(node.TypeDefinition);
if (childEventInvoker == null)
{
if (node.TypeDefinition.BaseType.IsGenericInstance)
{
var methodReference = MakeGeneric(node.TypeDefinition.BaseType, eventInvoker.MethodReference);
eventInvoker = new EventInvokerMethod
{
InvokerType = eventInvoker.InvokerType,
MethodReference = methodReference,
};
}
}
else
{
eventInvoker = childEventInvoker;
}
node.EventInvoker = eventInvoker;
foreach (var childNode in node.Nodes)
{
ProcessChildNode(childNode, eventInvoker);
}
}
示例13: VisitTypeNode
public override TypeNode VisitTypeNode(TypeNode typeNode) {
TypeNode savedCurrentType = this.currentType;
this.currentType = typeNode;
TypeNode result = base.VisitTypeNode(typeNode);
this.currentType = savedCurrentType;
return result;
}
示例14: Test
public void Test()
{
var gen = new XmlResultsGenerator(null,null,null, null, null);
var muSession = new MutationTestingSession();
var mutar = new MutationTarget(new MutationVariant());
var ass = new AssemblyNode("Assembly");
muSession.MutantsGrouped.Add(ass);
var nodeNamespace = new TypeNamespaceNode(ass, "Namespace");
ass.Children.Add(nodeNamespace);
var nodeType = new TypeNode(nodeNamespace, "Type");
nodeNamespace.Children.Add(nodeType);
var nodeMethod = new MethodNode(nodeType, "Method", null, true);
nodeType.Children.Add(nodeMethod);
var nodeGroup = new MutantGroup("Gr1", nodeMethod);
nodeMethod.Children.Add(nodeGroup);
var nodeMutant = new Mutant("m1", nodeGroup, mutar);
nodeGroup.Children.Add(nodeMutant);
XDocument generateResults = gen.GenerateResults(muSession, false, false, ProgressCounter.Inactive(), CancellationToken.None).Result;
Console.WriteLine(generateResults.ToString());
//gen.
}
示例15: ProcessField
void ProcessField(TypeNode node, FieldDefinition field)
{
var name = field.Name;
if (!field.IsPublic || field.IsStatic || !char.IsUpper(name, 0))
{
return;
}
if (node.TypeDefinition.HasGenericParameters)
{
var message = string.Format("Skipped converting public field '{0}.{1}' to a property because generic types are not currently supported. You should make this a public property instead.", node.TypeDefinition.Name, field.Name);
logger.LogWarning(message);
return;
}
field.Name = string.Format("<{0}>k__BackingField", name);
field.IsPublic = false;
field.IsPrivate = true;
var get = GetGet(field, name);
node.TypeDefinition.Methods.Add(get);
var set = GetSet(field, name);
node.TypeDefinition.Methods.Add(set);
var propertyDefinition = new PropertyDefinition(name, PropertyAttributes.None, field.FieldType)
{
GetMethod = get,
SetMethod = set
};
foreach (var customAttribute in field.CustomAttributes)
{
propertyDefinition.CustomAttributes.Add(customAttribute);
}
node.TypeDefinition.Properties.Add(propertyDefinition);
ForwardedFields.Add(field, propertyDefinition);
}