18 using System.Collections.Generic;
19 using System.Reflection;
23 using ErrorManagement;
25 namespace TypeSystem {
39 private Type reflectionType;
54 get {
return this.reflectionType; }
67 this.reflectionType = type;
68 this.userType = userType;
79 #region createBCLUserType()
81 if ((type.IsClass) || (type.IsValueType))
85 throw new ArgumentException(String.Format(
"The type '{0}' is not a class, nor an interface.", type));
90 private void createMethods(MethodInfo[] methods,
Location location) {
100 foreach (MethodInfo method
in methods) {
102 ParameterInfo[] parameters = method.GetParameters();
103 for (
int j = 0; j < parameters.GetLength(0); j++)
104 if (parameters[j].ParameterType.FullName!=null)
105 mt.AddParameter(TypeTable.Instance.GetType(parameters[j].ParameterType.FullName, location));
109 accessModifierInfo =
new AccessModifier(mods, method.Name, mt,
false);
110 mt.MemberInfo = accessModifierInfo;
111 accessModifierInfo.Class = (
UserType)userType;
113 if (userType.
Members.ContainsKey(method.Name)) {
118 ((IntersectionType)userType.
Members[method.Name].Type).AddType(mt);
121 userType.AddMember(method.Name, accessModifierInfo);
128 #region createField()
138 private FieldType createField(FieldInfo field,
Location location) {
139 AccessModifier accessModifierInfo;
140 FieldType ft =
new FieldType(TypeTable.Instance.GetType(field.FieldType.FullName, location));
142 List<Modifier> mods = getFieldModifierList(field);
144 accessModifierInfo =
new AccessModifier(mods, field.Name, ft,
false);
145 ft.MemberInfo = accessModifierInfo;
146 accessModifierInfo.Class = (
UserType)userType;
148 userType.AddMember(field.Name, accessModifierInfo);
157 #region createProperty()
168 private PropertyType createProperty(PropertyInfo prop,
Location location) {
169 AccessModifier accessModifierInfo;
170 PropertyType pt =
new PropertyType(TypeTable.Instance.GetType(prop.PropertyType.FullName, location), prop.CanRead, prop.CanWrite);
173 MethodInfo methodInfo;
175 methodInfo = userType.TypeInfo.GetMethod(
"get_" + prop.Name);
177 methodInfo = userType.TypeInfo.GetMethod(
"set_" + prop.Name);
179 mods = getPropertyModifierList(prop, mods);
181 accessModifierInfo =
new AccessModifier(mods, prop.Name, pt,
false);
182 pt.MemberInfo = accessModifierInfo;
183 accessModifierInfo.Class = (
UserType)userType;
185 userType.Members[prop.Name] = accessModifierInfo;
207 TypeExpression member = this.FindMember(memberName);
221 MethodInfo[] methodsInfo;
222 PropertyInfo propertyInfo;
223 BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
226 if (userType.
Members.ContainsKey(memberName))
227 return userType.
Members[memberName].Type;
230 if ((fieldInfo = reflectionType.GetField(memberName, flags)) != null)
231 return createField(fieldInfo,
new Location());
233 if ((propertyInfo = reflectionType.GetProperty(memberName, flags)) != null)
234 return createProperty(propertyInfo,
new Location());
236 if ((methodsInfo = reflectionType.GetMethods(flags)) != null) {
237 createMethods(methodsInfo,
new Location());
238 if (!userType.
Members.ContainsKey(memberName))
241 return userType.Members[memberName].Type;
248 #region Parenthesis()anulada
252 #region FindConstructor
261 ConstructorInfo[] constructors = userType.TypeInfo.GetConstructors();
264 foreach (ConstructorInfo constructor
in constructors) {
266 ParameterInfo[] parameters = constructor.GetParameters();
267 for (
int j = 0; j < parameters.GetLength(0); j++)
272 accessModifierInfo =
new AccessModifier(mods, constructor.Name, mt,
false);
273 mt.MemberInfo = accessModifierInfo;
274 accessModifierInfo.Class = (
UserType)userType;
281 ((IntersectionType)userType.
Members[userType.
Name].Type).AddType(mt);
284 userType.AddMember(userType.Name, accessModifierInfo);
297 #region GetMethodModifierList()
304 List<Modifier> mods =
new List<Modifier>();
305 if (method.IsAbstract)
306 mods.Add(Modifier.Abstract);
307 if (method.IsPrivate)
308 mods.Add(Modifier.Private);
310 mods.Add(Modifier.Public);
312 mods.Add(Modifier.Protected);
314 mods.Add(Modifier.Static);
315 if (method.IsVirtual)
316 mods.Add(Modifier.Virtual);
320 List<Modifier> mods =
new List<Modifier>();
321 if (member.DeclaringType.IsAbstract)
322 mods.Add(Modifier.Abstract);
323 if (member.DeclaringType.IsNotPublic)
324 mods.Add(Modifier.Private);
325 if (member.DeclaringType.IsPublic)
326 mods.Add(Modifier.Public);
331 #region GetFieldModifierList()
332 private static List<Modifier> getFieldModifierList(FieldInfo field) {
338 List<Modifier> mods =
new List<Modifier>();
340 mods.Add(Modifier.Private);
342 mods.Add(Modifier.Public);
344 mods.Add(Modifier.Protected);
346 mods.Add(Modifier.Static);
351 #region GetPropertyModifierList()
352 private static List<Modifier> getPropertyModifierList(PropertyInfo property, List<Modifier> mods) {
358 if (property.CanRead)
359 mods.Add(Modifier.CanRead);
360 if (property.CanWrite)
361 mods.Add(Modifier.CanWrite);
368 #region createBaseClassAndInterfacesTree()
375 System.Type baseClass = this.reflectionType.BaseType;
376 if (baseClass != null) {
377 BCLClassType BCLBaseClass =
new BCLClassType(baseClass.FullName, baseClass);
378 userType.AddBaseClass(BCLBaseClass,
new Location(null, 0, 0));
381 Type[] interfaces = this.reflectionType.GetInterfaces();
382 foreach (Type interfaze
in interfaces) {
383 BCLInterfaceType baseInterface =
new BCLInterfaceType(interfaze.FullName, interfaze);
384 userType.AddBaseInterface(baseInterface,
new Location(null, 0, 0));
Represents a type obtained using introspection.
void createBaseClassAndInterfacesTree()
Creates, based on introspection, the base class of the user type and the list of interfaces implement...
static TypeTable Instance
Gets the unique instance of TypeTable
This class encapsulates a location in a specific file. Implements an Inmutable pattern. So it can be used in any context, that is his internal fields never change.
static List< Modifier > getMethodModifierList(MemberInfo member)
TypeExpression FindMember(string memberName, Location location)
Finds a attribute of a BCL user type, using introspection. Inheritance is not taken into account...
static List< Modifier > getMethodModifierList(MethodBase method)
Gets the modifier list from a method info
Abstract class that represents all different types.
TypeExpression GetType(string name, Location location)
Gets the type associated to the name specified in the argument.
TypeExpression FindMember(string memberName)
Finds a attribute of a BCL user type, using introspection. Inheritance is not taken into account...
AccessModifier Constructors
Gets the constructor list
Implementation of a table of types.
Introspection(IBCLUserType userType, Type type)
Constructor of Introspection.
Dictionary< string, AccessModifier > Members
Gets and sets the attribute list
Type TypeInfo
Gets the type
Representa a method type.
static TypeExpression createBCLUserType(string name, System.Type type, Location location)
Method that encapsulates the creation of a BCL class or interface
const int MAX_DEPTH_LEVEL_TYPE_EXPRESSION
In order to avoid stack overflow in the construction of typeexpression string (ToString), we set a maximum level of depth
Association Class between ClassType and MethodType (or Fields). Represents the access modifier inform...
A class that makes possible to have intersection types as class members (overload) ...
TypeExpression Type
Gets or sets the attribute type expression
Representa an intersection type.
TypeExpression FindConstructor(Location location)
Finds and adds the list of constructor to a BCL type
Represents a error produced when the attribute identifier is not defined.
string Name
Class identifier;
Represents a class or interface type.
void AddParameter(TypeExpression paramType)
Adds a new parameter type.