public static Functions.Functions GetFunction(FieldInfo field)
 {
     if (field.GetCustomAttribute<OkButtonAttribute>(false) != null)
         return Functions.Functions.Ok;
     if (field.GetCustomAttribute<CloseButtonAttribute>(false) != null)
         return Functions.Functions.Close;
     if (field.GetCustomAttribute<CancelButtonAttribute>(false) != null)
         return Functions.Functions.Cancel;
     return Functions.Functions.None;
 }
Beispiel #2
0
        public override IEnumerable<string> GetAttributesTextFor(FieldInfo field, Usage defaultUsage, ParsingPolicyAttribute[] parsingPolicies)
        {
            var res = new List<string>(base.GetAttributesTextFor(field, defaultUsage, parsingPolicies));

            var fieldType = field.FieldType;
            var renameRule = field.GetCustomAttribute<RenameAttribute>();
            string fieldName = field.GetCustomAttribute<NameAttribute>()?.Name ?? field.Name;

            if (!field.IsDefined<RefAttribute>())
            {
                if (field.IsPolymorphic())
                {
                    Type attributeType = !fieldType.IsArray || field.IsDefined<InlineAttribute>() ? typeof(XmlElementAttribute) : typeof(XmlArrayItemAttribute);
                    foreach (var t in field.GetKnownSerializableTypes())
                        res.Add(GetItemAttributeText(attributeType, t, renameRule));
                }
                else if (
                    field.FieldType.IsArray &&
                    !field.IsDefined<ConverterAttribute>() &&
                    !field.IsDefined<ParserAttribute>() &&
                    !parsingPolicies.Any(p => p.CanParse(field.FieldType)))
                {
                    Type attributeType = field.IsDefined<InlineAttribute>() ? typeof(XmlElementAttribute) : typeof(XmlArrayItemAttribute);
                    Type itemTypeName = field.FieldType.GetElementType();
                    res.Add(GetItemAttributeText(attributeType, itemTypeName, renameRule));
                }
            }

            var rawFieldType = field.GetRawFieldType(parsingPolicies);
            if (rawFieldType.IsSimple())
            {
                res.Add(AttributeBuilder.GetTextFor<XmlAttributeAttribute>(fieldName));
            }
            else if (!res.Any(a => a.Contains(nameof(XmlElementAttribute))))
            {
                 if (rawFieldType.IsArray)
                    res.Add(AttributeBuilder.GetTextFor<XmlArrayAttribute>(fieldName));
                 else
                    res.Add(AttributeBuilder.GetTextFor<XmlElementAttribute>(fieldName));
            }

            if (field.IsDefined<HiddenAttribute>())
                res.Add(AttributeBuilder.GetTextFor<XmlIgnoreAttribute>());

            return res.Where(a => a != null);
        }
        private string BuildConfigurationKey(FieldInfo constant, string variableName)
        {
            // Can make this polymorphic if the need arises
            if (constant.GetCustomAttribute<StaticKey>() != null)
            {
                return BuildStaticConfigurationKey(variableName);
            }

            return BuildEnvironmentConfigurationKey(variableName);
        }
        internal void Add(FieldInfo fi)
        {
            if (fi.IsInitOnly)
                return;

            if (fi.IsPrivate)
            { // require DataMemberAttribute
                if (fi.GetCustomAttribute<DataMemberAttribute>() == null)
                    return;
            }

            if (fi.GetCustomAttribute<IgnoreDataMemberAttribute>() != null)
                return;

            var right = makeFieldReader(new FieldFunctionInfo(fi));
            if (right == null)
                return;
            var left = Expression.Field(_pResult, fi);
            _bodyList.Add(Expression.Assign(left, right));
        }
Beispiel #5
0
        static string ToString(FieldInfo sourceField, object container)
        {
            object value = sourceField.GetValue(container);
            // Handle nullable types here
            if (value != null && Nullable.GetUnderlyingType(sourceField.FieldType) != null)
            {
                bool hasValue = (bool)sourceField.FieldType.GetProperty("HasValue").GetValue(value);
                if (hasValue) value = sourceField.FieldType.GetProperty("Value").GetValue(value);
            }

            ConverterAttribute converter = sourceField.GetCustomAttribute<ConverterAttribute>();
            if (converter != null)
                return converter.ToString(value, sourceField);
            else
                return value?.ToString();
        }
