Esempio n. 1
0
        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]);
                }
            }
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public FormalParameter(Type type)
 {
     _name = null;
     _type = new FormalTypeName(type);
     _isRef = false;
     _isOut = false;
     _defaultValue = null;
 }
Esempio n. 5
0
 public FormalMethodName(ConstructorInfo constructorInfo)
 {
     _isConstructor = true;
     _name = new FormalTypeName(constructorInfo.DeclaringType).Name;
     ReadMethod(constructorInfo);
 }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 private string TickedTypeName(FormalTypeName type)
 {
     var sb = new StringBuilder(TypeName(type));
     if (type.IsRef)
         sb.Append(" ^");
     return sb.ToString();
 }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
 public FormalEventName(EventInfo evt)
 {
     _name = evt.Name;
     _delegateType = new FormalTypeName(evt.EventHandlerType);
 }
Esempio n. 12
0
 protected bool IsFiltered(FormalTypeName type)
 {
     return _filteredClasses.Contains(type.Namespace + '.' + type.Name);
 }
Esempio n. 13
0
 protected bool Filter(FormalTypeName type)
 {
     return !IsFiltered(type);
 }
Esempio n. 14
0
 public abstract string TypeName(FormalTypeName type);