private void SetAttributeValues(Dictionary <string, string> attributes, object entry) { SimpleConfigurationAttribute simpleConfigurationAttribute; lock (SimpleConfiguration <T> .simpleConfigurationTable) { simpleConfigurationAttribute = SimpleConfiguration <T> .simpleConfigurationTable[entry.GetType()]; } ulong num = simpleConfigurationAttribute.RequiredMask; foreach (KeyValuePair <string, string> keyValuePair in attributes) { SimpleConfigurationPropertyAttribute simpleConfigurationPropertyAttribute = simpleConfigurationAttribute.TryGetProperty(keyValuePair.Key); if (simpleConfigurationPropertyAttribute == null) { this.ThrowParserException(); } object value = this.ConvertToStrongType(simpleConfigurationPropertyAttribute.Type, keyValuePair.Value); simpleConfigurationPropertyAttribute.SetValue(entry, value); if (simpleConfigurationPropertyAttribute.IsRequired) { num &= ~simpleConfigurationPropertyAttribute.PropertyMask; } } if (num != 0UL) { this.ThrowParserException(); } }
protected virtual void AddConfiguration(Type configurationType) { lock (SimpleConfiguration <T> .simpleConfigurationTable) { if (!SimpleConfiguration <T> .simpleConfigurationTable.ContainsKey(configurationType)) { object[] customAttributes = configurationType.GetCustomAttributes(typeof(SimpleConfigurationAttribute), false); if (customAttributes == null || customAttributes.Length == 0) { throw new OwaNotSupportedException("A SimpleConfigurationAttribute should be defined on the type"); } SimpleConfigurationAttribute simpleConfigurationAttribute = (SimpleConfigurationAttribute)customAttributes[0]; PropertyInfo[] properties = configurationType.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo propertyInfo in properties) { object[] customAttributes2 = propertyInfo.GetCustomAttributes(typeof(SimpleConfigurationPropertyAttribute), false); if (customAttributes2 != null && customAttributes2.Length != 0) { SimpleConfigurationPropertyAttribute simpleConfigurationPropertyAttribute = (SimpleConfigurationPropertyAttribute)customAttributes2[0]; simpleConfigurationPropertyAttribute.PropertyInfo = propertyInfo; simpleConfigurationAttribute.AddProperty(simpleConfigurationPropertyAttribute); } } SimpleConfiguration <T> .simpleConfigurationTable.Add(configurationType, simpleConfigurationAttribute); } } }
internal SimpleConfigurationPropertyAttribute TryGetProperty(string propertyName) { SimpleConfigurationPropertyAttribute result = null; if (this.propertyTable.TryGetValue(propertyName, out result)) { return(result); } return(null); }
internal void AddProperty(SimpleConfigurationPropertyAttribute property) { if (this.propertyCount >= 64) { throw new OwaNotSupportedException(string.Format("SimpleConfiguration doesn't support types with more than {0} properties", 64)); } ulong num = 1UL << this.propertyCount; property.PropertyMask = num; if (property.IsRequired) { this.requiredMask |= num; } this.propertyTable.Add(property.Name, property); this.propertyCount++; }