예제 #1
0
 internal AccessorWithMonoCecil(AssemblyWithMonoCecil assembly, MethodDefinition method)
 {
     MethodDefinition = method;
     attributes       = new Lazy <Attributes>(() => new Attributes(assembly, method, typeof(CompilerGeneratedAttribute)));
     body             = new Lazy <ILMethodBodyWithMonoCecilCil>(
         () => method.IsDefined(assembly, typeof(CompilerGeneratedAttribute)) ? null : new ILMethodBodyWithMonoCecilCil(method));
 }
예제 #2
0
 internal ParameterWithMonoCecil(AssemblyWithMonoCecil assembly, ParameterDefinition parameter, MemberReference member)
 {
     this.assembly  = assembly;
     this.parameter = parameter;
     attributes     = new Lazy <Attributes>(() => new Attributes(assembly, parameter, excludedAttributeTypes));
     parameterType  = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, parameter.ParameterType, member);
 }
 internal DestructorWithMonoCecil(AssemblyWithMonoCecil assembly, IClassType declaringType, MethodDefinition method)
 {
     this.declaringType = declaringType;
     this.method        = method;
     attributes         = new Lazy <Attributes>(() => new Attributes(assembly, method));
     body = new Lazy <ILMethodBodyWithMonoCecilCil>(() => new ILMethodBodyWithMonoCecilCil(method));
 }
        internal InterfaceEventWithMonoCecil(IInterfaceTypeWithMonoCecil declaringType, EventDefinition @event)
        {
            this.@event        = @event;
            this.declaringType = declaringType;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes = new Lazy <Attributes>(() => new Attributes(assembly, @event));
            eventType  = new DelegateReferenceWithMonoCecil(assembly, @event.EventType);
        }
        private static ITypeReferenceWithMonoCecil CreateBuiltInReference(AssemblyWithMonoCecil assembly, TypeReference type)
        {
            TypeSystem  typeSystem  = assembly.Assembly.MainModule.TypeSystem;
            BuiltInType?builtInType =
                (from entry in builtInTypes
                 let typeReference = entry.Key(typeSystem)
                                     where typeReference == type
                                     select entry.Value).FirstOrDefault();

            return(builtInType.HasValue ? new BuiltInTypeReferenceWithMonoCecil(builtInType.Value, type) : null);
        }
        internal ConversionOperatorWithMonoCecil(ITypeWithMonoCecil declaringType, MethodDefinition method)
        {
            this.declaringType = declaringType;
            this.method        = method;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes       = new Lazy <Attributes>(() => new Attributes(assembly, method));
            parameter        = new OperatorParameterWithMonoCecil(new ParameterWithMonoCecil(assembly, method.Parameters[0], method));
            returnType       = TypeReferenceWithMonoCecilFactory.CreateReference(declaringType.Assembly, method.ReturnType, method);
            returnAttributes = new Lazy <Attributes>(() => new Attributes(assembly, method.MethodReturnType));
            body             = new Lazy <ILMethodBodyWithMonoCecilCil>(() => new ILMethodBodyWithMonoCecilCil(method));
        }
예제 #7
0
        internal OperatorOverloadWithMonoCecil(ITypeWithMonoCecil declaringType, MethodDefinition method)
        {
            this.declaringType = declaringType;
            this.method        = method;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes = new Lazy <Attributes>(() => new Attributes(assembly, method));
            returnType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, method.ReturnType, method);
            parameters = new Lazy <Parameters <OperatorParameterWithMonoCecil> >(
                () => new Parameters <OperatorParameterWithMonoCecil>(assembly, method, parameter => new OperatorParameterWithMonoCecil(parameter)));
            body = new Lazy <ILMethodBodyWithMonoCecilCil>(() => new ILMethodBodyWithMonoCecilCil(method));
        }
        public static ITypeReferenceWithMonoCecil CreateReference(AssemblyWithMonoCecil assembly, TypeReference type, MemberReference member = null, bool ignoreNestedType = false)
        {
            if (type.IsByReference)
            {
                type = type.GetElementType();
            }

            if (type.IsArray)
            {
                return(new ArrayTypeReferenceWithMonoCecil(assembly, type, member));
            }

            if (type.DeclaringType != null && !ignoreNestedType && (member == null || !IsParentType(type, member.DeclaringType)))
            {
                return(new NestedTypeReferenceWithMonoCecil(assembly, type));
            }

            if (type.IsGenericParameter)
            {
                return(new GenericParameterReferenceWithMonoCecil(type));
            }

            ITypeReferenceWithMonoCecil typeReference = CreateBuiltInReference(assembly, type);

            if (typeReference != null)
            {
                return(typeReference);
            }

            switch (type.Resolve().TypeClassification())
            {
            case TypeClassification.AbstractClass:
            case TypeClassification.Class:
            case TypeClassification.SealedClass:
            case TypeClassification.StaticClass:
                return(new ClassReferenceWithMonoCecil(assembly, type));

            case TypeClassification.Delegate:
                return(new DelegateReferenceWithMonoCecil(assembly, type));

            case TypeClassification.Enum:
                return(new EnumReferenceWithMonoCecil(type));

            case TypeClassification.Interface:
                return(new InterfaceReferenceWithMonoCecil(assembly, type));

            case TypeClassification.Struct:
                return(new StructReferenceWithMonoCecil(assembly, type));

            default:
                return(new UnspecifiedTypeReferenceWithMonoCecil(assembly, type));
            }
        }
        internal InterfaceMethodWithMonoCecil(IInterfaceTypeWithMonoCecil declaringType, MethodDefinition method)
        {
            this.method        = method;
            this.declaringType = declaringType;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes        = new Lazy <Attributes>(() => new Attributes(assembly, method));
            returnAttributes  = new Lazy <Attributes>(() => new Attributes(assembly, method.MethodReturnType));
            genericParameters = new Lazy <GenericParameterDeclarations>(() => new GenericParameterDeclarations(assembly, method));
            returnType        = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, method.ReturnType, method);
            parameters        = new Lazy <Parameters <MethodParameterWithMonoCecil> >(
                () => new Parameters <MethodParameterWithMonoCecil>(assembly, method, parameter => new MethodParameterWithMonoCecil(parameter)));
        }
