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