Example #1
0
        private SafeDictionary <string, myPropInfo> Getproperties(Type type, string typename)
        {
            SafeDictionary <string, myPropInfo> sd = null;

            if (_propertycache.TryGetValue(typename, out sd))
            {
                return(sd);
            }
            sd = new SafeDictionary <string, myPropInfo>();
            var pr = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            foreach (var p in pr)
            {
                myPropInfo d = CreateMyProp(p.PropertyType, p.Name);
                d.CanWrite = p.CanWrite;
                d.setter   = CreateSetMethod(p);
                d.getter   = CreateGetMethod(p);
                sd.Add(p.Name, d);
            }

            _propertycache.Add(typename, sd);
            return(sd);
        }
Example #2
0
        private object FastCreateInstance(Type objtype)
        {
            try
            {
                CreateObject c = null;
                if (_constrcache.TryGetValue(objtype, out c))
                {
                    return(c());
                }
                DynamicMethod dynMethod = new DynamicMethod("_", objtype, null, true);
                ILGenerator   ilGen     = dynMethod.GetILGenerator();

                ilGen.Emit(OpCodes.Newobj, objtype.GetConstructor(Type.EmptyTypes));
                ilGen.Emit(OpCodes.Ret);
                c = (CreateObject)dynMethod.CreateDelegate(typeof(CreateObject));
                _constrcache.Add(objtype, c);
                return(c());
            }
            catch (Exception exc)
            {
                throw new Exception(string.Format("Failed to fast create instance for type '{0}' from assemebly '{1}'",
                                                  objtype.FullName, objtype.AssemblyQualifiedName), exc);
            }
        }