コード例 #1
0
        public bool Equals(IDotNetType type)
        {
            Argument.IsNotNull(() => type);

            if (!(type is RuntimeType runtimeType))
            {
                return(false);
            }

            return(_type.Equals(runtimeType._type));
        }
コード例 #2
0
        public bool IsSubclassOf(IDotNetType type)
        {
            Argument.IsNotNull(() => type);

            if (!(type is RuntimeType runtimeType))
            {
                return(false);
            }

            return(_type.IsSubclassOf(runtimeType._type));
        }
コード例 #3
0
ファイル: CecilType.cs プロジェクト: benda/ILSpyTheming
        public bool Equals(IDotNetType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!(type is NRType))
            {
                return(false);
            }

            return(this.type.Equals(((NRType)type).type));
        }
コード例 #4
0
ファイル: CecilType.cs プロジェクト: benda/ILSpyTheming
        public bool IsSubclassOf(IDotNetType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (!(type is NRType baseType))
            {
                return(false);
            }

            return(this.type.GetAllBaseTypeDefinitions().Any(t => t.Equals(baseType.type)));
        }
コード例 #5
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            IDotNetType type = obj as IDotNetType;

            if (type == null)
            {
                return(false);
            }

            return(this.DotNetType == type.DotNetType);
        }
コード例 #6
0
        /// <summary>
        /// Extension method that creates the array portion definition of a type definition in C# syntax.
        /// </summary>
        /// <param name="source">The source type to get the array information to format.</param>
        /// <returns>The formatted array syntax for the target type, or null if no array data was provided in the type definition.</returns>
        public static string FormatCSharpArraySignatureSyntax(this IDotNetType source)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsArray)
            {
                return(null);
            }

            var arraySignatureBuilder = new StringBuilder();

            foreach (var sourceArrayDimension in source.ArrayDimensions)
            {
                arraySignatureBuilder.Append(sourceArrayDimension == 1
                    ? $"{Symbols.ArrayDefinitionStart}{Symbols.ArrayDefinitionEnd}"
                    : $"{Symbols.ArrayDefinitionStart}{new string(',', sourceArrayDimension - 1)}{Symbols.ArrayDefinitionEnd}");
            }

            return(arraySignatureBuilder.ToString());
        }
コード例 #7
0
        /// <summary>
        /// Extension method that creates a C# signature for the tuple type.
        /// </summary>
        /// <param name="source">The target declaration syntax for a tuple.</param>
        /// <returns>The formatted tuple or null if data is missing.</returns>
        public static string FormatCSharpTupleSignatureSyntax(this IDotNetType source)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsTuple)
            {
                return(null);
            }

            if (!source.TupleTypes.Any())
            {
                return(null);
            }

            StringBuilder tupleSignature = new StringBuilder(Symbols.ParametersDefinitionStart);

            int totalParameters  = source.TupleTypes.Count;
            int currentParameter = 0;

            foreach (var sourceParameter in source.TupleTypes)
            {
                currentParameter++;

                tupleSignature.Append(!sourceParameter.HasDefaultName
                    ? $"{sourceParameter.TupleType.FormatCSharpFullTypeName()} {sourceParameter.Name} "
                    : sourceParameter.TupleType.FormatCSharpFullTypeName());

                if (totalParameters > currentParameter)
                {
                    tupleSignature.Append(", ");
                }
            }

            tupleSignature.Append(Symbols.ParametersDefinitionEnd);

            return(tupleSignature.ToString());
        }
コード例 #8
0
 public bool Equals(IDotNetType type)
 {
     return(type is UnresolvableType && type.AssemblyQualifiedName == AssemblyQualifiedName);
 }
コード例 #9
0
 public bool IsSubclassOf(IDotNetType type)
 {
     return(Equals(type));
 }
