예제 #1
0
파일: Profile.cs 프로젝트: microsoft/exsim
        public bool SetPropertyValue(string name, string value, XElement element)
        {
            ProfilePropertyInfo propertyInfo =
                (
                    from ProfilePropertyInfo info in this.Properties
                    where info.Name == name
                    select info
                ).FirstOrDefault();

            if (propertyInfo == null && element != null && element.Attribute("name") != null)
            {
                propertyInfo =
                    (
                        from ProfilePropertyInfo info in this.Properties
                        where info.Name.ToLower() == String.Format("{0}.{1}", name, element.Attribute("name").Value).ToLower()
                        select info
                    ).FirstOrDefault();
            }

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

            return(SetPropertyValue(propertyInfo, value, element));
        }
예제 #2
0
파일: Profile.cs 프로젝트: microsoft/exsim
        public bool SetPropertyValue(ProfilePropertyInfo property, string value, XElement element)
        {
            PropertyInfo match = property.PropertyInfo;

            if (property.IsPropertyDictionary && element != null)
            {
                IProfilePropertyDictionary dict = property.PropertyDictionary;

                dict.Set(element.Attribute("name").Value, value);

                return(true);
            }

            if (this.HasProperties.Contains(match.Name) == false)
            {
                throw new NotSupportedException(String.Format("The profile {0} does not use property {1}.", this.Symbol, match.Name));
            }

            Type propertyType = match.PropertyType;

            if (Nullable.GetUnderlyingType(propertyType) != null)
            {
                propertyType = Nullable.GetUnderlyingType(propertyType);

                if (value == null || value.Length == 0)
                {
                    match.SetValue(this, null, null);
                    return(true);
                }
            }

            if (propertyType == typeof(bool))
            {
                match.SetValue(this, Convert.ToBoolean(value), null);
            }
            else if (propertyType == typeof(uint))
            {
                match.SetValue(this, Convert.ToUInt32(value), null);
            }
            else if (propertyType.IsEnum)
            {
                match.SetValue(this, Enum.Parse(propertyType, value, true), null);
            }
            else
            {
                SetCustomProperty(new ProfilePropertyInfo(this, match), value);
            }

            return(true);
        }
예제 #3
0
파일: Profile.cs 프로젝트: microsoft/exsim
 public virtual void SetCustomProperty(ProfilePropertyInfo property, string value)
 {
     throw new NotSupportedException();
 }