Esempio n. 1
0
 public object this[string name]
 {
     get
     {
         return(this.fields[name]);
     }
     set
     {
         if (value != null && !(value is DBNull))
         {
             MapCore mapCore = this.GetMapCore();
             if (mapCore != null)
             {
                 Field field = (Field)mapCore.GroupFields.GetByName(name);
                 if (field == null)
                 {
                     throw new ArgumentException(SR.ExceptionFieldNameDoesNotExist(name));
                 }
                 if (!field.Type.IsInstanceOfType(value) && field.Type != Field.ConvertToSupportedType(value.GetType()))
                 {
                     throw new ArgumentException(SR.ExceptionFieldMustBeOfType(name, field.Type.ToString()));
                 }
                 field.SetValue(Field.ConvertToSupportedValue(value), this.fields);
                 mapCore.InvalidateRules();
                 mapCore.InvalidateDataBinding();
             }
             else
             {
                 this.fields[name] = Field.ConvertToSupportedValue(value);
             }
             this.InvalidateViewport();
         }
     }
 }
Esempio n. 2
0
        public NamedElement GetItemById(object itemID)
        {
            NamedElement namedElement = null;

            if (itemID is string)
            {
                namedElement = this.items.GetByName((string)itemID);
            }
            if (namedElement == null)
            {
                object           key        = Field.ConvertToSupportedValue(itemID);
                StringEnumerator enumerator = this.fieldNames.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string    current          = enumerator.Current;
                        Hashtable itemsByFiledName = this.GetItemsByFiledName(current);
                        namedElement = (itemsByFiledName[key] as NamedElement);
                        if (namedElement != null)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (namedElement == null && this.createNewItemForUnresoved)
            {
                namedElement = (NamedElement)Activator.CreateInstance(this.newItemsType);
                if (namedElement != null)
                {
                    if (itemID is string)
                    {
                        namedElement.Name = (string)itemID;
                    }
                    else
                    {
                        object           obj         = Field.ConvertToSupportedValue(itemID);
                        StringEnumerator enumerator2 = this.fieldNames.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                string current2 = enumerator2.Current;
                                if (this.fields[current2].Type == obj.GetType())
                                {
                                    this.SetFieldValue(namedElement, current2, obj);
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable2 = enumerator2 as IDisposable;
                            if (disposable2 != null)
                            {
                                disposable2.Dispose();
                            }
                        }
                    }
                    this.AddItem(namedElement);
                }
            }
            return(namedElement);
        }