コード例 #10
0
        /// <summary>
        /// Extension method that returns a value declaration in the C# language format.
        /// </summary>
        /// <param name="source">The target type to create the value definition for.</param>
        /// <param name="value">The value to be formatted.</param>
        /// <returns>The definition of the value formatted for C#</returns>
        public static string FormatCSharpValueSyntax(this IDotNetType source, string value)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsLoaded)
            {
                return(null);
            }

            if (source.Name == "Type" & source.Namespace == "System")
            {
                return($"typeof({value})");
            }

            if (source.IsEnum)
            {
                try
                {
                    var enumData = source.GetEnumModel();


                    return(enumData?.FormatCSharpEnumTypeSyntax(value));
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            if (!source.IsWellKnownType)
            {
                return(value);
            }

            string result = null;

            switch (source.WellKnownType)
            {
            case WellKnownLanguageType.Void:

                result = Keywords.Void;

                break;

            case WellKnownLanguageType.Boolean:

                result = value.ToLower();
                break;

            case WellKnownLanguageType.Character:
                result = $"'{value}'";
                break;

            case WellKnownLanguageType.String:
                result = $"\"{value}\"";
                break;

            default:
                result = value;
                break;
            }

            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Extension method that generates the default value syntax for a parameter in the C# language.
        /// </summary>
        /// <param name="source">The target default value to format.</param>
        /// <param name="type">The target type of the value to be formatted.</param>
        /// <returns>The fully formatted syntax for the default value or null if data was missing.</returns>
        public static string FormatCSharpParameterDefaultValueSyntax(this IDotNetParameterDefaultValue source, IDotNetType type)
        {
            if (source == null)
            {
                return(null);
            }
            if (type == null)
            {
                return(null);
            }

            string result = null;

            switch (source.ValueType)
            {
            case ParameterDefaultValueType.Value:

                result = type.FormatCSharpValueSyntax(source.Value);
                break;

            case ParameterDefaultValueType.DefaultKeyWord:

                result = Keywords.Default;
                break;

            case ParameterDefaultValueType.NullKeyword:

                result = Keywords.Null;
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Extension method that generates the fully qualified type name from the <see cref="IDotNetType"/> model in the C# format.
        /// </summary>
        /// <param name="source">The source type to get the full type name from.</param>
        /// <returns>The fully qualified namespace and full type definition. Null if the type is missing or not loaded. </returns>
        public static string FormatCSharpFullTypeName(this IDotNetType source)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsLoaded)
            {
                return(null);
            }

            string typeName    = null;
            string returnValue = null;

            if (source.IsWellKnownType)
            {
                switch (source.WellKnownType)
                {
                case WellKnownLanguageType.NotWellKnown:
                    typeName = null;
                    break;

                case WellKnownLanguageType.Object:
                    typeName = WellKnownTypes.Object;
                    break;

                case WellKnownLanguageType.Void:
                    typeName = Keywords.Void;
                    break;

                case WellKnownLanguageType.Boolean:
                    typeName = WellKnownTypes.Boolean;
                    break;

                case WellKnownLanguageType.Character:
                    typeName = WellKnownTypes.Character;
                    break;

                case WellKnownLanguageType.Signed8BitInteger:
                    typeName = WellKnownTypes.SByte;
                    break;

                case WellKnownLanguageType.UnSigned8BitInteger:
                    typeName = WellKnownTypes.Byte;
                    break;

                case WellKnownLanguageType.Signed16BitInteger:
                    typeName = WellKnownTypes.Short;
                    break;

                case WellKnownLanguageType.Unsigned16BitInteger:
                    typeName = WellKnownTypes.Ushort;
                    break;

                case WellKnownLanguageType.Signed32BitInteger:
                    typeName = WellKnownTypes.Int;
                    break;

                case WellKnownLanguageType.Unsigned32BitInteger:
                    typeName = WellKnownTypes.Uint;
                    break;

                case WellKnownLanguageType.Signed64BitInteger:
                    typeName = WellKnownTypes.Long;
                    break;

                case WellKnownLanguageType.Unsigned64BitInteger:
                    typeName = WellKnownTypes.Ulong;
                    break;

                case WellKnownLanguageType.Decimal:
                    typeName = WellKnownTypes.Decimal;
                    break;

                case WellKnownLanguageType.Single:
                    typeName = WellKnownTypes.Float;
                    break;

                case WellKnownLanguageType.Double:
                    typeName = WellKnownTypes.Double;
                    break;

                case WellKnownLanguageType.Pointer:
                    typeName = WellKnownTypes.Pointer;
                    break;

                case WellKnownLanguageType.PlatformPointer:
                    typeName = WellKnownTypes.PlatformPointer;
                    break;

                case WellKnownLanguageType.DateTime:
                    typeName = WellKnownTypes.Datetime;
                    break;

                case WellKnownLanguageType.String:
                    typeName = WellKnownTypes.String;
                    break;

                default:
                    typeName = null;
                    break;
                }
            }
            else
            {
                typeName = $"{source.Namespace}.{source.Name}";
            }

            returnValue = typeName;
            if (source.IsGeneric)
            {
                returnValue = $"{typeName}{source.GenericParameters.FormatCSharpGenericSignatureSyntax()}";
            }
            if (source.IsArray)
            {
                returnValue = $"{typeName}{source.FormatCSharpArraySignatureSyntax()}";
            }
            if (source.IsTuple)
            {
                returnValue = source.FormatCSharpTupleSignatureSyntax();
            }
            return(returnValue);
        }
コード例 #13
0
        public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IDotNetType ownerType, IDotNetType targetType)
        {
            Argument.IsNotNull(() => ownerType);

            if (ownerType is RuntimeType runtimeType)
            {
                return(new RuntimeTypeDependencyPropertyDescriptor(runtimeType.Type, name));
            }

            if (ownerType is UnresolvableType)
            {
                return(new UnresolvableDependencyPropertyDescriptor());
            }

            throw new ArgumentException("Invalid type: " + ownerType.GetType());
        }
コード例 #14
0
        public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IDotNetType ownerType, IDotNetType targetType)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }

            if (ownerType is NRType)
            {
                return(new NRTypeDependencyPropertyDescriptor(((NRType)ownerType).Type, name));
            }
            if (ownerType is UnresolvableType)
            {
                return(new UnresolvableDependencyPropertyDescriptor());
            }

            throw new ArgumentException("Invalid IType: " + ownerType.GetType());
        }