public void Bool ()
		{
			DefaultValueAttribute dvat = new DefaultValueAttribute (true);
			Assert.IsTrue ((bool) dvat.Value, "Value");

			Assert.IsFalse (dvat.Equals (true), "Equals(true)");
			Assert.IsTrue (dvat.Equals (new DefaultValueAttribute (true)), "Equals(new)");

			Assert.AreEqual (true.GetHashCode (), dvat.GetHashCode (), "GetHashCode");
		}
		public void Null ()
		{
			DefaultValueAttribute dva = new DefaultValueAttribute (null);
			Assert.IsNull (dva.Value, "Value");

			Assert.IsFalse (dva.Equals (null), "Equals(null)");
			Assert.IsTrue (dva.Equals (new DefaultValueAttribute (null)), "Equals(new)");

			// != Value (null) GetHashCode
			Assert.IsTrue (dva.GetHashCode () != 0, "GetHashCode");
		}
        public static dynamic GetDefaultValue(this PropertyInfo property)
        {
            System.ComponentModel.DefaultValueAttribute defaultValue = property.GetAttribute <System.ComponentModel.DefaultValueAttribute>();

            if (defaultValue != null)
            {
                return(defaultValue.Value);
            }

            return(property.PropertyType.GetDefaultValue());
        }
示例#4
0
		public void Null ()
		{
			DefaultValueAttribute dva = new DefaultValueAttribute (null);
			Assert.IsNull (dva.Value, "Value");

			Assert.IsFalse (dva.Equals (null), "Equals(null)");

			DefaultValueAttribute dva2 = new DefaultValueAttribute (null);
			Assert.IsTrue (dva.Equals (dva2), "Equals(new)");

			Assert.AreEqual (dva.GetHashCode (), dva2.GetHashCode (), "GetHashCode");
		}
        private void ScanAnalysisServicesObjectForPropertiesWithNonDefaultValue(object o, string FriendlyPath)
        {
            if (o == null)
            {
                return;
            }

            PropertyInfo[] properties = o.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
            foreach (PropertyInfo prop in properties)
            {
                if (!prop.CanWrite || !prop.CanRead)
                {
                    continue;
                }

                object[] attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.DefaultValueAttribute), true);
                System.ComponentModel.DefaultValueAttribute defaultAttr = (System.ComponentModel.DefaultValueAttribute)(attrs.Length > 0 ? attrs[0] : null);
                if (defaultAttr == null)
                {
                    continue;                      //only show properties with defaults
                }
                attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true);
                System.ComponentModel.BrowsableAttribute browsableAttr = (System.ComponentModel.BrowsableAttribute)(attrs.Length > 0 ? attrs[0] : null);
                if (browsableAttr != null && !browsableAttr.Browsable)
                {
                    continue;                                                    //don't show attributes marked not browsable
                }
                attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.ReadOnlyAttribute), true);
                System.ComponentModel.ReadOnlyAttribute readOnlyAttr = (System.ComponentModel.ReadOnlyAttribute)(attrs.Length > 0 ? attrs[0] : null);
                if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                {
                    continue;                                                  //don't show attributes marked read only
                }
                if (prop.PropertyType.Namespace != "System" && !prop.PropertyType.IsPrimitive && !prop.PropertyType.IsValueType && !prop.PropertyType.IsEnum)
                {
                    object v = prop.GetValue(o, null);
                    if (v != null)
                    {
                        ScanAnalysisServicesObjectForPropertiesWithNonDefaultValue(v, FriendlyPath + " > " + prop.Name);
                    }
                    continue;
                }

                object value = prop.GetValue(o, null);
                if (defaultAttr.Value != null && !defaultAttr.Value.Equals(value))
                {
                    string sValue = (value == null ? string.Empty : value.ToString());
                    this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath, prop.Name, defaultAttr.Value.ToString(), sValue));
                }
            }
        }
