Ejemplo n.º 1
0
        static Tuple <AccessLevel, SealedEnum, AbstractEnum> EmitModifiers(Type type)
        {
            //set defaults
            AccessLevel  _access   = AccessLevel.IsPrivate;
            AbstractEnum _abstract = AbstractEnum.NotAbstract;
            SealedEnum   _sealed   = SealedEnum.NotSealed;

            // check if not default
            if (type.IsPublic)
            {
                _access = AccessLevel.IsPublic;
            }
            else if (type.IsNestedPublic)
            {
                _access = AccessLevel.IsPublic;
            }
            else if (type.IsNestedFamily)
            {
                _access = AccessLevel.IsProtected;
            }
            else if (type.IsNestedFamANDAssem)
            {
                _access = AccessLevel.IsProtectedInternal;
            }
            if (type.IsSealed)
            {
                _sealed = SealedEnum.Sealed;
            }
            if (type.IsAbstract)
            {
                _abstract = AbstractEnum.Abstract;
            }
            return(new Tuple <AccessLevel, SealedEnum, AbstractEnum>(_access, _sealed, _abstract));
        }
Ejemplo n.º 2
0
        private Tuple <AccessLevel, SealedEnum, AbstractEnum> EmitModifiers(Type type)
        {
            AccessLevel accessModifier = Model.AccessLevel.Private;

            if (type.IsPublic || type.IsNestedPublic)
            {
                accessModifier = Model.AccessLevel.Public;
            }
            else if (type.IsNestedFamily)
            {
                accessModifier = Model.AccessLevel.Protected;
            }
            else
            {
                accessModifier = Model.AccessLevel.Internal;
            }

            SealedEnum sealedModifier = Model.SealedEnum.NotSealed;

            if (type.IsSealed)
            {
                sealedModifier = Model.SealedEnum.Sealed;
            }

            AbstractEnum abstractModifier = Model.AbstractEnum.NotAbstract;

            if (type.IsAbstract)
            {
                abstractModifier = Model.AbstractEnum.Abstract;
            }

            return(new Tuple <AccessLevel, SealedEnum, AbstractEnum>(accessModifier, sealedModifier, abstractModifier));
        }
Ejemplo n.º 3
0
        private static Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum> EmitModifiers(MethodBase method)
        {
            AccessLevel accessModifier = Model.AccessLevel.Private;

            if (method.IsPublic)
            {
                accessModifier = Model.AccessLevel.Public;
            }
            else if (method.IsFamily)
            {
                accessModifier = Model.AccessLevel.Protected;
            }
            else if (method.IsFamilyAndAssembly)
            {
                accessModifier = Model.AccessLevel.Internal;
            }

            AbstractEnum abstractModifier = Model.AbstractEnum.NotAbstract;

            if (method.IsAbstract)
            {
                abstractModifier = Model.AbstractEnum.Abstract;
            }

            StaticEnum staticModifier = Model.StaticEnum.NonStatic;

            if (method.IsStatic)
            {
                staticModifier = Model.StaticEnum.Static;
            }

            VirtualEnum virtualModifier = Model.VirtualEnum.NonVirtual;

            return(new Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum>(accessModifier, abstractModifier, staticModifier, virtualModifier));
        }
Ejemplo n.º 4
0
 public TupleFour(AccessLevel accessLevel, AbstractEnum abstractEnum, StaticEnum staticEnum, VirtualEnum virtualEnum)
 {
     this.accessLevel  = accessLevel;
     this.abstractEnum = abstractEnum;
     this.staticEnum   = staticEnum;
     this.virtualEnum  = virtualEnum;
 }
Ejemplo n.º 5
0
 internal static string Stringify(this AbstractEnum sealedEnum)
 {
     if (sealedEnum == AbstractEnum.Abstract)
     {
         return("Abstract ");
     }
     return("");
 }
Ejemplo n.º 6
0
    public void Should_return_derived_type()
    {
        EnumWithDerivedType.Get(2).Should().Be(EnumWithDerivedType.ItemOfDerivedType);

        AbstractEnum.Get(1).Should().Be(AbstractEnum.Item);

        ExtensibleTestEnum.Get("DerivedItem").Should().Be(ExtensibleTestEnum.DerivedItem);
        ExtendedTestEnum.Get("DerivedItem").Should().Be(ExtendedTestEnum.DerivedItem);
        DifferentAssemblyExtendedTestEnum.Get("DerivedItem").Should().Be(DifferentAssemblyExtendedTestEnum.DerivedItem);
    }
        public static AbstractEnumBaseDTO ToBaseDTO(this AbstractEnum enumType)
        {
            switch (enumType)
            {
            case AbstractEnum.Abstract:
                return(AbstractEnumBaseDTO.Abstract);

            case AbstractEnum.NotAbstract:
                return(AbstractEnumBaseDTO.NotAbstract);
            }
            throw new Exception();
        }
