Esempio n. 1
0
        public DynamicMethodHandle(MethodInfo info, params object[] parameters)
        {
            if (info == null)
            {
                DynamicMethod = null;
            }
            else
            {
                MethodName = info.Name;
                ParameterInfo[] infoParams = info.GetParameters();
                object[]        inParams   = null;

                if (parameters == null)
                {
                    inParams = new object[] { null }
                }
                ;
                else
                {
                    inParams = parameters;
                }

                int pCount = infoParams.Length;
                if (pCount > 0 &&
                    ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
                     (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)))
                {
                    HasFinalArrayParam    = true;
                    MethodParamsLength    = pCount;
                    FinalArrayElementType = infoParams[pCount - 1].ParameterType;
                }
                DynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
            }
        }
Esempio n. 2
0
        private static DynamicConstructor GetCachedConstructor(Type objectType)
        {
            DynamicConstructor result = null;

            if (_ctorCache.TryGetValue(objectType, out result))
            {
                return(result);
            }

            lock (_ctorCache)
            {
                if (!_ctorCache.TryGetValue(objectType, out result))
                {
                    ConstructorInfo info = objectType.GetConstructor(ctorFlags, null, Type.EmptyTypes, null);
                    result = DynamicMethodHandlerFactory.CreateConstructor(info);
                    _ctorCache.Add(objectType, result);
                }
            }
            return(result);
        }
 public DynamicMemberHandle(FieldInfo info)
     : this(info.Name, info.FieldType, DynamicMethodHandlerFactory.CreateFieldGetter(info), DynamicMethodHandlerFactory.CreateFieldSetter(info))
 {
 }
 public DynamicMemberHandle(PropertyInfo info)
     : this(info.Name, info.PropertyType, DynamicMethodHandlerFactory.CreatePropertyGetter(info), DynamicMethodHandlerFactory.CreatePropertySetter(info))
 {
 }