public T Get <T>(ResourceField <T> field, ResourceId id)
        {
            Debug.Assert(field != null);
            Debug.Assert(!id.IsDefault);

            return(_resourceMap[id].GetValue(field));
        }
        public ProjectData SetRaw(ResourceField field, ResourceId id, object value)
        {
            Debug.Assert(field != null);
            Debug.Assert(!id.IsDefault);

            var resource = _resourceMap[id].SetValue(field, value);

            return(WithResourceMap(_resourceMap.SetItem(resource.Id, resource)));
        }
        internal Resource SetResourceField(Resource resource, ResourceField field, object value)
        {
            Debug.Assert(resource != null);
            Debug.Assert(field != null);

            var project = Data.Set(field, resource.Id, value);

            return(UpdateProject(project).GetResource(resource.Id));
        }
        public object GetValue(ResourceField field)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (!_fields.TryGetValue(field, out var result))
            {
                return(field.DefaultValue);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public Resource SetValue(ResourceField field, object value)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (field.IsReadOnly ||
                value == null && !field.Type.IsClass ||
                value != null && !field.Type.IsAssignableFrom(value.GetType()))
            {
                throw new ArgumentException(nameof(value));
            }

            return(Project.SetResourceField(this, field, value));
        }
        public ProjectData Set(ResourceField field, ResourceId id, object value)
        {
            Debug.Assert(field != null);
            Debug.Assert(!id.IsDefault);

            if (field == ResourceFields.Name)
            {
                return(SetResourceName(this, id, (string)value));
            }
            else if (field == ResourceFields.Initials)
            {
                return(SetResourceInitials(this, id, (string)value));
            }
            else
            {
                return(SetRaw(field, id, value));
            }
        }
        public ResourceData SetValue(ResourceField field, object value)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (value == null && !field.Type.IsClass ||
                value != null && !field.Type.IsAssignableFrom(value.GetType()))
            {
                throw new ArgumentException(nameof(value));
            }

            var existingValue = GetValue(field);

            if (Equals(value, existingValue))
            {
                return(this);
            }

            var fields = _fields.SetItem(field, value);

            if (field == ResourceFields.Name && !HasValue(ResourceFields.Initials))
            {
                var name = (string)value;
                if (name != null && name.Length > 0)
                {
                    var initials = name.Substring(0, 1);
                    fields = fields.SetItem(ResourceFields.Initials, initials);
                }
            }
            else if (field == ResourceFields.Initials && !HasValue(ResourceFields.Name))
            {
                var initials = (string)value;
                if (initials != null)
                {
                    fields = fields.SetItem(ResourceFields.Name, initials);
                }
            }


            return(new ResourceData(fields));
        }
Ejemplo n.º 8
0
 public object GetValue(ResourceField field)
 {
     return(_data.GetValue(field));
 }
Ejemplo n.º 9
0
 public Resource SetValue <T>(ResourceField <T> field, T value)
 {
     return(SetValue((ResourceField)field, value));
 }
Ejemplo n.º 10
0
 public T GetValue <T>(ResourceField <T> field)
 {
     return((T)GetValue((ResourceField)field));
 }
Ejemplo n.º 11
0
 public bool HasValue(ResourceField field)
 {
     return(_data.HasValue(field));
 }
 public bool HasValue(ResourceField field)
 {
     return(_fields.ContainsKey(field));
 }