Exemple #1
0
        private static DynamicConstructor GetCachedConstructor(Type objectType)
        {
            DynamicConstructor dynamicConstructor = null;

            if (MethodCaller._ctorCache.TryGetValue(objectType, out dynamicConstructor))
            {
                return(dynamicConstructor);
            }
            lock (MethodCaller._ctorCache)
            {
                if (!MethodCaller._ctorCache.TryGetValue(objectType, out dynamicConstructor))
                {
                    ConstructorInfo constructor = objectType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
                    dynamicConstructor = DynamicMethodHandlerFactory.CreateConstructor(constructor);
                    MethodCaller._ctorCache.Add(objectType, dynamicConstructor);
                }
            }
            return(dynamicConstructor);
        }
 public DynamicMethodHandle(MethodInfo info, params object[] parameters)
 {
     if (info == null)
     {
         this.DynamicMethod = null;
     }
     else
     {
         this.MethodName = info.Name;
         ParameterInfo[] infoArray = info.GetParameters();
         int             length    = infoArray.Length;
         if ((length > 0) && (((length == 1) && infoArray[0].ParameterType.IsArray) || (infoArray[length - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)))
         {
             this.HasFinalArrayParam    = true;
             this.MethodParamsLength    = length;
             this.FinalArrayElementType = infoArray[length - 1].ParameterType;
         }
         this.DynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
     }
 }
Exemple #3
0
 public DynamicMemberHandle(FieldInfo info) : this(info.Name, info.FieldType, DynamicMethodHandlerFactory.CreateFieldGetter(info), DynamicMethodHandlerFactory.CreateFieldSetter(info))
 {
 }
Exemple #4
0
 public DynamicMemberHandle(PropertyInfo info) : this(info.Name, info.PropertyType, DynamicMethodHandlerFactory.CreatePropertyGetter(info), DynamicMethodHandlerFactory.CreatePropertySetter(info))
 {
 }