Пример #1
0
        /// <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);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Reflect PHP classes declared statically in the given script <c>type</c>.
        /// </summary>
        /// <param name="scriptType">Script type to reflect.</param>
        /// <param name="types">List of types to reflect to.</param>
        private static void ReflectScriptTypeClasses(Type scriptType,
                                                     Dictionary <string, DTypeDesc> /*!*/ types)
        {
            ScriptDeclaresAttribute script_declares = ScriptDeclaresAttribute.Reflect(scriptType);

            if (script_declares == null)
            {
                return;
            }

            var module = scriptType.Module;

            foreach (var typeToken in script_declares.DeclaredTypes)
            {
                Type type = module.ResolveType(typeToken);

                // reflect PHP class, skip PHP types that were declared conditionally
                if (PhpType.IsPhpRealType(type) && !PhpType.IsRealConditionalDefinition(type))
                {
                    // converts CLR namespaces and nested types to PHP namespaces:
                    string full_name = QualifiedName.FromClrNotation(type.FullName, true).ToString();

                    // Creating PhpTypeDesc with cache lookup since this type can be in the cache already:
                    // Also force PHP type, because we already checked PhpType.IsPhpRealType(type)
                    PhpTypeDesc phpType = (PhpTypeDesc)DTypeDesc.Create(type.TypeHandle);

                    DTypeDesc existing;
                    if (types.TryGetValue(full_name, out existing))
                    {
                        // TODO (TP): can be generic overload!!
                        existing.MemberAttributes |= PhpMemberAttributes.Ambiguous;
                    }
                    types.Add(full_name, phpType);
                }
            }
        }