예제 #1
0
        public ForeignClass(Type target)
        {
            this.target = target.GetTypeInfo();

            if (this.target.IsAbstract && !this.target.IsSealed)
            {
                throw new ArgumentException("The target type can't be abstract!", nameof(target));
            }

            if (this.target.IsGenericType && this.target.GetGenericTypeDefinition() == this.target.AsType())
            {
                throw new ArgumentException("The target type can't be an undefined generic!", nameof(target));
            }

            getSlotForeign = Expression.Call(vmParam, genericGetSlotForeign.MakeGenericMethod(target), slot);

            Functions = new ReadOnlyDictionary <string, WrenForeignMethod>(functions);

            var classAttribute = this.target.GetCustomAttribute <WrenClassAttribute>();

            Name = classAttribute?.Name ?? this.target.Name;

            classMethods = new WrenForeignClassMethods
            {
                Allocate = WrenConstructorAttribute.MakeAllocator(target),
                Finalize = WrenFinalizerAttribute.MakeFinalizer(target)
            };

            Source = generateSource();
        }
예제 #2
0
        private void makeConstructors(StringBuilder sourceBuilder)
        {
            var constructor = WrenConstructorAttribute.GetConstructorDetails(target.AsType());

            if (constructor == null)
            {
                return;
            }

            foreach (var constructorAttribute in constructor.Attributes)
            {
                sourceBuilder.AppendLine($@"{Definition.MakeConstructor(constructorAttribute.Arguments)} {{{(
                    constructorAttribute.HasCode ? $"\n{constructorAttribute.GetCode(target.AsType())}\n" : " ")}}}");
            }
        }