Beispiel #1
0
        /// <summary>
        ///     Returns a simplified class name from Namespace.Class with respect to usings
        /// </summary>
        /// <param name="type"></param>
        /// <param name="usetypes">whether to use class names for generics instead of parameter names</param>
        /// <param name="reflectedType">type reflected by <see cref="Reflectotron" /></param>
        /// <param name="deleg"></param>
        /// <returns></returns>
        public string Write(Type type, bool usetypes = false, Type reflectedType = null, GetReturnType deleg = null)
        {
            var fullname = type.FullName;
            if (fullname == null)
            {
                return TrimTypeName(type.Name);
            }

            if ((reflectedType != null) && (deleg != null))
            {
                if (reflectedType.IsGenericType)
                {
                    var returnType = deleg(reflectedType.GetGenericTypeDefinition());
                    if (returnType.IsGenericParameter)
                        return returnType.Name;
                }
            }

            var nameSpace = type.Namespace;
            var shortName = TrimTypeName(type.Name);
            if (shortName.EndsWith("Attribute") && (type.BaseType == typeof (Attribute)))
                //"attribute" can be safely removed
            {
                shortName = shortName.Remove(shortName.LastIndexOf("Attribute", StringComparison.Ordinal));
            }

            if ((nameSpace != _namespace) && _classes.ContainsKey(shortName) && (_classes[shortName] != nameSpace))
                //class name conflict, use full name
                return $"{nameSpace}.{shortName}{GetGenericPart(type, usetypes)}";

            if (!_classes.ContainsKey(shortName)) //unknown class with no conflicts            
                _classes.Add(shortName, nameSpace); //remember it

            return $"{shortName}{GetGenericPart(type, usetypes)}";
        }
 internal PlaceholderMethodSymbol(
     NamedTypeSymbol container,
     string name,
     GetTypeParameters getTypeParameters,
     GetReturnType getReturnType,
     GetParameters getParameters)
 {
     _container      = container;
     _name           = name;
     _typeParameters = getTypeParameters(this);
     _returnType     = getReturnType(this);
     _parameters     = getParameters(this);
 }
 internal PlaceholderMethodSymbol(
     NamedTypeSymbol container,
     string name,
     GetTypeParameters getTypeParameters,
     GetReturnType getReturnType,
     GetParameters getParameters)
 {
     _container = container;
     _name = name;
     _typeParameters = getTypeParameters(this);
     _returnType = getReturnType(this);
     _parameters = getParameters(this);
 }
 internal PlaceholderMethodSymbol(
     NamedTypeSymbol container,
     CSharpSyntaxNode syntax,
     string name,
     GetTypeParameters getTypeParameters,
     GetReturnType getReturnType,
     GetParameters getParameters,
     bool returnValueIsByRef) :
     this(container, syntax, name)
 {
     _typeParameters = getTypeParameters(this);
     _returnType = getReturnType(this);
     _parameters = getParameters(this);
     _returnValueIsByRef = returnValueIsByRef;
 }
 internal PlaceholderMethodSymbol(
     NamedTypeSymbol container,
     CSharpSyntaxNode syntax,
     string name,
     GetTypeParameters getTypeParameters,
     GetReturnType getReturnType,
     GetParameters getParameters,
     bool returnValueIsByRef) :
     this(container, syntax, name)
 {
     _typeParameters     = getTypeParameters(this);
     _returnType         = getReturnType(this);
     _parameters         = getParameters(this);
     _returnValueIsByRef = returnValueIsByRef;
 }
Beispiel #6
0
 /// <summary>
 ///     Shorthand for <see cref="Write" /> optimised for return types
 /// </summary>
 /// <param name="type">Type of return type</param>
 /// <param name="reflectedType">Object the memeber with "type" is within</param>
 /// <param name="deleg">How to acquire type from reflected type</param>
 /// <returns></returns>
 public string WriteReturnType(Type type, Type reflectedType, GetReturnType deleg)
 {
     return Write(type, false, reflectedType, deleg);
 }