Ejemplo n.º 8
0
        public static Tuple <AccessLevel, SealedEnum, AbstractEnum> MapToObject(this Tuple <AccessLevelBaseDTO, SealedEnumBaseDTO, AbstractEnumBaseDTO> tuple)
        {
            if (tuple == null)
            {
                return(null);
            }
            AccessLevel  accessLevelBase  = tuple.Item1.MapToObject();
            SealedEnum   sealedEnumBase   = tuple.Item2.MapToObject();
            AbstractEnum abstractEnumBase = tuple.Item3.MapToObject();

            return(new Tuple <AccessLevel, SealedEnum, AbstractEnum>(accessLevelBase, sealedEnumBase, abstractEnumBase));
        }
Ejemplo n.º 9
0
        public static Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum> MapToObject(this Tuple <AccessLevelBaseDTO, AbstractEnumBaseDTO, StaticEnumBaseDTO, VirtualEnumBaseDTO> tuple)
        {
            if (tuple == null)
            {
                return(null);
            }
            AccessLevel  accessLevelBase  = tuple.Item1.MapToObject();
            AbstractEnum abstractEnumBase = tuple.Item2.MapToObject();
            StaticEnum   staticEnumBase   = tuple.Item3.MapToObject();
            VirtualEnum  virtualEnumBase  = tuple.Item4.MapToObject();

            return(new Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum>(accessLevelBase, abstractEnumBase, staticEnumBase, virtualEnumBase));
        }
Ejemplo n.º 10
0
        internal static Enums.AbstractEnum ToLogicEnum(this AbstractEnum baseEnum)
        {
            switch (baseEnum)
            {
            case AbstractEnum.Abstract:
                return(Enums.AbstractEnum.Abstract);

            case AbstractEnum.NotAbstract:
                return(Enums.AbstractEnum.NotAbstract);

            default:
                throw new Exception();
            }
        }
