Ejemplo n.º 1
0
        public bool TrySetMember(string name, object valueOrig, out string error)
        {
            error = null;
            object value = GetRalObject(valueOrig);

            try
            {
                if (IsDynamic)
                {
                    DynamicInvoker.SetValue(Object, name, value);
                    return(true);
                }

                var property = InformationOnTheTypes.FindProperty(Type, name);
                if (property == null)
                {
                    if (!FindInterfacePropertyAsObject(name, out property))
                    {
                        error = "Не найдено Свойство " + name;
                        return(false);
                    }
                }

                property.SetValue(Object, value);

                return(true);
            }
            catch (Exception e)
            {
                error = GetExceptionString("установки свойства", name, e);
            }
            return(false);
        }
        // Возвращает делегат для вызова внешнего события в 1С
        // Пример использования
        //Делегат=Ъ(Врап.ПолучитьДелегатВнешнегоСобытия1C());
        // У объекта Тест есть поле
        //  public Action<string, string, string> ВнешнееСобытие1С;
        // Которое мы установим
        //Тест.ВнешнееСобытие1С=Делегат.ПолучитьСсылку();
        // И ктоторое может быть вызвано при возникновении события
        // ВнешнееСобытие1С?.DynamicInvoke("Тестовый", "ТестовоеСообщение", значение);

        private static IPropertyOrFieldInfo FindProperty(object obj, string delegateName)
        {
            var T        = obj.GetType();
            var property = InformationOnTheTypes.FindProperty(T, delegateName);

            if (property == null)
            {
                throw new Exception("Не найдено Делегат  " + delegateName);
            }

            return(property);
        }
Ejemplo n.º 3
0
        private bool FindInterfacePropertyAsObject(string name, out IPropertyOrFieldInfo result)
        {
            result = null;

            if (!(IsType || Type.GetTypeInfo().IsInterface))
            {
                return(false);
            }

            result = InformationOnTheTypes.FindProperty(Object.GetType(), name);

            if (result == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        // получение свойства
        public bool TryGetMember(string name, out object result, out string error)
        {
            result = null;
            error  = null;
            try
            {
                if (IsDynamic)
                {
                    result = DynamicInvoker.GetValue(Object, name);
                    return(true);
                }

                if (IsEnum)
                {
                    result = Enum.Parse(Type, name);
                    return(true);
                }

                var property = InformationOnTheTypes.FindProperty(Type, name);
                if (property == null)
                {
                    if (!FindInterfacePropertyAsObject(name, out property))
                    {
                        error = "Не найдено Свойство " + name;
                        return(false);
                    }
                }

                result = property.GetValue(Object);

                return(true);
            }
            catch (Exception e)
            {
                error = GetExceptionString("получения свойства", name, e);
            }
            result = null;
            return(false);
        }