Beispiel #6
0
        public void Visit(string settingsNamespace, string fieldPath, FieldInfo rawSettingsField, object rawSettings)
        {
            var defaultAttr = rawSettingsField.GetCustomAttribute<DefaultAttribute>();
            if (defaultAttr != null)
            {
                if (!CanAssign(rawSettingsField, defaultAttr.Value))
                    throw new ConfigurationException("Invalid default field value for {0}.{1}: '{2}'.", rawSettingsField.DeclaringType.Name, rawSettingsField.Name, defaultAttr.Value);

                object targetValue = rawSettingsField.GetValue(rawSettings);
                if (targetValue == null)
                {
                    if (rawSettingsField.FieldType == typeof(string)) rawSettingsField.SetValue(rawSettings, defaultAttr.Value.ToString());
                    else rawSettingsField.SetValue(rawSettings, defaultAttr.Value);
                }
            }
        }
Beispiel #7
0
        public static string GetLocalizedEnumDescription(this Enum @enum)
        {
            System.Reflection.FieldInfo field = @enum.GetType().GetField(@enum.ToString());

            LocalizedDescriptionAttribute customAttribute = field.GetCustomAttribute <LocalizedDescriptionAttribute>(false);

            if (customAttribute != null)
            {
                string name = customAttribute.Description;
                if (!string.IsNullOrEmpty(name))
                {
                    return(name);
                }
            }
            return(field.Name);
        }
        private static ValueDescriptor CreateValueDescriptor(FieldInfo enumValue)
        {
            Debug.Assert(enumValue != null, "enumValue");

            string displayName = null;
            string description = null;

            var displayAttribute = enumValue.GetCustomAttribute<DisplayAttribute>();
            if (displayAttribute != null)
            {
                displayName = displayAttribute.Name;
                description = displayAttribute.Description;
            }

            displayName = displayName ?? enumValue.Name;

            return new ValueDescriptor(displayName, description);
        }
        /// <summary>
        /// Initializes a new instance of the TsProperty class with the specific CLR field.
        /// </summary>
        /// <param name="memberInfo">The CLR field represented by this instance of the TsProperty.</param>
        public TsProperty(FieldInfo memberInfo)
        {
            this.MemberInfo = memberInfo;
            this.Name = memberInfo.Name;

            if (memberInfo.ReflectedType.IsGenericType) {
                var definitionType = memberInfo.ReflectedType.GetGenericTypeDefinition();
                var definitionTypeProperty = definitionType.GetProperty(memberInfo.Name);
                if (definitionTypeProperty.PropertyType.IsGenericParameter) {
                    this.PropertyType = TsType.Any;
                } else {
                    this.PropertyType = memberInfo.FieldType.IsEnum ? new TsEnum(memberInfo.FieldType) : new TsType(memberInfo.FieldType);
                }
            } else {
                var propertyType = memberInfo.FieldType;
                if (propertyType.IsNullable()) {
                    propertyType = propertyType.GetNullableValueType();
                }

                this.PropertyType = propertyType.IsEnum ? new TsEnum(propertyType) : new TsType(propertyType);
            }

            var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);
            if (attribute != null) {
                if (!string.IsNullOrEmpty(attribute.Name)) {
                    this.Name = attribute.Name;
                }

                this.IsOptional = attribute.IsOptional;
            }

            this.IsIgnored = (memberInfo.GetCustomAttribute<TsIgnoreAttribute>(false) != null);

            if (memberInfo.IsLiteral && !memberInfo.IsInitOnly) {
                // it's a constant
                this.ConstantValue = memberInfo.GetValue(null);
            } else {
                // not a constant
                this.ConstantValue = null;
            }
        }
        public void Add(FieldInfo fi)
        {
            if (fi.IsInitOnly)
                return;

            if(fi.IsPrivate)
            { // require DataMemberAttribute
                if (fi.GetCustomAttribute<DataMemberAttribute>() == null)
                    return;
            }

            if (fi.GetCustomAttribute<IgnoreDataMemberAttribute>() != null)
                return;

            var prevField = Expression.Field(_pPrev, fi);
            var nextField = Expression.Field(_pNext, fi);
            var resultField = Expression.Field(_vResult, fi);
            var right = callMemberCombiner(fi, fi.FieldType, prevField, nextField);

            _bodyList.Add(Expression.Assign(resultField, right));
            _assingExist = true;
        }
