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(); } }
public Parameters( AssemblyWithMonoCecil assembly, PropertyDefinition indexer, Func <ParameterWithMonoCecil, TParameter> parameterFactory) { Initialize(assembly, indexer, indexer.Parameters, parameterFactory); }
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(); }
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); }
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); }
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(); }
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); }
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)); }
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))); }
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); }
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)); }
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); }
public ParameterSignature(AssemblyWithMonoCecil assembly, ParameterDefinition parameter) { modifier = parameter.Modifier(assembly); name = string.Format("parameter{0}", parameter.Index + 1); parameterType = TypeReferenceWithMonoCecilFactory.CreateReference(assembly, parameter.ParameterType); }
internal SolutionWithMonoCecil(AssemblyWithMonoCecil assembly) { this.assembly = assembly; projects = new ProjectWithMonoCecil[] { new ProjectWithMonoCecil(this, assembly) }; }
public InterfaceReferences(AssemblyWithMonoCecil assembly, TypeDefinition type) { InterfaceReferencesWithMonoCecil = type.Interfaces .Select(interfaceType => new InterfaceReferenceWithMonoCecil(assembly, interfaceType)) .ToList(); }
public GenericParameterDeclarations(AssemblyWithMonoCecil assembly, TypeDefinition type) { Initialize(assembly, type.GenericParameters); }
private void Initialize(AssemblyWithMonoCecil assembly, IEnumerable <GenericParameter> types) { GenericParameterDeclarationsWithMonoCecil = types .Select(parameter => new GenericParameterDeclarationWithMonoCecil(assembly, parameter)) .ToList(); }
public GenericParameterDeclarations(AssemblyWithMonoCecil assembly, MethodDefinition method) { Initialize(assembly, method.GenericParameters); }
public IndexerSignature(AssemblyWithMonoCecil assembly, PropertyDefinition indexer) { this.assembly = assembly; parameters = indexer.Parameters.ToArray(parameter => new ParameterSignature(assembly, parameter)); }
public static ITypeReferenceWithMonoCecil GetReturnType(AssemblyWithMonoCecil assembly) { return(TypeReferenceWithMonoCecilFactory.CreateReference(assembly, assembly.Assembly.MainModule.TypeSystem.Object)); }
public static bool IsDefined(this ICustomAttributeProvider attributeProvider, AssemblyWithMonoCecil assembly, Type type) { return(attributeProvider.CustomAttributes.Any(attribute => attribute.AttributeType.FullName == type.FullName)); }