public FormalTypeName(Type type) { if (type.IsArray) { _arrayRank = type.GetArrayRank(); _arrayElementType = new FormalTypeName(type.GetElementType()); } _isGenericTypeArg = type.IsGenericParameter; _isRef = !type.IsValueType; _isByRef = type.IsByRef; _name = type.Name; if (_isByRef && _name.EndsWith("&")) _name = _name.Remove(_name.Length - 1); _namespace = type.Namespace; if (type.IsNested && type.FullName != null) { _wrapperClass = new FormalTypeName(type.DeclaringType); } if (type.IsGenericType) { if (type.IsGenericTypeDefinition) { ReadGenericDefinition(type); } else { ReadGenericDefinition(type.GetGenericTypeDefinition()); var args = type.GetGenericArguments(); _genericInstance = new FormalTypeName[args.Length]; for (var i = 0; i < args.Length; i++) _genericInstance[i] = new FormalTypeName(args[i]); } } }
public FormalMethodName(MethodInfo methodInfo, bool isOperator = false, bool extension = false) { _isConstructor = false; _isOperator = isOperator; _isExtension = extension; _name = methodInfo.Name; _returnType = new FormalTypeName(methodInfo.ReturnType); ReadMethod(methodInfo); }
void ReadGenericDefinition(Type type) { var args = type.GetGenericArguments(); _genericArgs = new FormalTypeName[args.Length]; _genericConstraints = new FormalTypeName[args.Length][]; for (var i = 0; i < args.Length; i++) { var requiredBase = args[i].GetGenericParameterConstraints(); var attrs = args[i].GenericParameterAttributes; List<FormalTypeName> restrictions = new List<FormalTypeName>(); foreach (var b in requiredBase) restrictions.Add(new FormalTypeName(b)); if ((attrs & System.Reflection.GenericParameterAttributes.ReferenceTypeConstraint) != 0) restrictions.Add(FormalTypeName.Class); if ((attrs & System.Reflection.GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) restrictions.Add(FormalTypeName.Struct); if ((attrs & System.Reflection.GenericParameterAttributes.DefaultConstructorConstraint) != 0) restrictions.Add(FormalTypeName.DefaultConstructor); _genericArgs[i] = new FormalTypeName(args[i]); _genericConstraints[i] = restrictions.ToArray(); } var endstr = "`" + args.Length; if (_name.EndsWith(endstr)) _name = _name.Remove(_name.Length - endstr.Length); }
public FormalParameter(Type type) { _name = null; _type = new FormalTypeName(type); _isRef = false; _isOut = false; _defaultValue = null; }
public FormalMethodName(ConstructorInfo constructorInfo) { _isConstructor = true; _name = new FormalTypeName(constructorInfo.DeclaringType).Name; ReadMethod(constructorInfo); }
private void ReadMethod(MethodBase method) { if (method.IsGenericMethod) { if (method.IsGenericMethodDefinition) { ReadGenericDefinition(method); } else { ReadGenericDefinition(((MethodInfo)method).GetGenericMethodDefinition()); var args = method.GetGenericArguments(); _genericInstance = new FormalTypeName[args.Length]; for (var i = 0; i < args.Length; i++) _genericInstance[i] = new FormalTypeName(args[i]); } } _parameters = method.GetParameters().Select(p => new FormalParameter(p)).ToArray(); }
public FormalParameter(ParameterInfo param) { _name = param.Name; _type = new FormalTypeName(param.ParameterType); _isRef = param.ParameterType.IsByRef; _isOut = param.IsOut; _defaultValue = Utils.StringRepresentation(param.RawDefaultValue, param.ParameterType); }
static string StandardType(FormalTypeName type) { if (type.Namespace == null) return null; var t = type.Namespace + '.' + type.Name; string s; return _standardTypes.TryGetValue(t, out s) ? s : null; }
private string TickedTypeName(FormalTypeName type) { var sb = new StringBuilder(TypeName(type)); if (type.IsRef) sb.Append(" ^"); return sb.ToString(); }
public override string TypeName(FormalTypeName type) { var standard = StandardType(type); if (standard != null) return standard; if (type.ArrayRank > 0) { var elmName = TypeName(type.ArrayElementType); return "array<" + elmName + (type.ArrayRank > 1 ? ", " + type.ArrayRank : "") + ">"; } StringBuilder sb = new StringBuilder(); if (type.WrapperClass != null) sb.Append(type.WrapperClass).Append("::"); sb.Append(type.Name); if (type.GenericInstance != null) sb.Append('<').Append(string.Join(", ", type.GenericInstance.Select(TickedTypeName))).Append('>'); else if (type.GenericArgs != null) sb.Append('<').Append(string.Join(", ", type.GenericArgs.Select(TickedTypeName))).Append('>'); return sb.ToString(); }
public FormalEventName(EventInfo evt) { _name = evt.Name; _delegateType = new FormalTypeName(evt.EventHandlerType); }
protected bool IsFiltered(FormalTypeName type) { return _filteredClasses.Contains(type.Namespace + '.' + type.Name); }
protected bool Filter(FormalTypeName type) { return !IsFiltered(type); }
public abstract string TypeName(FormalTypeName type);