Example #1
0
 internal override sealed void Reset()
 {
     lock (this.cache)
     {
         this.cache.Clear();
         TypeAccelerators.FillCache(this.cache);
     }
 }
Example #2
0
 static ScriptSession()
 {
     TypeAccelerators.AddSitecoreAccelerators();
     using (var ps = System.Management.Automation.PowerShell.Create())
     {
         var psVersionTable = ps.Runspace.SessionStateProxy.GetVariable("PSVersionTable") as Hashtable;
         PsVersion = (Version)psVersionTable["PSVersion"];
     }
 }
        internal static string Type(System.Type type, bool dropNamespaces = false)
        {
            string    assemblyQualifiedName;
            Exception exception;

            if (type == null)
            {
                return(string.Empty);
            }
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                string        str2    = Type(type.GetGenericTypeDefinition(), dropNamespaces);
                int           num     = str2.LastIndexOf('`');
                int           length  = str2.Length - (str2.Length - num);
                StringBuilder builder = new StringBuilder(str2, 0, length, 0x200);
                builder.Append('[');
                bool flag = true;
                foreach (System.Type type2 in type.GetGenericArguments())
                {
                    if (!flag)
                    {
                        builder.Append(',');
                    }
                    flag = false;
                    builder.Append(Type(type2, dropNamespaces));
                }
                builder.Append(']');
                assemblyQualifiedName = builder.ToString();
            }
            else if (type.IsArray)
            {
                string        str3     = Type(type.GetElementType(), dropNamespaces);
                StringBuilder builder2 = new StringBuilder(str3, str3.Length + 10);
                builder2.Append("[");
                for (int i = 0; i < (type.GetArrayRank() - 1); i++)
                {
                    builder2.Append(",");
                }
                builder2.Append("]");
                assemblyQualifiedName = builder2.ToString();
            }
            else
            {
                assemblyQualifiedName = TypeAccelerators.FindBuiltinAccelerator(type) ?? (dropNamespaces ? type.Name : type.ToString());
            }
            if ((!type.IsGenericParameter && !type.ContainsGenericParameters) && (!dropNamespaces && (LanguagePrimitives.ConvertStringToType(assemblyQualifiedName, out exception) != type)))
            {
                assemblyQualifiedName = type.AssemblyQualifiedName;
            }
            return(assemblyQualifiedName);
        }
Example #4
0
        internal static string Type(System.Type type)
        {
            if (type == null)
            {
                return(string.Empty);
            }
            string typeName;

            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                string        str           = ToStringCodeMethods.Type(type.GetGenericTypeDefinition());
                int           num           = str.LastIndexOf('`');
                int           length        = str.Length - (str.Length - num);
                StringBuilder stringBuilder = new StringBuilder(str, 0, length, 512);
                stringBuilder.Append('[');
                bool flag = true;
                foreach (System.Type genericArgument in type.GetGenericArguments())
                {
                    if (!flag)
                    {
                        stringBuilder.Append(',');
                    }
                    flag = false;
                    stringBuilder.Append(ToStringCodeMethods.Type(genericArgument));
                }
                stringBuilder.Append(']');
                typeName = stringBuilder.ToString();
            }
            else if (type.IsArray)
            {
                string        str           = ToStringCodeMethods.Type(type.GetElementType());
                StringBuilder stringBuilder = new StringBuilder(str, str.Length + 10);
                stringBuilder.Append("[");
                for (int index = 0; index < type.GetArrayRank() - 1; ++index)
                {
                    stringBuilder.Append(",");
                }
                stringBuilder.Append("]");
                typeName = stringBuilder.ToString();
            }
            else
            {
                typeName = TypeAccelerators.FindBuiltinAccelerator(type) ?? type.ToString();
            }
            if (!type.IsGenericParameter && !type.ContainsGenericParameters && LanguagePrimitives.ConvertStringToType(typeName, out Exception _) != type)
            {
                typeName = type.AssemblyQualifiedName;
            }
            return(typeName);
        }
Example #5
0
 /// <summary>
 /// Create a deep clone of the available type data object.
 /// </summary>
 public object Clone()
 {
     return(new AvailableTypeData()
     {
         TypeAccelerators = (JsonCaseInsensitiveStringDictionary <TypeAcceleratorData>)TypeAccelerators.Clone(),
         Assemblies = (JsonCaseInsensitiveStringDictionary <AssemblyData>)Assemblies.Clone()
     });
 }
 static ScriptSession()
 {
     TypeAccelerators.AddSitecoreAccelerators();
 }