private ContainerRowModel CreateTypeTree(System.Type type) { var children = new List<RowModel>(); object[] attrs; Attribute attr; BindingFlags flags = BindingFlags.Static | BindingFlags.Public; Lazy<object> instance = null; if (IsConstructable(type)) { flags |= BindingFlags.Instance; instance = new Lazy<object>(() => Activator.CreateInstance(type), LazyThreadSafetyMode.ExecutionAndPublication); } foreach (MethodInfo method in type.GetMethods(flags).Where(m => IsTestMethod(m, true, true, true))) { // Create a row for this method attrs = method.GetCustomAttributes(true); attr = FindAttribute(attrs, "TestAttribute") ?? FindAttribute(attrs, "BenchmarkAttribute"); var eea = FindAttribute(attrs, "ExpectedExceptionAttribute"); bool isTestSet = method.IsStatic && MayBeTestSuite(method.ReturnType) && IsTestMethod(method, true, true, false); var utt = new UnitTestTask(method, instance, attr, eea, isTestSet); var row = new TaskRowModel(method.Name, TestNodeType.Test, utt, true); if (IsTestMethod(method, false, false, true)) // benchmark? row.BasePriority--; // Give benchmarks low priority by default children.Add(row); } foreach (Type nested in type.GetNestedTypes().Where(IsTestFixtureOrSuite)) children.Add(CreateTypeTree(nested)); // Create a row for this type var result = new ContainerRowModel(type.Name, TestNodeType.TestFixture, children); result.SetSummary(type.FullName); attrs = type.GetCustomAttributes(true); attr = FindAttribute(attrs, "TestFixtureAttribute"); string description = GetPropertyValue<string>(attr, "Description", null); if (description != null) result.SetSummary(string.Format("{0} ({1})", description, type.FullName)); return result; }
/// <summary> Write UnionSubclass XML Elements from nested mapped classes in a not-mapped class. </summary> public virtual void WriteNestedUnionSubclassTypes(System.Xml.XmlWriter writer, System.Type type) { foreach(System.Type nestedType in type.GetNestedTypes(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic)) { if(nestedType.GetCustomAttributes(typeof(ClassAttribute), false).Length != 0) continue; if(nestedType.GetCustomAttributes(typeof(UnionSubclassAttribute), false).Length == 0) WriteNestedUnionSubclassTypes(writer, nestedType); // Not mapped (try its nested types) else // Mapped WriteUnionSubclass(writer, nestedType); } }
internal RealSchemaType(System.Type type, WsdlGenerator.XMLNamespace xns, string serviceEndpoint, Hashtable typeToServiceEndpoint, bool bUnique, WsdlGenerator WsdlGenerator) : base(type) { this._type = type; this._serviceEndpoint = serviceEndpoint; this._typeToServiceEndpoint = typeToServiceEndpoint; this._bUnique = bUnique; this._WsdlGenerator = WsdlGenerator; this._bStruct = type.IsValueType; this._xns = xns; this._implIFaces = null; this._iFaces = null; this._methods = null; this._fields = null; this._methodTypes = null; this._nestedTypes = type.GetNestedTypes(); if (this._nestedTypes != null) { foreach (System.Type type2 in this._nestedTypes) { this._WsdlGenerator.AddType(type2, xns); } } }
private RubyMethod FindCLRMethod(string methodId, System.Type clrtype) { BindingFlags flags = BindingFlags.Instance | BindingFlags.Public; if (this._type == Type.IClass) { // static methods if (methodId == "new") { if (clrtype.IsSubclassOf(typeof(System.Delegate))) { return new RubyMethod(new DelegateConstructor(clrtype), 0, Access.Public, this); } else { ConstructorInfo[] ci = clrtype.GetConstructors(); if (ci == null || ci.Length == 0) return null; MethodBase[] mi = new MethodBase[ci.Length]; System.Array.Copy(ci, mi, ci.Length); return new RubyMethod(new MultiMethod(mi), -1, Access.Public, this); } } else if (methodId == "allocator") { return new RubyMethod(Methods.rb_class_allocate_instance.singleton, 0, Access.Private, this); } else if (methodId == "[]") { // instantiate a generic type // ruby: type = ns::List[System::Int32] if (clrtype.IsGenericType) { // clrtype is Type`n+Inner but we are looking for Type`n+Inner`n // we need to strip generic arguments from the name, but supply // them to the GenericTypeGetter return new RubyMethod( new GenericTypeGetter( clrtype.Assembly, clrtype.GetGenericTypeDefinition().FullName, clrtype.GetGenericArguments()), -1, Access.Public, this); } else { return new RubyMethod( new GenericTypeGetter(clrtype.Assembly, clrtype.FullName, null), -1, Access.Public, this); } } flags = BindingFlags.Static | BindingFlags.Public; } bool is_setter = false; // methods ending with "=" are expected to be either // field or property setters if (methodId.EndsWith("=")) { is_setter = true; methodId = methodId.Substring(0, methodId.Length - 1); } // default member access, an Indexer in C# if (methodId == "[]") { object[] attributes = clrtype.GetCustomAttributes( typeof(System.Reflection.DefaultMemberAttribute), true); if (attributes.Length > 0) { methodId = ((DefaultMemberAttribute)attributes[0]).MemberName; } } MemberInfo[] members = clrtype.GetMember(methodId, flags); if (members.Length == 0) { // we didn't find a member with the exact name // but we still need to check for nested types with // additional type parameters string genericNestedId = methodId + "`"; foreach (System.Type nested in clrtype.GetNestedTypes(flags)) { if (nested.Name.StartsWith(genericNestedId)) { return new RubyMethod( new ValueMethod( new GenericContainer( clrtype.Assembly, clrtype.Name + "+" + methodId, clrtype.GetGenericArguments())), 0, Access.Public, this); } } return null; } if (members[0] is MethodBase) { if (is_setter) return null; MethodBase[] methods = new MethodBase[members.Length]; System.Array.Copy(members, methods, members.Length); return new RubyMethod(new MultiMethod(methods), -1, Access.Public, this); } if (members[0] is PropertyInfo) { // not all the property overloads may have the getter/setter // we're looking for, so we maintain a count and resize // the methods array later if necessary int count = 0; MethodBase[] methods = new MethodBase[members.Length]; foreach (PropertyInfo pi in members) { MethodInfo method = is_setter ? pi.GetSetMethod() : pi.GetGetMethod(); if (method != null) methods[count++] = method; } if (count == 0) return null; if (count < members.Length) System.Array.Resize(ref methods, count); return new RubyMethod(new MultiMethod(methods), -1, Access.Public, this); } FieldInfo field = members[0] as FieldInfo; if (field != null) { if (is_setter) return new RubyMethod(new FieldSetter(field), 1, Access.Public, this); else return new RubyMethod(new FieldGetter(field), 0, Access.Public, this); } //EventInfo eventinfo = members[0] as EventInfo; //if (eventinfo != null) //{ // return ...; //} // nested types System.Type type = members[0] as System.Type; if (type != null) { // see section 10.7.1 of ECMA if (type.IsGenericTypeDefinition) type = type.MakeGenericType(clrtype.GetGenericArguments()); return new RubyMethod( new NestedTypeGetter(Load(type, null, false)), 0, Access.Public, this); } return null; }
//----------------------------------------------------------------------------- // Helper to import the specific type and return a TypeEntry. // This will recursively import all base types. // Returns null if we can't import the type. //----------------------------------------------------------------------------- protected TypeEntry AddImportedType(System.Type tImport) { #if true // Don't import non-public classes // be wary of nesting //if (tImport.IsClass || tImport.IsValueType) { if (tImport.DeclaringType == null) { // Not nested if (!tImport.IsPublic) return null; } else { // If Nested, check topmost containing class. System.Type t = tImport; while (t.DeclaringType != null) { t = t.DeclaringType; } if (!t.IsPublic) return null; } } #endif // If we've already imported this, then nothing to do. { TypeEntry t = TryLookupCLRType(tImport); if (t != null) return t; } // Blue doesn't handle Generics (from V2.0 CLR), so just ignore them when imported. if (IsGenericType(tImport)) { Console.WriteLine("Skipping Generic type:" + tImport.FullName); return null; } #if false // Debugging facility. Userbreakpoint when we import a specific class. if (tImport.Name == "IDictionaryEnumerator") System.Diagnostics.Debugger.Break(); #endif // Stub immediately to avoid infinite cycles. TypeEntry tBlue = TypeEntry.CreateImportStub(tImport); m_hashClrType.Add(tImport, tBlue); // If we're a nested type, make sure our containing type is imported. if (tImport.DeclaringType != null) { AddImportedType(tImport.DeclaringType); } Scope scope = this.CreateImportedContext(tImport); string stClass = tImport.Name; // Already check for multiple imports //if (LookupSymbol(scope, stClass, false) == null) { // Add Base class TypeEntry tSuper = null; if (tImport.BaseType != null) { tSuper = AddImportedType(tImport.BaseType); } // Add interfaces, removing all interfaces that we can't access System.Type [] tCLRInterfaces = tImport.GetInterfaces(); ArrayList al = new ArrayList(tCLRInterfaces.Length); foreach(System.Type tInterface in tCLRInterfaces) { TypeEntry t = AddImportedType(tInterface); if (t != null) al.Add(t); } TypeEntry [] tBlueInterfaces = (TypeEntry[]) al.ToArray(typeof(TypeEntry)); TypeEntry tParent = (tImport.DeclaringType == null) ? null : this.ResolveCLRTypeToBlueType(tImport.DeclaringType); // @todo - do we have to check if we've been imported again? // We create the symbol, but don't add the scope until we need to. // (else that would be a lot of scopes to add that we'd never use) // Note that this must be done on the same reference that we added at the top // because by now, the other types have links to that original reference. tBlue.FinishImportStub(tSuper, tBlueInterfaces, tParent); scope.AddSymbol(tBlue); #if true // If we have any nested classes, add them. // This will require us to create the class scope. System.Type [] tNestedTypes = tImport.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic); if (tNestedTypes.Length > 0) { tBlue.EnsureScopeCreated(); foreach(System.Type tNested in tNestedTypes) { AddImportedType(tNested); } } #endif return tBlue; } /* else { ThrowError(SymbolError.IllegalAssembly(tImport.Assembly, "Class '" + tImport.FullName + "' defined multiple times")); return null; } */ } // end function