Esempio n. 1
0
        public void Overrides(bool isInterface, bool isSealed, bool isAbstract)
        {
            var mGenerics = Enumerable.Range(0, 2).Select(i => GenericParameter.Create("U" + i)).ToArray();
            var baseType  = isInterface ? TypeSignature.Interface("Base", ns, Accessibility.APublic)
                                       : TypeSignature.Class("BaseC", ns, Accessibility.APublic, isAbstract: true);

            var baseMethod1  = MethodSignature.Abstract("M1", baseType, isInterface ? Accessibility.APublic : Accessibility.AProtected, TypeSignature.Object).With(isAbstract: isInterface);
            var baseMethod2  = MethodSignature.Abstract("M2", baseType, Accessibility.APublic, mGenerics[0], new MethodParameter(mGenerics[1], "a")).With(typeParameters: mGenerics.ToImmutableArray());
            var baseProperty = PropertySignature.Abstract("P1", baseType, TypeSignature.Boolean, Accessibility.APublic, null);

            cx.AddType(TypeDef.Empty(baseType).AddMember(
                           isInterface ? MethodDef.InterfaceDef(baseMethod1) : MethodDef.Create(baseMethod1, _ => Expression.Constant <object>(null)),
                           MethodDef.InterfaceDef(baseMethod2),
                           PropertyDef.InterfaceDef(baseProperty)
                           ));

            var type     = TypeSignature.Class("C", ns, Accessibility.APublic, canOverride: !isSealed, isAbstract: isAbstract);
            var method1  = MethodSignature.Override(type, baseMethod1, isAbstract: isAbstract);
            var method2  = MethodSignature.Override(type, baseMethod2);
            var property = PropertySignature.Override(type, baseProperty);

            cx.AddType(TypeDef.Empty(type, isInterface ? null : baseType.Specialize())
                       .AddImplements(isInterface ? new [] { baseType.Specialize() } : new SpecializedType[0])
                       .AddMember(
                           isAbstract ? MethodDef.InterfaceDef(method1) : MethodDef.Create(method1, _ => Expression.Constant(1).Box()),
                           MethodDef.Create(method2, (_, __) => Expression.Default(method2.TypeParameters[0])),
                           PropertyDef.Create(property, @this => Expression.Default(property.Type))
                           ));

            check.CheckOutput(cx, $"ifc({isInterface})-sealed({isSealed})-abstract({isAbstract})");
        }