Exemplo n.º 1
0
        protected void SetBaseType(Type baseType)
        {
            Assertion.IsTrue(baseType != null || _attributes.IsSet(TypeAttributes.Interface));
            Assertion.IsTrue(baseType == null || _attributes.IsSet(TypeAttributes.ClassSemanticsMask, TypeAttributes.Class) || baseType.IsClass);

            _baseType = baseType;
        }
Exemplo n.º 2
0
        public MutableType CreateType(string name, string @namespace, TypeAttributes attributes, Type baseType, MutableType declaringType)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            // Name space may be null.
            // Base type may be null (for interfaces).
            // Declaring type may be null.

            var isInterface = attributes.IsSet(TypeAttributes.Interface);

            if (!isInterface && baseType == null)
            {
                throw new ArgumentException("Base type cannot be null.", "baseType");
            }
            if (isInterface && baseType != null)
            {
                throw new ArgumentException(string.Format("Base type must be null for interfaces. Type: '{0}'", baseType.FullName), "baseType");
            }

            if (baseType != null && !IsValidBaseType(baseType))
            {
                throw new ArgumentException(
                          string.Format(
                              "Base type must not be sealed, an interface, an array, a byref type, a pointer, a generic parameter, "
                              + "contain generic parameters and must have an accessible constructor. Type: '{0}'",
                              baseType.FullName),
                          "baseType");
            }

            return(CreateMutableType(name, @namespace, attributes, baseType, declaringType));
        }
Exemplo n.º 3
0
        public static MutableType CreateInterface(
            string name                                        = "MyMutableInterface",
            string @namespace                                  = "MyNamespace",
            TypeAttributes attributes                          = TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract,
            MutableType declaringType                          = null,
            IMemberSelector memberSelector                     = null,
            IRelatedMethodFinder relatedMethodFinder           = null,
            IInterfaceMappingComputer interfaceMappingComputer = null,
            IMutableMemberFactory mutableMemberFactory         = null)
        {
            // Declaring type stays null.

            memberSelector           = memberSelector ?? new MemberSelector(new BindingFlagsEvaluator());
            relatedMethodFinder      = relatedMethodFinder ?? new RelatedMethodFinder();
            interfaceMappingComputer = interfaceMappingComputer ?? new InterfaceMappingComputer();
            mutableMemberFactory     = mutableMemberFactory ?? new MutableMemberFactory(relatedMethodFinder);
            Assertion.IsTrue(attributes.IsSet(TypeAttributes.Interface | TypeAttributes.Abstract));

            var mutableType = new MutableType(declaringType, null, name, @namespace, attributes, interfaceMappingComputer, mutableMemberFactory);

            mutableType.SetMemberSelector(memberSelector);

            return(mutableType);
        }
Exemplo n.º 4
0
        public bool HasRightVisibility(TypeAttributes typeAttributes, BindingFlags bindingFlags)
        {
            var flag = typeAttributes.IsSet(TypeAttributes.VisibilityMask, TypeAttributes.NestedPublic) ? BindingFlags.Public : BindingFlags.NonPublic;

            return(IsFlagDefined(bindingFlags, flag));
        }