/// <summary> /// Used by CLR modules and PHP pure modules. /// </summary> internal static void ReflectTypes(Assembly /*!*/ realAssembly, Dictionary <string, DTypeDesc> /*!*/ types) { // types: foreach (Type type in realAssembly.GetTypes()) { if (type.IsVisible) { // skip PHP types that were declared conditionally: if (PhpType.IsPhpRealType(type) && PhpType.IsRealConditionalDefinition(type)) { continue; } // converts CLR namespaces and nested types to PHP namespaces: string full_name = ClrNotationUtils.FromClrNotation(type.FullName, true).ToString(); DTypeDesc existing; if (types.TryGetValue(full_name, out existing)) { ClrTypeDesc existing_clr = existing as ClrTypeDesc; if (existing_clr != null && (existing_clr.GenericOverloads.Count > 0 || type.IsGenericTypeDefinition)) { ClrTypeDesc new_clr = DTypeDesc.Create(type) as ClrTypeDesc; if (new_clr != null) { // type is overloaded by the number of generic parameters: existing_clr.AddGenericOverload(new_clr); } else { // do not add, just mark existing with the flag: existing.MemberAttributes |= PhpMemberAttributes.Ambiguous; } } else { // do not add, just mark existing with the flag: existing.MemberAttributes |= PhpMemberAttributes.Ambiguous; } } else { types[full_name] = DTypeDesc.Create(type); } } } }
/// <summary> /// Used by full-reflect. /// </summary> public ClrEvent(VariableName name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, EventInfo/*!*/ realEvent, bool hasAddMethod, bool hasRemoveMethod) : base(new DPropertyDesc(declaringType, memberAttributes), name) { this.realEvent = realEvent; this.hasAddMethod = hasAddMethod; this.hasRemoveMethod = hasRemoveMethod; }
/// <summary> /// Used by full-reflect. /// </summary> public ClrProperty(VariableName name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, PropertyInfo/*!*/ realProperty, bool hasGetter, bool hasSetter) : base(new DPropertyDesc(declaringType, memberAttributes), name) { Debug.Assert(realProperty != null); this.realProperty = realProperty; this.hasGetter = hasGetter; this.hasSetter = hasSetter; }
/// <summary> /// Used by full-reflect. /// </summary> public ClrField(VariableName/*!*/ name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, FieldInfo/*!*/ fieldInfo) : base(new DPropertyDesc(declaringType, memberAttributes), name) { this.fieldInfo = fieldInfo; }
/// <summary> /// Used by full-reflect (<see cref="DTypeDesc"/>). /// </summary> internal static ClrMethod/*!*/ CreateConstructor(ClrTypeDesc/*!*/ declaringType) { ClrMethod result; if (declaringType is ClrDelegateDesc) { // the real constructor should not be accessible from PHP code result = new ClrMethod(Name.ClrCtorName, declaringType, PhpMemberAttributes.Constructor, 1, false); result.ClrMethodDesc.ArglessStub = new RoutineDelegate(declaringType._NoConstructorErrorStub); } else { ConstructorInfo[] realOverloads = declaringType.RealType.GetConstructors( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); //// TODO (less restrictive?): PhpMemberAttributes attrs = PhpMemberAttributes.Constructor; int visible_count = 0; for (int i = 0; i < realOverloads.Length; i++) { if (ClrTypeDesc.IsMethodVisible(realOverloads[i])) visible_count++; } if (declaringType.RealType.IsValueType) // add an empty .ctor visible_count++; if (visible_count > 0) { result = new ClrMethod(Name.ClrCtorName, declaringType, attrs, visible_count, false); foreach (MethodBase real_overload in realOverloads) { if (ClrTypeDesc.IsMethodVisible(real_overload)) { Overload overload; result.AddOverload(real_overload, out overload); } } if (declaringType.RealType.IsValueType) // add an empty .ctor { Overload overload; result.AddOverload(BuildDefaultValueCtor(declaringType.RealType), out overload); } } else { result = new ClrMethod(Name.ClrCtorName, declaringType, PhpMemberAttributes.Constructor, 1, false); result.ClrMethodDesc.ArglessStub = new RoutineDelegate(declaringType._NoConstructorErrorStub); } } return result; }