public static IConstantExpressionWithMonoCecil CreateExpression(AssemblyWithMonoCecil assembly, object value)
        {
            if (value == null)
            {
                return(new NullExpressionWithMonoCecil());
            }

            TypeDefinition type = value as TypeDefinition;

            if (type != null)
            {
                return(new TypeofExpressionWithMonoCecil(TypeReferenceWithMonoCecilFactory.CreateReference(assembly, type)));
            }

            switch (Type.GetTypeCode(value.GetType()))
            {
            case TypeCode.Double:
                return(new DoubleConstantExpressionWithMonoCecil((double)value));

            case TypeCode.Int32:
                return(new IntegerConstantExpressionWithMonoCecil((int)value));

            case TypeCode.String:
                return(new StringConstantExpressionWithMonoCecil((string)value));

            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        internal ConstantGroupWithMonoCecil(ITypeWithMonoCecil declaringType, FieldDefinition field)
        {
            this.declaringType = declaringType;
            this.field         = field;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes    = new Lazy <Attributes>(() => new Attributes(assembly, field));
            fieldType     = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, field.FieldType, field);
            ConstantValue = ConstantExpressionFactory.CreateExpression(assembly, field.Constant);
        }
Пример #3
0
        internal MethodWithMonoCecil(ITypeWithMonoCecil declaringType, MethodDefinition method)
        {
            this.declaringType = declaringType;
            this.method        = method;
            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)));
            body = new Lazy <ILMethodBodyWithMonoCecilCil>(() => new ILMethodBodyWithMonoCecilCil(method));
        }
Пример #4
0
        internal FieldGroupWithMonoCecil(ITypeWithMonoCecil declaringType, FieldDefinition field)
        {
            this.declaringType = declaringType;
            this.field         = field;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes = new Lazy <Attributes>(() => new Attributes(assembly, field));
            RequiredModifierType modifierType = field.FieldType as RequiredModifierType;

            fieldType = TypeReferenceWithMonoCecilFactory.CreateReference(
                assembly,
                modifierType == null ? field.FieldType : modifierType.ElementType,
                field);
        }
Пример #5
0
        internal NestedDelegateWithMonoCecil(ITypeWithMonoCecil declaringType, TypeDefinition type)
        {
            this.declaringType = declaringType;
            this.type          = type;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes        = new Lazy <Attributes>(() => new Attributes(assembly, type));
            genericParameters = new Lazy <GenericParameterDeclarations>(() => new GenericParameterDeclarations(assembly, type));
            MethodDefinition invokeMethod = type.Methods.First(method => method.Name == "Invoke");

            returnType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, invokeMethod.ReturnType, invokeMethod);
            parameters = new Lazy <Parameters <DelegateParameterWithMonoCecil> >(
                () => new Parameters <DelegateParameterWithMonoCecil>(assembly, invokeMethod, parameter => new DelegateParameterWithMonoCecil(parameter)));
        }
Пример #6
0
        public GenericParameters(AssemblyWithMonoCecil assembly, TypeReference type)
        {
            GenericInstanceType genericType = type as GenericInstanceType;

            if (genericType == null)
            {
                GenericParametersWithMonoCecil = new List <ITypeReferenceWithMonoCecil>();
            }
            else
            {
                GenericParametersWithMonoCecil = genericType.GenericArguments
                                                 .Select(parameter => TypeReferenceWithMonoCecilFactory.CreateReference(assembly, parameter))
                                                 .ToList();
            }
        }
        internal PropertyWithMonoCecil(ITypeWithMonoCecil declaringType, PropertyDefinition property)
        {
            this.declaringType = declaringType;
            this.property      = property;
            attributes         = new Lazy <Attributes>(() => new Attributes(declaringType.Assembly, property));
            propertyType       = TypeReferenceWithMonoCecilFactory.CreateReference(declaringType.Assembly, property.PropertyType, property);
            if (property.GetMethod != null)
            {
                getAccessor = new AccessorWithMonoCecil(declaringType.Assembly, property.GetMethod);
            }

            if (property.SetMethod != null)
            {
                setAccessor = new AccessorWithMonoCecil(declaringType.Assembly, property.SetMethod);
            }
        }
        internal IndexerWithMonoCecil(ITypeWithMonoCecil declaringType, PropertyDefinition indexer)
        {
            this.declaringType = declaringType;
            this.indexer       = indexer;
            attributes         = new Lazy <Attributes>(() => new Attributes(declaringType.Assembly, indexer));
            indexerType        = TypeReferenceWithMonoCecilFactory.CreateReference(declaringType.Assembly, indexer.PropertyType, indexer);
            parameters         = new Lazy <Parameters <IndexerParameterWithMonoCecil> >(
                () => new Parameters <IndexerParameterWithMonoCecil>(declaringType.Assembly, indexer, parameter => new IndexerParameterWithMonoCecil(parameter)));
            if (indexer.GetMethod != null)
            {
                getAccessor = new AccessorWithMonoCecil(declaringType.Assembly, indexer.GetMethod);
            }

            if (indexer.SetMethod != null)
            {
                setAccessor = new AccessorWithMonoCecil(declaringType.Assembly, indexer.SetMethod);
            }
        }
Пример #9
0
 public ParameterSignature(AssemblyWithMonoCecil assembly, ParameterDefinition parameter)
 {
     modifier      = parameter.Modifier(assembly);
     name          = string.Format("parameter{0}", parameter.Index + 1);
     parameterType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, parameter.ParameterType);
 }
Пример #10
0
 public static ITypeReferenceWithMonoCecil GetReturnType(AssemblyWithMonoCecil assembly)
 {
     return(TypeReferenceWithMonoCecilFactory.CreateReference(assembly, assembly.Assembly.MainModule.TypeSystem.Object));
 }