55using System . Data ;
66using System . Reflection ;
77using System . Runtime . InteropServices ;
8+ using System . Text ;
89
910namespace Desharp . Completers {
1011 /// <summary>
@@ -24,6 +25,15 @@ public class Detector {
2425 /// Common `System.Delegate` `Type` object instance
2526 /// </summary>
2627 protected static Type delegateType = typeof ( System . Delegate ) ;
28+ /// <summary>
29+ /// `System.Tuple` string value (backwards compatibility for .NET 4.0+)
30+ /// </summary>
31+ protected static string systemTupleStr = "System.Tuple" ;
32+ /// <summary>
33+ /// `System.Tuple` string value length (backwards compatibility for .NET 4.0+)
34+ /// </summary>
35+ protected static int systemTupleStrLen = 12 ;
36+
2737 /// <summary>
2838 /// True if value is sbyte | byte | short | ushort | int | uint | long | ulong | float | double | decimal | char | bool | string | object.
2939 /// </summary>
@@ -32,7 +42,7 @@ public class Detector {
3242 /// <returns>True if `obj` is any primitive value except `enum`, `struct` and `unmanaged`.</returns>
3343 public static bool IsPrimitiveType ( ref object obj , ref Type objType ) {
3444 // https://docs.microsoft.com/en-US/dotnet/api/system.type.isprimitive?view=netframework-4.8
35- if ( objType . IsPrimitive || obj is string || obj is decimal || obj is System . Decimal ) return true ; // decimal and string is not primitive
45+ if ( objType . IsPrimitive || obj is string || obj is decimal || obj is System . DBNull ) return true ; // decimal and string is not primitive
3646 return false ;
3747 }
3848 /// <summary>
@@ -69,9 +79,9 @@ public static bool IsDictionary (ref object obj, ref Type objType) {
6979 if ( objType . IsGenericType && objType . GetGenericTypeDefinition ( ) == typeof ( Dictionary < , > ) ) {
7080 return true ;
7181 } else if (
72- objType . GetProperty ( "Count" ) is PropertyInfo &&
73- objType . GetProperty ( "Keys" ) is PropertyInfo &&
74- objType . GetProperty ( "Values" ) is PropertyInfo
82+ objType . GetProperty ( "Count" , BindingFlags . Instance | BindingFlags . Public ) is PropertyInfo &&
83+ objType . GetProperty ( "Keys" , BindingFlags . Instance | BindingFlags . Public ) is PropertyInfo &&
84+ objType . GetProperty ( "Values" , BindingFlags . Instance | BindingFlags . Public ) is PropertyInfo
7585 ) {
7686 return true ;
7787 }
@@ -105,7 +115,7 @@ public static bool IsEnum (ref object obj, ref Type objType) {
105115 /// <param name="objType">Type object for value or null.</param>
106116 /// <returns>True if `obj` is `Type` object.</returns>
107117 public static bool IsTypeObject ( ref object obj , ref Type objType ) {
108- if ( obj is Type ) return true ;
118+ if ( obj is _Type ) return true ;
109119 return false ;
110120 }
111121 /// <summary>
@@ -137,7 +147,10 @@ public static bool IsCollection (ref object obj, ref Type objType) {
137147 /// <returns>True if `obj` is `System.Func<,>`.</returns>
138148 public static bool IsTuple ( ref object obj , ref Type objType ) {
139149 // this string comparison is because of backward compatibility for .NET 4.0+
140- if ( objType . FullName . IndexOf ( "System.Tuple" ) == 0 ) return true ;
150+ //if (objType.FullName.IndexOf("System.Tuple") == 0) return true;
151+ string objTypefullName = objType . FullName ;
152+ int sysTupleLen = Detector . systemTupleStrLen ;
153+ if ( objTypefullName . Length >= sysTupleLen && Detector . systemTupleStr == objTypefullName . Substring ( 0 , sysTupleLen ) ) return true ;
141154 return false ;
142155 }
143156 /// <summary>
@@ -163,15 +176,24 @@ public static bool IsDelegate(ref object obj, ref Type objType) {
163176 ) return true ;
164177 return false ;
165178 }
166-
167179 /// <summary>
168180 /// True if value is MethodInfo | PropertyInfo | FieldInfo | EventInfo | MemberInfo | ConstructorInfo.
169181 /// </summary>
170182 /// <param name="obj">Any value except null.</param>
171183 /// <param name="objType">Type object for value or null.</param>
172184 /// <returns>True if value is MethodInfo | PropertyInfo | FieldInfo | EventInfo | MemberInfo | ConstructorInfo.</returns>
173185 public static bool IsReflectionObject ( ref object obj , ref Type objType ) {
174- if ( obj is MemberInfo || obj is _MemberInfo ) return true ;
186+ if ( obj is _MemberInfo ) return true ;
187+ return false ;
188+ }
189+ /// <summary>
190+ /// True if `obj` implements `IFormattable` or if `obj` is `Stringbuilder`
191+ /// </summary>
192+ /// <param name="obj">Any value except null.</param>
193+ /// <param name="objType">Type object for value or null.</param>
194+ /// <returns>True if `obj` implements `IFormattable` or if `obj` is `Stringbuilder`</returns>
195+ public static bool IsExtraFormatedObject ( ref object obj , ref Type objType ) {
196+ if ( obj is IFormattable || obj is StringBuilder || obj is System . Guid ) return true ;
175197 return false ;
176198 }
177199 }
0 commit comments