Exemple #1
0
        public MutableType(
            MutableType declaringType,
            Type baseType,
            string name,
            string @namespace,
            TypeAttributes attributes,
            IInterfaceMappingComputer interfaceMappingComputer,
            IMutableMemberFactory mutableMemberFactory)
            : base(name, @namespace, attributes, null, EmptyTypes)
        {
            // Base type may be null (for interfaces).
            // Declaring type may be null.
            ArgumentUtility.CheckNotNull("interfaceMappingComputer", interfaceMappingComputer);
            ArgumentUtility.CheckNotNull("mutableMemberFactory", mutableMemberFactory);

            SetDeclaringType(declaringType);
            SetBaseType(baseType);

            _interfaceMappingComputer = interfaceMappingComputer;
            _mutableMemberFactory     = mutableMemberFactory;

            _allMethods = GetAllBaseMethods(baseType);

            _allMethodsIndex = new Dictionary <MethodInfo, int>();
            for (int index = 0; index < _allMethods.Count; index++)
            {
                _allMethodsIndex.Add(MethodBaseDefinitionCache.GetBaseDefinition(_allMethods[index]), index);
            }

            _baseDefinitionsOfAbstractMethods = GetBaseDefinitionsOfAbstractMethods(baseType);
        }
Exemple #2
0
 public MutableEventInfo(
     MutableType declaringType,
     string name,
     EventAttributes attributes,
     MutableMethodInfo addMethod,
     MutableMethodInfo removeMethod,
     MutableMethodInfo raiseMethod)
     : base(declaringType, name, attributes, addMethod, removeMethod, raiseMethod)
 {
 }
Exemple #3
0
        public static void AddTypeInitialization(this MutableType declaringType, Expression typeInitialization)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNull("typeInitialization", typeInitialization);

            if (declaringType.MutableTypeInitializer == null)
            {
                declaringType.AddTypeInitializer(ctx => typeInitialization);
            }
            else
            {
                declaringType.MutableTypeInitializer.SetBody(ctx => Expression.Block(ctx.PreviousBody, typeInitialization));
            }
        }
Exemple #4
0
        public MutableConstructorInfo(
            MutableType declaringType, MethodAttributes attributes, IEnumerable <ParameterDeclaration> parameters, Expression body)
            : base(declaringType, attributes)
        {
            ArgumentUtility.CheckNotNull("parameters", parameters);
            ArgumentUtility.CheckNotNull("body", body);
            Assertion.IsTrue(body.Type == typeof(void));

            var paras = parameters.ToList();

            _parameters           = paras.Select((p, i) => new MutableParameterInfo(this, i, p.Name, p.Type, p.Attributes)).ToList().AsReadOnly();
            _parameterExpressions = paras.Select(p => p.Expression).ToList().AsReadOnly();
            _body = body;
        }
Exemple #5
0
        public static MutableMethodInfo AddMethod(
            this MutableType declaringType,
            string name,
            MethodAttributes attributes = MethodAttributes.Public,
            Type returnType             = null,
            IEnumerable <ParameterDeclaration> parameters             = null,
            Func <MethodBodyCreationContext, Expression> bodyProvider = null)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            returnType = returnType ?? typeof(void);
            parameters = parameters ?? ParameterDeclaration.None;
            // Body provider may be null (for abstract methods).

            return(declaringType.AddMethod(name, attributes, GenericParameterDeclaration.None, ctx => returnType, ctx => parameters, bodyProvider));
        }
Exemple #6
0
        public static MutableMethodInfo AddAbstractMethod(
            this MutableType declaringType,
            string name,
            MethodAttributes attributes = MethodAttributes.Public,
            Type returnType             = null,
            IEnumerable <ParameterDeclaration> parameters = null)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            returnType = returnType ?? typeof(void);
            parameters = parameters ?? ParameterDeclaration.None;

            var abstractAttributes = attributes.Set(MethodAttributes.Abstract | MethodAttributes.Virtual);

            return(declaringType.AddMethod(name, abstractAttributes, returnType, parameters, bodyProvider: null));
        }
Exemple #7
0
        public static MutableMethodInfo AddMethod(
            this MutableType declaringType,
            string name,
            MethodAttributes attributes,
            MethodDeclaration methodDeclaration,
            Func <MethodBodyCreationContext, Expression> bodyProvider)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("methodDeclaration", methodDeclaration);
            // Body provider may be null (for abstract methods).

            var md = methodDeclaration;

            return(declaringType.AddMethod(name, attributes, md.GenericParameters, md.ReturnTypeProvider, md.ParameterProvider, bodyProvider));
        }
Exemple #8
0
        public MutablePropertyInfo(
            MutableType declaringType, string name, PropertyAttributes attributes, MutableMethodInfo getMethod, MutableMethodInfo setMethod)
            : base(declaringType, name, attributes, getMethod, setMethod)
        {
            IEnumerable <ParameterInfo> indexParameters;

            if (getMethod != null)
            {
                indexParameters = getMethod.GetParameters();
            }
            else
            {
                var setMethodParameters = setMethod.GetParameters();
                indexParameters = setMethodParameters.Take(setMethodParameters.Length - 1);
            }

            _indexParameters = indexParameters.Select(p => new PropertyParameterInfoWrapper(this, p)).ToList().AsReadOnly();
        }
Exemple #9
0
        public MutableMethodInfo(
            MutableType declaringType,
            string name,
            MethodAttributes attributes,
            ICollection <MutableGenericParameter> genericParameters,
            Type returnType,
            IEnumerable <ParameterDeclaration> parameters,
            MethodInfo baseMethod,
            Expression body)
            : base(
                declaringType,
                name,
                attributes,
                null,
                genericParameters.Cast <Type>())
        {
            ArgumentUtility.CheckNotNull("returnType", returnType);
            ArgumentUtility.CheckNotNull("parameters", parameters);
            Assertion.IsTrue(baseMethod == null || (baseMethod.IsVirtual && attributes.IsSet(MethodAttributes.Virtual)));
            Assertion.IsTrue(body != null || attributes.IsSet(MethodAttributes.Abstract));
            Assertion.IsTrue(body == null || returnType.IsTypePipeAssignableFrom(body.Type));

            foreach (var genericParameter in genericParameters)
            {
                genericParameter.InitializeDeclaringMember(this);
            }

            var paras = parameters.ToList();

            _genericParameters    = genericParameters.ToList().AsReadOnly();
            _returnParameter      = new MutableParameterInfo(this, -1, null, returnType, ParameterAttributes.None);
            _parameters           = paras.Select((p, i) => new MutableParameterInfo(this, i, p.Name, p.Type, p.Attributes)).ToList().AsReadOnly();
            _parameterExpressions = paras.Select(p => p.Expression).ToList().AsReadOnly();
            _baseMethod           = baseMethod;
            _body = body;
        }
 public MutableFieldInfo(MutableType declaringType, string name, Type type, FieldAttributes attributes)
     : base(declaringType, name, type, attributes)
 {
 }