Ejemplo n.º 11
0
        private void InsertRedundantData(DbAssemblyMetadata loadedRoot)
        {
            foreach (DbNamespaceMetadata _namespace in loadedRoot.EFNamespaces)
            {
                foreach (DbTypeMetadata type in _namespace.EFTypes)
                {
                    type.NamespaceName = _namespace.Name;
                    AbstractEnum isAbstract = AbstractEnum.NotAbstract;
                    if (type.IsAbstract)
                    {
                        isAbstract = AbstractEnum.Abstract;
                    }
                    SealedEnum isSealed = SealedEnum.NotSealed;
                    if (type.IsSealed)
                    {
                        isSealed = SealedEnum.Sealed;
                    }

                    type.Modifiers = new Tuple <AccessLevelEnum, SealedEnum, AbstractEnum>(
                        type.AccessLevel, isSealed, isAbstract);
                    foreach (DbMethodMetadata method in type.EFMethodsAndConstructors)
                    {
                        isAbstract = AbstractEnum.NotAbstract;
                        if (method.IsAbstract)
                        {
                            isAbstract = AbstractEnum.Abstract;
                        }
                        StaticEnum isStatic = StaticEnum.NotStatic;
                        if (method.IsStatic)
                        {
                            isStatic = StaticEnum.Static;
                        }
                        VirtualEnum isVirtual = VirtualEnum.NotVirtual;
                        if (method.IsVirtual)
                        {
                            isVirtual = VirtualEnum.Virtual;
                        }

                        method.Modifiers = new Tuple <AccessLevelEnum, AbstractEnum, StaticEnum, VirtualEnum>(
                            method.AccessLevel, isAbstract, isStatic, isVirtual);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        static TypeModifiers EmitModifiers(Type type)
        {
            AccessLevel _access = AccessLevel.Private;

            if (type.IsPublic)
            {
                _access = AccessLevel.Public;
            }
            else if (type.IsNestedPublic)
            {
                _access = AccessLevel.Public;
            }
            else if (type.IsNestedFamily)
            {
                _access = AccessLevel.Protected;
            }
            else if (type.IsNestedFamANDAssem)
            {
                _access = AccessLevel.ProtectedInternal;
            }
            SealedEnum _sealed = SealedEnum.NotSealed;

            if (type.IsSealed)
            {
                _sealed = SealedEnum.Sealed;
            }
            AbstractEnum _abstract = AbstractEnum.NotAbstract;
            StaticEnum   _static   = StaticEnum.NotStatic;

            if (type.IsAbstract)
            {
                _abstract = AbstractEnum.Abstract;
                _static   = StaticEnum.Static;
            }

            return(new TypeModifiers()
            {
                AbstractEnum = _abstract,
                StaticEnum = _static,
                SealedEnum = _sealed,
                AccessLevel = _access
            });
        }
Ejemplo n.º 13
0
        private static MethodModifiers EmitModifiers(MethodBase method)
        {
            AccessLevel _access = AccessLevel.Private;

            if (method.IsPublic)
            {
                _access = AccessLevel.Public;
            }
            else if (method.IsFamily)
            {
                _access = AccessLevel.Protected;
            }
            else if (method.IsFamilyAndAssembly)
            {
                _access = AccessLevel.ProtectedInternal;
            }
            AbstractEnum _abstract = AbstractEnum.NotAbstract;

            if (method.IsAbstract)
            {
                _abstract = AbstractEnum.Abstract;
            }
            StaticEnum _static = StaticEnum.NotStatic;

            if (method.IsStatic)
            {
                _static = StaticEnum.Static;
            }
            VirtualEnum _virtual = VirtualEnum.NotVirtual;

            if (method.IsVirtual)
            {
                _virtual = VirtualEnum.Virtual;
            }

            return(new MethodModifiers()
            {
                AbstractEnum = _abstract,
                StaticEnum = _static,
                VirtualEnum = _virtual,
                AccessLevel = _access
            });
        }
Ejemplo n.º 14
0
        private static MethodModifiers EmitModifiers(MethodBase method)
        {
            AccessLevel access = method.IsPublic ? AccessLevel.Public :
                                 method.IsFamily ? AccessLevel.Protected :
                                 method.IsAssembly ? AccessLevel.Internal : AccessLevel.Private;

            AbstractEnum _abstract = method.IsAbstract ? AbstractEnum.Abstract : AbstractEnum.NotAbstract;

            StaticEnum _static = method.IsStatic ? StaticEnum.Static : StaticEnum.NotStatic;

            VirtualEnum _virtual = method.IsVirtual ? VirtualEnum.Virtual : VirtualEnum.NotVirtual;

            return(new MethodModifiers()
            {
                AbstractEnum = _abstract,
                StaticEnum = _static,
                VirtualEnum = _virtual,
                AccessLevel = access
            });
        }
Ejemplo n.º 15
0
        private Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum> EmitModifiers(MethodBase method)
        {
            AccessLevel access = AccessLevel.IsPrivate;

            if (method.IsPublic)
            {
                access = AccessLevel.IsPublic;
            }
            else if (method.IsFamily)
            {
                access = AccessLevel.IsProtected;
            }
            else if (method.IsFamilyAndAssembly)
            {
                access = AccessLevel.IsProtectedInternal;
            }

            AbstractEnum isAbstract = AbstractEnum.NotAbstract;

            if (method.IsAbstract)
            {
                isAbstract = AbstractEnum.Abstract;
            }

            StaticEnum isStatic = StaticEnum.NotStatic;

            if (method.IsStatic)
            {
                isStatic = StaticEnum.Static;
            }

            VirtualEnum isVirtual = VirtualEnum.NotVirtual;

            if (method.IsVirtual)
            {
                isVirtual = VirtualEnum.Virtual;
            }

            return(new Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum>(access, isAbstract, isStatic, isVirtual));
        }
Ejemplo n.º 16
0
        private Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum> EmitModifiers(MethodBase method)
        {
            AccessLevel _access = AccessLevel.Private;

            if (method.IsPublic)
            {
                _access = AccessLevel.Public;
            }
            else if (method.IsFamily)
            {
                _access = AccessLevel.Protected;
            }
            else if (method.IsFamilyAndAssembly)
            {
                _access = AccessLevel.Internal;
            }
            AbstractEnum _abstract = AbstractEnum.NotAbstract;

            if (method.IsAbstract)
            {
                _abstract = AbstractEnum.Abstract;
            }
            else if (method.IsFinal)
            {
                _abstract = AbstractEnum.Sealed;
            }
            StaticEnum _static = StaticEnum.NotStatic;

            if (method.IsStatic)
            {
                _static = StaticEnum.Static;
            }
            VirtualEnum _virtual = VirtualEnum.NotVirtual;

            if (method.IsVirtual)
            {
                _virtual = VirtualEnum.Virtual;
            }
            return(new Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum>(_access, _abstract, _static, _virtual));
        }
Ejemplo n.º 17
0
        private Tuple <AccessLevel, SealedEnum, AbstractEnum> EmitModifiers(Type type)
        {
            AccessLevel accessLevel = AccessLevel.IsPrivate;

            // check if not default
            if (type.IsPublic)
            {
                accessLevel = AccessLevel.IsPublic;
            }
            else if (type.IsNestedPublic)
            {
                accessLevel = AccessLevel.IsPublic;
            }
            else if (type.IsNestedFamily)
            {
                accessLevel = AccessLevel.IsProtected;
            }
            else if (type.IsNestedFamANDAssem)
            {
                accessLevel = AccessLevel.IsProtectedInternal;
            }

            SealedEnum sealedEnum = SealedEnum.NotSealed;

            if (type.IsSealed)
            {
                sealedEnum = SealedEnum.Sealed;
            }

            AbstractEnum abstractEnum = AbstractEnum.NotAbstract;

            if (type.IsAbstract)
            {
                abstractEnum = AbstractEnum.Abstract;
            }

            return(new Tuple <AccessLevel, SealedEnum, AbstractEnum>(accessLevel, sealedEnum, abstractEnum));
        }
Ejemplo n.º 18
0
        static Tuple <AccessLevelEnum, SealedEnum, AbstractEnum> EmitModifiers(Type type)
        {
            AccessLevelEnum _access = AccessLevelEnum.IsPrivate;

            if (type.IsPublic)
            {
                _access = AccessLevelEnum.IsPublic;
            }
            else if (type.IsNestedPublic)
            {
                _access = AccessLevelEnum.IsPublic;
            }
            else if (type.IsNestedFamily)
            {
                _access = AccessLevelEnum.IsProtected;
            }
            else if (type.IsNestedFamANDAssem)
            {
                _access = AccessLevelEnum.IsProtectedInternal;
            }

            SealedEnum _sealed = SealedEnum.NotSealed;

            if (type.IsSealed)
            {
                _sealed = SealedEnum.Sealed;
            }

            AbstractEnum _abstract = AbstractEnum.NotAbstract;

            if (type.IsAbstract)
            {
                _abstract = AbstractEnum.Abstract;
            }

            return(new Tuple <AccessLevelEnum, SealedEnum, AbstractEnum>(_access, _sealed, _abstract));
        }
    public void Should_throw_if_item_is_invalid()
    {
        TestEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(TestEnum)}\" with identifier \"invalid\" is not valid.");

        StructStringEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructStringEnum)}\" with identifier \"invalid\" is not valid.");

        AbstractEnum.Get(42).Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(AbstractEnum)}\" with identifier \"42\" is not valid.");

        StructIntegerEnum.Get(42).Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructIntegerEnum)}\" with identifier \"42\" is not valid.");

        // we cannot prevent construction of a struct
        new StructIntegerEnumWithZero().Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(StructIntegerEnumWithZero)}\" with identifier \"0\" is not valid.");

        ExtensibleTestValidatableEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(ExtensibleTestValidatableEnum)}\" with identifier \"invalid\" is not valid.");

        ExtendedTestValidatableEnum.Get("invalid").Invoking(e => e.EnsureValid())
        .Should().Throw <InvalidOperationException>().WithMessage($"The current enumeration item of type \"{nameof(ExtendedTestValidatableEnum)}\" with identifier \"invalid\" is not valid.");
    }