Beispiel #11
0
 public static bool HDRColor(FieldInfo field)
 {
     HDRAttribute attr = field.GetCustomAttribute<HDRAttribute>();
     if(attr != null)
         return attr.HDR;
     else
         return false;
 }
Beispiel #12
0
 public static bool UseFieldAsShaderConstant(FieldInfo field)
 {
     UseAsShaderConstantAttribute attr = field.GetCustomAttribute<UseAsShaderConstantAttribute>();
     if(attr != null)
         return attr.UseAsShaderConstant;
     else
         return true;
 }
Beispiel #13
0
 public static void GetStepSize(FieldInfo field, ref int stepSize)
 {
     StepSizeAttribute attr = field.GetCustomAttribute<StepSizeAttribute>();
     if(attr != null)
         stepSize = attr.StepSizeInt;
 }
Beispiel #14
0
 public static void GetMaxValue(FieldInfo field, ref int maxValue)
 {
     MaxValueAttribute attr = field.GetCustomAttribute<MaxValueAttribute>();
     if(attr != null)
         maxValue = attr.MaxValueInt;
 }
 public static string Handler(FieldInfo field)
 {
     var attr = field.GetCustomAttribute<MoveToAttribute>(false);
     return attr?._pageName;
 }
        static string GenerateField(FieldInfo fieldInfo)
        {
            StringBuilder sb = new StringBuilder();
            AnnotateAttribute annotateAttribute = fieldInfo.GetCustomAttribute<AnnotateAttribute>(false);

            if (annotateAttribute != null)
                sb.AppendFormat("//{0} \n", annotateAttribute.Text);

            if (fieldInfo.FieldType.IsValueType)
            {
                if (fieldInfo.FieldType == typeof(Int64))
                {
                    sb.Append("int64 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(Int32))
                {
                    sb.Append("int32 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(Int16))
                {
                    sb.Append("int16 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(Byte))
                {
                    sb.Append("int8 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(UInt64))
                {
                    sb.Append("uint64 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(UInt32))
                {
                    sb.Append("uint32 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(UInt16))
                {
                    sb.Append("uint16 " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType == typeof(SByte))
                {
                    sb.Append("int8 " + fieldInfo.Name + ";\n");
                }
            }
            else if (fieldInfo.FieldType.IsClass)
            {
                if (fieldInfo.FieldType == typeof(string))
                {
                    sb.Append("string " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType.IsGenericType)
                {
                    sb.Append("list<" + fieldInfo.FieldType.GenericTypeArguments.ElementAt(0).Name + "> " + fieldInfo.Name + ";\n");
                }
                else if (fieldInfo.FieldType.IsSubclassOf(typeof(BaseType)))
                {
                    sb.Append(fieldInfo.FieldType.Name + " " + fieldInfo.Name + ";\n");
                }

            }

            return sb.ToString();
        }
Beispiel #17
0
 public static void GetGroup(FieldInfo field, ref string group)
 {
     GroupAttribute attr = field.GetCustomAttribute<GroupAttribute>();
     if(attr != null)
         group = attr.Group;
 }
Beispiel #18
0
 public static By Locator(FieldInfo field)
 {
     var locator = field.GetCustomAttribute<JFindByAttribute>(false);
     return locator?._locator;
 }
 public static SiteAttribute Get(FieldInfo field)
 {
     return field.GetCustomAttribute<SiteAttribute>(false);
 }
Beispiel #20
0
            public Parameter(FieldInfo info)
            {
                Name = info.Name;
                ParameterType = info.FieldType;

                var id = info.GetCustomAttribute<IdAttribute>();
                if (id == null)
                    throw new Exception("expected an Id() attribute");

                Id = id.Id;
            }
Beispiel #21
0
    private static bool NotUndoableField(FieldInfo field)
    {
#if NETFX_CORE
      var attr = field.GetCustomAttribute(typeof(NotUndoableAttribute));
      return (attr != null);
#else
      return Attribute.IsDefined(field, typeof(NotUndoableAttribute));
#endif
    }
 public static By GetFrame(FieldInfo field)
 {
     var frame = field.GetCustomAttribute<FrameAttribute>(false);
     return frame?._frameLocator;
 }
Beispiel #23
0
 public static void GetDisplayName(FieldInfo field, ref string displayName)
 {
     DisplayNameAttribute attr = field.GetCustomAttribute<DisplayNameAttribute>();
     if(attr != null)
         displayName = attr.DisplayName;
 }
Beispiel #24
0
 public static void GetHelpText(FieldInfo field, ref string helpText)
 {
     HelpTextAttribute attr = field.GetCustomAttribute<HelpTextAttribute>();
     if(attr != null)
         helpText = attr.HelpText;
 }
        // Return non-empty name specified in a [Display] attribute for a field, if any; field.Name otherwise.
        private static string GetDisplayName(FieldInfo field)
        {
            var display = field.GetCustomAttribute<DisplayAttribute>(inherit: false);
            if (display != null)
            {
                // Note [Display(Name = "")] is allowed.
                var name = display.GetName();
                if (name != null)
                {
                    return name;
                }
            }

            return field.Name;
        }
 public static By FindsByLocator(FieldInfo field)
 {
     var locator = field.GetCustomAttribute<FindsByAttribute>(false);
     return locator != null ? FindsByLocator(locator) : null;
 }
        // Return non-empty group specified in a [Display] attribute for a field, if any; string.Empty otherwise.
        private static string GetDisplayGroup(FieldInfo field)
        {
            var display = field.GetCustomAttribute<DisplayAttribute>(inherit: false);
            if (display != null)
            {
                // Note [Display(Group = "")] is allowed.
                var group = display.GetGroupName();
                if (group != null)
                {
                    return group;
                }
            }

            return string.Empty;
        }
Beispiel #28
0
        /// <summary>
        /// Create and return a new Link object for member
        /// </summary>
        /// <param name="field">The member</param>
        /// <param name="model">Model with the link</param>
        private static ModelDoc.Link DocumentLink(FieldInfo field, IModel model)
        {
            ModelDoc.Link link = new ModelDoc.Link();
            link.Name = field.Name;
            if (field.FieldType.IsGenericType && field.FieldType.GetInterface("IList") != null)
                link.TypeName = "List<" + field.FieldType.GenericTypeArguments[0].Name + ">";
            else
                link.TypeName = field.FieldType.Name;
            UnitsAttribute units = field.GetCustomAttribute<UnitsAttribute>();
            if (units != null)
                link.Units = units.ToString();
            DescriptionAttribute description = field.GetCustomAttribute<DescriptionAttribute>();
            if (description != null)
                link.Description = description.ToString();

            LinkAttribute linkAtt = field.GetCustomAttribute<LinkAttribute>();
            link.IsOptional = linkAtt.IsOptional;

            object linkedObject = field.GetValue(model);
            if (linkedObject != null)
            {
                if (linkedObject is IModel)
                    link.LinkedModelName = Apsim.FullPath(linkedObject as IModel);
                else
                {
                }
            }

            return link;
        }
Beispiel #29
0
 public static void GetMinValue(FieldInfo field, ref float minValue)
 {
     MinValueAttribute attr = field.GetCustomAttribute<MinValueAttribute>();
     if(attr != null)
         minValue = attr.MinValueFloat;
 }
Beispiel #30
0
 public static string GroupName(FieldInfo field)
 {
     var locator = field.GetCustomAttribute<JFindByAttribute>(false);
     return locator?.Group;
 }
Beispiel #31
0
        // Return non-empty name specified in a [Display] attribute for the given field, if any; field's name otherwise
        private static string GetDisplayName(FieldInfo field)
        {
            DisplayAttribute display = field.GetCustomAttribute<DisplayAttribute>(inherit: false);
            if (display != null)
            {
                string name = display.GetName();
                if (!String.IsNullOrEmpty(name))
                {
                    return name;
                }
            }

            return field.Name;
        }