示例#6
0
        internal OptionConfigurationProperty(PropertyInfo propertyInfo)
        {
            OptionConfigurationPropertyAttribute propertyAttribute = null;

            System.ComponentModel.TypeConverterAttribute converterAttribute = null;
            System.ComponentModel.DefaultValueAttribute  defaultAttribute   = null;

            foreach (var attribute in Attribute.GetCustomAttributes(propertyInfo))
            {
                if (attribute is OptionConfigurationPropertyAttribute)
                {
                    propertyAttribute = (OptionConfigurationPropertyAttribute)attribute;
                }
                else if (attribute is System.ComponentModel.DefaultValueAttribute)
                {
                    defaultAttribute = (System.ComponentModel.DefaultValueAttribute)attribute;
                }
                else if (attribute is System.ComponentModel.TypeConverterAttribute)
                {
                    converterAttribute = (System.ComponentModel.TypeConverterAttribute)attribute;
                }
            }

            _name        = propertyAttribute.Name;
            _elementName = propertyAttribute.ElementName;
            _type        = propertyAttribute.Type ?? propertyInfo.PropertyType;
            _behavior    = propertyAttribute.Behavior;

            if (propertyAttribute.Converter != null)
            {
                _converter = propertyAttribute.Converter;
            }
            else
            {
                if (converterAttribute != null && !string.IsNullOrEmpty(converterAttribute.ConverterTypeName))
                {
                    Type type = Type.GetType(converterAttribute.ConverterTypeName, false);

                    if (type != null)
                    {
                        _converter = Activator.CreateInstance(type, true) as TypeConverter;
                    }
                }
            }

            //注意:要最后设置默认属性的值
            this.DefaultValue = defaultAttribute != null ? defaultAttribute.Value : propertyAttribute.DefaultValue;
        }
		public void Post ()
		{
			DefaultValueAttribute fva = new DefaultValueAttribute (null);
			DispatcherSynchronizationContext dsc = new DispatcherSynchronizationContext ();
			// that would throw a NRE but we can't catch it
			//dsc.Post (null, this);

			bool complete = false;
			dsc.Post (delegate (object obj) {
				Assert.IsNull (obj, "Post");
				complete = true;
			}, null);

			EnqueueConditional (() => complete);
			EnqueueTestComplete ();
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="SchemaAttributes"/> class.
 /// </summary>
 /// <param name="name">The name of the property that contains these attributes.</param>
 /// <param name="converter">The converter that defines how to convert from .NET to XLIFF.</param>
 /// <param name="defaultValue">The default .NET value of the property.</param>
 /// <param name="hasValueIndicator">The indicator that defines how to determine if the value has data.</param>
 /// <param name="schema">Defines how to map the property to XLIFF.</param>
 /// <param name="inheritanceList">A list that defines how to inherit the value from ancestors.</param>
 /// <param name="outputDependencies">A list of property names that, when written, must be accompanied by the
 /// property to which this attribute is applied.</param>
 public SchemaAttributes(
     string name,
     ConverterAttribute converter,
     DefaultValueAttribute defaultValue,
     HasValueIndicatorAttribute hasValueIndicator,
     SchemaEntityAttribute schema,
     IEnumerable<InheritValueAttribute> inheritanceList,
     IEnumerable<ExplicitOutputDependencyAttribute> outputDependencies)
 {
     this.Converter = converter;
     this.DefaultValue = defaultValue;
     this.ExplicitOutputDependencies = new List<ExplicitOutputDependencyAttribute>(outputDependencies);
     this.HasValueIndicator = hasValueIndicator;
     this.InheritanceList = new List<InheritValueAttribute>(inheritanceList);
     this.Name = name;
     this.Schema = schema;
 }
        public ObjectPropertyDescriptor(MemberDescriptor descr, IContext context, IPropertyMap propertyMap, object obj, Attribute[] attrs)
            : base(descr, attrs)
        {
            this.realPropertyDescriptor = (PropertyDescriptor) descr;
            this.name = propertyMap.Name;
            this.displayName = propertyMap.Name;

            Attribute[] attribs = new Attribute[descr.Attributes.Count + 4];

            int i = 0;
            foreach (Attribute attrib in descr.Attributes)
            {
                attribs[i] = attrib;
                i++;
            }
            attribs[i] = new DescriptionAttribute(propertyMap.Name + " is a property.");
            attribs[i + 1] = new CategoryAttribute("");
            attribs[i + 2] = new DefaultValueAttribute(context.ObjectManager.GetOriginalPropertyValue(obj, propertyMap.Name));
            attribs[i + 3] = new ReadOnlyAttribute(propertyMap.IsReadOnly);

            attributes = new AttributeCollection(attribs);
        }
 private void InitDefaultValueFromTypeInfo(ConfigurationPropertyAttribute attribProperty, DefaultValueAttribute attribStdDefault)
 {
     object defaultValue = attribProperty.DefaultValue;
     if (((defaultValue == null) || (defaultValue == ConfigurationElement.s_nullPropertyValue)) && (attribStdDefault != null))
     {
         defaultValue = attribStdDefault.Value;
     }
     if (((defaultValue != null) && (defaultValue is string)) && (this._type != typeof(string)))
     {
         try
         {
             defaultValue = this.Converter.ConvertFromInvariantString((string) defaultValue);
         }
         catch (Exception exception)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Default_value_conversion_error_from_string", new object[] { this._name, exception.Message }));
         }
     }
     if ((defaultValue == null) || (defaultValue == ConfigurationElement.s_nullPropertyValue))
     {
         if (this._type == typeof(string))
         {
             defaultValue = string.Empty;
         }
         else if (this._type.IsValueType)
         {
             defaultValue = System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(this._type);
         }
     }
     this.SetDefaultValue(defaultValue);
 }
 private static IActionDefaultsFacet Create(DefaultValueAttribute attribute, ISpecification holder) {
     return attribute == null ? null : new ActionDefaultsFacetAnnotation(attribute.Value, holder);
 }
 private static void GenerateLocalAssignmentFromDefaultAttribute(this ILGenerator IL, DefaultValueAttribute[] attrs, LocalBuilder local)
 {
     if (attrs.Length > 0)
     {
         DefaultValueAttribute defaultAttribute = attrs[0];
         IL.LoadValue(defaultAttribute.Value);
         if ((defaultAttribute.Value != null) && (defaultAttribute.Value.GetType().IsValueType))
         {
             IL.Emit(OpCodes.Box, defaultAttribute.Value.GetType());
         }
         IL.Emit(OpCodes.Stloc, local);
     }
 }
 private static IPropertyDefaultFacet Create(DefaultValueAttribute attribute, IFacetHolder holder) {
     return attribute == null ? null : new PropertyDefaultFacetAnnotation(attribute.Value, holder);
 }
        /// <summary>
        /// Add design time attributes.
        /// </summary>
        /// <param name="builder">The assembly attribute table builder.</param>
        private static void AddAttributes(AttributeTableBuilder builder)
        {
            builder.AddCustomAttributes(
                typeof(SignInButton),
                new Attribute[] {
                    new DefaultPropertyAttribute("ClientId"),
                    new DefaultEventAttribute("SessionChanged"),
                    new ToolboxBrowsableAttribute(true),
                    new ToolboxCategoryAttribute(LiveServicesCategory),
                    new ToolboxTabNameAttribute(LiveServicesCategory)});

            EditorBrowsableAttribute browsableAlways = new EditorBrowsableAttribute(EditorBrowsableState.Always);
            CategoryAttribute categoryLive = new CategoryAttribute(LiveServicesCategory);

            DescriptionAttribute description = new DescriptionAttribute(StringResources.DescriptionBrandingType);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "Branding",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionClientId);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "ClientId",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionRedirectUri);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "RedirectUri",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionScopes);
            DefaultValueAttribute defaultValue = new DefaultValueAttribute("wl.signin");
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "Scopes",
                new Attribute[] { browsableAlways, categoryLive, description, defaultValue });

            description = new DescriptionAttribute(StringResources.DescriptionTextType);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "TextType",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionSigninText);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "SignInText",
                new Attribute[] { browsableAlways, categoryLive, description });

            description = new DescriptionAttribute(StringResources.DescriptionSignoutText);
            builder.AddCustomAttributes(
                typeof(SignInButton),
                "SignOutText",
                new Attribute[] { browsableAlways, categoryLive, description });            
        }
            /// <summary>Returns whether resetting the component changes the value of the component.</summary>
            /// <returns>true if resetting the component changes the value of the component; otherwise, false.</returns>
            /// <param name="component">The component to test for reset capability. </param>
            public override bool CanResetValue(object component)
            {
                DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)this.Attributes[typeof(DefaultValueAttribute)];

                return(defaultValueAttribute != null && defaultValueAttribute.Value == this.GetValue(component));
            }
        private static string GetDefaultValue(DefaultValueAttribute attr) {
            if (attr == null || attr.Value == null) 
                return String.Empty;

            return attr.Value.ToString();
        }
        private void InitDefaultValueFromTypeInfo(ConfigurationPropertyAttribute attribProperty,
                                                    DefaultValueAttribute attribStdDefault) {
            object defaultValue = attribProperty.DefaultValue;

            // If there is no default value there - try the other attribute ( the clr standard one )
            if ((defaultValue == null || defaultValue == ConfigurationElement.s_nullPropertyValue) &&
                (attribStdDefault != null)) {
                defaultValue = attribStdDefault.Value;
            }

            // If there was a default value in the prop attribute - check if we need to convert it from string
            if ((defaultValue != null) && (defaultValue is string) && (_type != typeof(string))) {
                // Use the converter to parse this property default value
                try {
                    defaultValue = Converter.ConvertFromInvariantString((string)defaultValue);
                }
                catch (Exception ex) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Default_value_conversion_error_from_string, _name, ex.Message));
                }
            }
            if (defaultValue == null || defaultValue == ConfigurationElement.s_nullPropertyValue) {
                if (_type == typeof(string)) {
                    defaultValue = String.Empty;
                }
                else if (_type.IsValueType) {
                    defaultValue = TypeUtil.CreateInstanceWithReflectionPermission(_type);
                }
            }
            SetDefaultValue(defaultValue);
        }