Esempio n. 1
0
        public static void ImportExtensionMethodsIntoPackage(Package package, Type type)
        {
            package.VerifyNoMissingSymbols();

            var isbuiltin        = type.Assembly == Assembly.GetExecutingAssembly();
            var extendedType     = (Type)package.Dict["T"].CheckedValue;
            var restrictedImport = type.GetCustomAttributes(typeof(RestrictedImportAttribute), true).Length != 0;
            var names            = type.GetMethods(ImportBindingFlags).Select(x => x.Name).Distinct().ToArray();

            foreach (var name in names)
            {
                var methods = type.GetMember(name, ImportBindingFlags)
                              .Where(x => x is MethodInfo)
                              .Select(x => (MethodInfo)ResolveGenericMethod((MethodInfo)x))
                              .Where(x => ExtendsType(x, extendedType))
                              .ToList();

                if (methods.Count == 0)
                {
                    continue;
                }

                var importable = !restrictedImport || methods[0].GetCustomAttributes(typeof(LispAttribute), true).Length != 0;

                if (!importable)
                {
                    continue;
                }

                var sym     = package.FindOrCreate(name.LispName(), useMissing: true, excludeUseList: true, export: true);
                var builtin = sym.Value as ImportedFunction;

                if (builtin == null)
                {
                    sym.FunctionValue = builtin = new ImportedFunction(name, type);
                }

                if (isbuiltin)
                {
                    // Designed to go before other methods.
                    methods.AddRange(builtin.BuiltinExtensionMembers);
                    builtin.BuiltinExtensionMembers = methods.Distinct().ToArray();
                }
                else
                {
                    // todo: change order
                    // Goes after other methods as in c#.
                    methods.AddRange(builtin.ExternalExtensionMembers);
                    builtin.ExternalExtensionMembers = methods.Distinct().ToArray();
                }
            }
        }
Esempio n. 2
0
        public static void ImportIntoPackage(Package package, Type type)
        {
            AddPackageByType(type, package);

            var restrictedImport = type.GetCustomAttributes(typeof(RestrictedImportAttribute), true).Length != 0;

            package.ImportedType     = type;
            package.RestrictedImport = restrictedImport;
            var sym = package.FindOrCreate("T", excludeUseList: true, export: true);

            sym.ConstantValue = type;
            sym.Documentation = string.Format("The .NET type <{0}> imported in this package.", type);

            if (!ToBool(Symbols.LazyImport.Value))
            {
                package.VerifyNoMissingSymbols();
            }
        }