Ejemplo n.º 20
0
        private static TypeModifiers EmitModifiers(Type type)
        {
            AccessLevel _access = type.IsPublic || type.IsNestedPublic ? AccessLevel.Public :
                                  type.IsNestedFamily ? AccessLevel.Protected :
                                  type.IsNestedPrivate ? AccessLevel.Private :
                                  AccessLevel.Internal;
            StaticEnum   _static   = type.IsSealed && type.IsAbstract ? StaticEnum.Static : StaticEnum.NotStatic;
            SealedEnum   _sealed   = SealedEnum.NotSealed;
            AbstractEnum _abstract = AbstractEnum.NotAbstract;

            if (_static == StaticEnum.NotStatic)
            {
                _sealed   = type.IsSealed ? SealedEnum.Sealed : SealedEnum.NotSealed;
                _abstract = type.IsAbstract ? AbstractEnum.Abstract : AbstractEnum.NotAbstract;
            }

            return(new TypeModifiers()
            {
                AbstractEnum = _abstract,
                AccessLevel = _access,
                SealedEnum = _sealed,
                StaticEnum = _static
            });
        }
Ejemplo n.º 21
0
 public static string AbstractToString(AbstractEnum abstractEnum)
 {
     return(abstractEnum == AbstractEnum.Abstract ? "abstract" : "");
 }