예제 #10
0
        internal InterfacePropertyWithMonoCecil(IInterfaceTypeWithMonoCecil declaringType, PropertyDefinition property)
        {
            this.property      = property;
            this.declaringType = declaringType;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes   = new Lazy <Attributes>(() => new Attributes(assembly, property));
            propertyType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, property.PropertyType, property);
            if (property.GetMethod != null)
            {
                getAccessor = new InterfaceAccessorWithMonoCecil(assembly, property.GetMethod);
            }

            if (property.SetMethod != null)
            {
                setAccessor = new InterfaceAccessorWithMonoCecil(assembly, property.SetMethod);
            }
        }
        internal InterfaceIndexerWithMonoCecil(IInterfaceTypeWithMonoCecil declaringType, PropertyDefinition indexer)
        {
            this.indexer       = indexer;
            this.declaringType = declaringType;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes  = new Lazy <Attributes>(() => new Attributes(assembly, indexer));
            indexerType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, indexer.PropertyType, indexer);
            parameters  = new Lazy <Parameters <IndexerParameterWithMonoCecil> >(
                () => new Parameters <IndexerParameterWithMonoCecil>(assembly, indexer, parameter => new IndexerParameterWithMonoCecil(parameter)));
            if (indexer.GetMethod != null)
            {
                getAccessor = new InterfaceAccessorWithMonoCecil(assembly, indexer.GetMethod);
            }

            if (indexer.SetMethod != null)
            {
                setAccessor = new InterfaceAccessorWithMonoCecil(assembly, indexer.SetMethod);
            }
        }
        internal GenericParameterDeclarationWithMonoCecil(AssemblyWithMonoCecil assembly, GenericParameter type)
        {
            this.type      = type;
            attributes     = new Lazy <Attributes>(() => new Attributes(assembly, type));
            typeConstraint = GetTypeConstraint(type);
            direction      = GetDirection(type);
            hasEmptyConstructorConstraint = type.HasDefaultConstructorConstraint && !type.HasNotNullableValueTypeConstraint;
            genericParameterConstraints   = new List <GenericParameterReferenceWithMonoCecil>();
            interfaceConstraints          = new List <InterfaceReferenceWithMonoCecil>();
            foreach (TypeReference constraintType in type.Constraints)
            {
                TypeDefinition constraintTypeDefinition = constraintType.Resolve();
                if (constraintType.IsGenericParameter)
                {
                    genericParameterConstraints.Add(new GenericParameterReferenceWithMonoCecil(constraintType));
                }
                else if (constraintTypeDefinition.IsInterface)
                {
                    interfaceConstraints.Add(new InterfaceReferenceWithMonoCecil(assembly, constraintType));
                }
                else if (constraintTypeDefinition.IsClass)
                {
                    if (baseClassConstraint != null)
                    {
                        throw new InvalidOperationException("GenericParameterDeclaration appears to have 2 base classes.");
                    }

                    if (constraintType.FullName != "System.ValueType")
                    {
                        baseClassConstraint = new ClassReferenceWithMonoCecil(assembly, constraintType);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Unknown constraint type.");
                }
            }
        }
예제 #13
0
 internal NamedAttributeValueWithMonoCecil(AssemblyWithMonoCecil assembly, CustomAttributeNamedArgument attributeValue)
 {
     this.attributeValue = attributeValue;
     value = ConstantExpressionFactory.CreateExpression(assembly, attributeValue.Argument.Value);
 }
 internal InterfaceAccessorWithMonoCecil(AssemblyWithMonoCecil assembly, MethodDefinition method)
 {
     attributes = new Lazy <Attributes>(() => new Attributes(assembly, method));
 }
 internal NestedTypeReferenceWithMonoCecil(AssemblyWithMonoCecil assembly, TypeReference nestedType)
 {
     type            = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, nestedType.DeclaringType);
     this.nestedType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, nestedType, ignoreNestedType: true);
 }
예제 #16
0
 internal ArrayTypeReferenceWithMonoCecil(AssemblyWithMonoCecil assembly, TypeReference type, MemberReference member)
 {
     this.type = type;
     //dimensions = type..GetArrayRank();
     elementType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, type.GetElementType(), member);
 }
 internal StructReferenceWithMonoCecil(AssemblyWithMonoCecil assembly, TypeReference type)
 {
     this.type         = type;
     genericParameters = new Lazy <GenericParameters>(() => new GenericParameters(assembly, type));
 }
 internal AttributeWithMonoCecil(AssemblyWithMonoCecil assembly, CustomAttribute attribute)
 {
     this.attribute = new InternalAttributeWithMonoCecil(assembly, attribute);
 }