Exemplo n.º 1
0
 public Parameters(
     AssemblyWithMonoCecil assembly,
     MethodDefinition method,
     Func <ParameterWithMonoCecil, TParameter> parameterFactory)
 {
     Initialize(assembly, method, method.Parameters, parameterFactory);
 }
        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();
            }
        }
Exemplo n.º 3
0
 public Parameters(
     AssemblyWithMonoCecil assembly,
     PropertyDefinition indexer,
     Func <ParameterWithMonoCecil, TParameter> parameterFactory)
 {
     Initialize(assembly, indexer, indexer.Parameters, parameterFactory);
 }
Exemplo n.º 4
0
 public Attributes(AssemblyWithMonoCecil assembly, ICustomAttributeProvider member, params Type[] excludedTypes)
 {
     string[] excludedTypeReferences = excludedTypes.Select(type => type.FullName).ToArray();
     AttributesWithMonoCecil = member.CustomAttributes
                               .Where(attribute => !excludedTypeReferences.Contains(attribute.Constructor.DeclaringType.FullName))
                               .Select(attribute => new AttributeWithMonoCecil(assembly, attribute))
                               .ToList();
 }
Exemplo n.º 5
0
 public HiddenMembersAnalyzer(AssemblyWithMonoCecil assembly, TypeDefinition type)
 {
     this.assembly = assembly;
     this.type     = type;
     events        = new Lazy <ISet <string> >(FindEvents);
     fields        = new Lazy <ISet <string> >(FindFields);
     indexers      = new Lazy <ISet <string> >(FindIndexers);
     methods       = new Lazy <ISet <string> >(FindMethods);
     properties    = new Lazy <ISet <string> >(FindProperties);
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 private void Initialize(
     AssemblyWithMonoCecil assembly,
     MemberReference member,
     IEnumerable <ParameterDefinition> parameters,
     Func <ParameterWithMonoCecil, TParameter> parameterFactory)
 {
     ParametersWithMonoCecil = parameters
                               .Select(parameter => parameterFactory(new ParameterWithMonoCecil(assembly, parameter, member)))
                               .ToList();
 }
 internal InternalAttributeWithMonoCecil(AssemblyWithMonoCecil assembly, CustomAttribute attribute)
 {
     attributeType        = new ClassReferenceWithMonoCecil(assembly, attribute.AttributeType);
     namedAttributeValues = attribute.Fields
                            .Concat(attribute.Properties)
                            .Select(value => new NamedAttributeValueWithMonoCecil(assembly, value))
                            .ToList();
     unnamedAttributeValues = attribute.ConstructorArguments
                              .Select(value => new UnnamedAttributeValueWithMonoCecil(assembly, value))
                              .ToList();
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
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)));
        }
Exemplo n.º 12
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();
            }
        }
        public static ParameterModifier Modifier(this ParameterDefinition parameter, AssemblyWithMonoCecil assembly)
        {
            if (parameter.IsOut)
            {
                return(ParameterModifier.Out);
            }

            if (parameter.ParameterType.IsByReference)
            {
                return(ParameterModifier.Ref);
            }

            if (parameter.IsDefined(assembly, typeof(ParamArrayAttribute)))
            {
                return(ParameterModifier.Params);
            }

            return(ParameterModifier.None);
        }
