Пример #1
0
        public object Instantiate(string typeName, params object[] args)
        {
            var type = _typeMap.ResolveType(typeName);

            if (type == null)
            {
                throw new TypeNotFound(typeName);
            }

            return(TryInvokeExtension.Try(
                       () => (type.IsValueType && args.Length == 0)
                                        ? FormatterServices.GetUninitializedObject(type)
                                        : type.GetConstructors().First(c => c.GetParameters().ParametersMatch(args)).Invoke(args)));
        }
Пример #2
0
        public void SetStaticField(string typeName, string fieldName, object value)
        {
            var type = _typeMap.ResolveType(typeName);

            if (type == null)
            {
                throw new TypeNotFound(typeName);
            }

            var field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);

            if (field == null)
            {
                throw new MemberNotFound(typeName, fieldName);
            }

            TryInvokeExtension.Try(
                () =>
            {
                field.SetValue(null, value);
                return(null);
            });
        }