Example #1
0
        private IToObject GetToObject(TypeKey key)
        {
            IToObject toObject = null;

            if (key != null && key.FromType != null && key.ToType != null)
            {
                if (this.m_toObjectDic.TryGetValue(key, out toObject))
                {
                    return(toObject);
                }

                try
                {
                    var type = this.CreateMapType(key);
                    if (type == null)
                    {
                        return(toObject);
                    }

                    object obj = Activator.CreateInstance(type);
                    toObject = obj as IToObject;
                    this.m_toObjectDic.TryAdd(key, toObject);
                }
                catch { }
            }

            return(toObject);
        }
Example #2
0
        private IToObject GetToObject(TypeKey key)
        {
            IToObject toObject = null;

            if (key != null && key.FromType != null && key.ToType != null)
            {
                using (this.m_rwLock.GetReadLock())
                {
                    this.m_toObjectDic.TryGetValue(key, out toObject);
                }
                if (toObject != null)
                {
                    return(toObject);
                }

                using (this.m_rwLock.GetWriteLock())
                {
                    this.m_toObjectDic.TryGetValue(key, out toObject);
                    if (toObject != null)
                    {
                        return(toObject);
                    }

                    try
                    {
                        var type = this.CreateMapType(key);
                        if (type == null)
                        {
                            return(toObject);
                        }

                        object obj = Activator.CreateInstance(type, new object[] { key.FromType, this });
                        toObject = obj as IToObject;
                        this.m_toObjectDic[key] = toObject;
                    }
                    catch { }
                }
            }

            return(toObject);
        }