Exemplo n.º 14
0
        protected TypeWithMonoCecil(TType declaringType)
        {
            TypeDefinition = declaringType.TypeDefinition;
            AssemblyWithMonoCecil assembly = declaringType.Assembly;

            attributes            = new Lazy <Attributes>(() => new Attributes(assembly, TypeDefinition, typeof(DefaultMemberAttribute)));
            genericParameters     = new Lazy <GenericParameterDeclarations>(() => new GenericParameterDeclarations(assembly, TypeDefinition));
            implementedInterfaces = new Lazy <InterfaceReferences>(() => new InterfaceReferences(assembly, TypeDefinition));
            interfaces            = new Lazy <IReadOnlyCollection <TNestedInterface> >(() => NestedTypeCollection.NestedTypes.NestedInterfaces);
            FieldCollection       = new FieldCollection <TField, TConstant, TType>(
                () => new Fields <TField, TConstant, TType>(declaringType, this));
            EventCollection = new EventCollection <TEvent, TEventProperty, TType>(
                () => new Events <TEvent, TEventProperty, TType>(declaringType, this));
            PropertyCollection = new PropertyCollection <TProperty, TIndexer, TType>(
                () => new Properties <TProperty, TIndexer, TType>(declaringType, this));
            MethodCollection = new MethodCollection <TConstructor, TMethod, TType>(
                () => new Methods <TConstructor, TMethod, TType>(declaringType, CreateConstructor, CreateMethod));
            NestedTypeCollection = new NestedTypeCollection <TNestedAbstractClass, TNestedClass, TNestedSealedClass, TNestedStaticClass, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStruct>(
                () => new NestedTypes <TNestedAbstractClass, TNestedClass, TNestedSealedClass, TNestedStaticClass, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStruct>(declaringType, this));
        }
Exemplo n.º 15
0
 public MethodSignature(AssemblyWithMonoCecil assembly, MethodDefinition method)
 {
     this.assembly = assembly;
     name          = method.Name;
     parameters    = method.Parameters.ToArray(parameter => new ParameterSignature(assembly, parameter));
 }
 public static TypeReference GetTypeReference(this AssemblyWithMonoCecil assembly, Type type)
 {
     return assembly.Assembly.MainModule.Import(type);
 }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
0
 internal SolutionWithMonoCecil(AssemblyWithMonoCecil assembly)
 {
     this.assembly = assembly;
     projects      = new ProjectWithMonoCecil[] { new ProjectWithMonoCecil(this, assembly) };
 }
Exemplo n.º 19
0
 public InterfaceReferences(AssemblyWithMonoCecil assembly, TypeDefinition type)
 {
     InterfaceReferencesWithMonoCecil = type.Interfaces
                                        .Select(interfaceType => new InterfaceReferenceWithMonoCecil(assembly, interfaceType))
                                        .ToList();
 }
Exemplo n.º 20
0
 public GenericParameterDeclarations(AssemblyWithMonoCecil assembly, TypeDefinition type)
 {
     Initialize(assembly, type.GenericParameters);
 }
Exemplo n.º 21
0
 private void Initialize(AssemblyWithMonoCecil assembly, IEnumerable <GenericParameter> types)
 {
     GenericParameterDeclarationsWithMonoCecil = types
                                                 .Select(parameter => new GenericParameterDeclarationWithMonoCecil(assembly, parameter))
                                                 .ToList();
 }
Exemplo n.º 22
0
 public GenericParameterDeclarations(AssemblyWithMonoCecil assembly, MethodDefinition method)
 {
     Initialize(assembly, method.GenericParameters);
 }
Exemplo n.º 23
0
 public IndexerSignature(AssemblyWithMonoCecil assembly, PropertyDefinition indexer)
 {
     this.assembly = assembly;
     parameters    = indexer.Parameters.ToArray(parameter => new ParameterSignature(assembly, parameter));
 }
Exemplo n.º 24
0
 public static ITypeReferenceWithMonoCecil GetReturnType(AssemblyWithMonoCecil assembly)
 {
     return(TypeReferenceWithMonoCecilFactory.CreateReference(assembly, assembly.Assembly.MainModule.TypeSystem.Object));
 }
Exemplo n.º 25
0
 public static bool IsDefined(this ICustomAttributeProvider attributeProvider, AssemblyWithMonoCecil assembly, Type type)
 {
     return(attributeProvider.CustomAttributes.Any(attribute => attribute.AttributeType.FullName == type.FullName));
 }