ParseEscSeqs() public static method

Parses escape sequences found in char or string literals
public static ParseEscSeqs ( string &data, bool isVerbatim ) : void
data string String containing the literal that may have escape sequences
isVerbatim bool /// Used to tell if the literal passed is a verbatim string. /// True if data represents verbatim string, false otherwise ///
return void
Beispiel #1
0
        ///
        /// <summary>
        ///		Converts string parameter containing type into an actual type
        /// </summary>
        ///
        /// <param name="typeData">String containing type</param>
        ///
        /// <returns>Found type or null if type is not found</returns>
        ///
        public static Type GetType(string typeData)
        {
            if (!HasCachedCommonTypes)
            {
                CacheCommonTypes();
            }

            LiteralExp.ParseEscSeqs(ref typeData, false);

            Type returnedType = null;

            Regex typeRegex = new Regex(@"^[\w][\w\d]*$");

            if (typeRegex.IsMatch(typeData))
            {
                bool isFailedtype;
                if (!cachedTypes.TryGetValue(typeData, out returnedType) && !failedTypes.TryGetValue(typeData, out isFailedtype))
                {
                    Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly assembly in assemblies)
                    {
                        try {
                            foreach (Type type in assembly.GetTypes())
                            {
                                if (type.Name == typeData)
                                {
                                    returnedType          = type;
                                    cachedTypes[typeData] = returnedType;
                                    break;
                                }
                            }
                            if (returnedType != null)
                            {
                                cachedTypes[typeData] = returnedType;
                                break;
                            }
                        }
                        catch (System.Reflection.ReflectionTypeLoadException) {
                            continue;
                        }
                    }
                }
                if (returnedType == null)
                {
                    failedTypes[typeData] = true;
                }
            }

            return(returnedType);
        }
Beispiel #2
0
        ///
        /// <summary>
        ///		Parses identifiers (fields or properties)
        /// </summary>
        ///
        /// <param name="environment">The environment containing the field or property</param>
        /// <param name="data">The name of the field or property</param>
        ///
        /// <returns>An CseObject containing the value of the identifier or containing null if identifier cannot be found</returns>
        ///
        /// <exception cref="CseLogicExceptionType.IDENT_NOT_FOUND" />
        ///
        internal static CseObject Parse(CseObject environment, string data)
        {
            if (data[0].Equals('@'))
            {
                data = data.Remove(0, 1);
            }

            LiteralExp.ParseEscSeqs(ref data, false);

            CseObject result       = null;
            Type      instanceType = TypeExp.GetTypeObj(environment.Value);

            if (!instanceType.IsEnum)
            {
                if (environment == CsEval.EvalEnvironment)
                {
                    CseObject tempLookup = TempIdentifierExp.Lookup(data);
                    if (tempLookup != null)
                    {
                        return(tempLookup);
                    }
                }

                FieldInfo fieldInfo = instanceType.GetField(data, defaultFlags | BindingFlags.GetField);
                if (fieldInfo != null)
                {
                    result = new CseObject(fieldInfo.GetValue(environment.Value));
                    result.CompileTimeType = fieldInfo.FieldType;
                }
                else
                {
                    PropertyInfo propertyInfo = instanceType.GetProperty(data, defaultFlags | BindingFlags.GetProperty);
                    if (propertyInfo != null)
                    {
                        result = new CseObject(propertyInfo.GetValue(environment.Value, null));
                        result.CompileTimeType = propertyInfo.PropertyType;
                    }
                    else
                    {
                        Type t = TypeExp.GetType(data);
                        if (t != null)
                        {
                            result = new CseObject(t);
                            result.CompileTimeType = t.GetType();
                        }
                        else
                        {
                            throw new CseLogicException(CseLogicExceptionType.IDENT_NOT_FOUND, data);
                        }
                    }
                }
            }
            else
            {
                dynamic resultObj = Enum.Parse(instanceType, data);
                result = new CseObject(resultObj);
                result.CompileTimeType = resultObj.GetType();
            }

            return(result);
        }