public override GUIContent GetNodeName()
        {
            var asset = target as FlowAsset;

            if (!asset)
            {
                return(new GUIContent("missing (FlowAsset)"));
            }
            string assetPath = AssetPath;

            if (string.IsNullOrEmpty(assetPath))
            {
                string name;
                name = NameAttribute.Get(asset.GetType(), null);
                if (string.IsNullOrEmpty(name))
                {
                    name = asset.GetType().Name;

                    if (name.EndsWith("FlowAsset", StringComparison.InvariantCultureIgnoreCase))
                    {
                        name = name.Substring(0, name.Length - 9);
                    }
                    else if (name.EndsWith("Asset"))
                    {
                        name = name.Substring(0, name.Length - 5);
                    }
                }
                return(new GUIContent(name, "FlowAsset"));
            }
            else
            {
                string fileName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
                return(new GUIContent(fileName + "(Asset)", "FlowAsset"));
            }
        }
Ejemplo n.º 2
0
        private Clickable GetClickable(string name)
        {
            var fields = this.GetFields(typeof(IClickable));
            var result = fields.FirstOrDefault(field => NameAttribute.GetElementName(field).ToLower().Contains(name.ToLower()));

            return((Clickable)result?.GetValue(this));
        }
Ejemplo n.º 3
0
        public Enum()
        {
            InitializeComponent();

            EnableUndo = true;

            // GetValuesだと順番が狂うため、GetFieldsで取得
            var  list        = new List <T>();
            var  fields      = typeof(T).GetFields();
            var  iconBitmaps = new List <Bitmap>();
            bool hasIcon     = false;

            foreach (var f in fields)
            {
                if (f.FieldType != typeof(T))
                {
                    continue;
                }

                var attributes = f.GetCustomAttributes(false);
                var name       = NameAttribute.GetName(attributes);
                if (name == string.Empty)
                {
                    name = f.ToString();
                }

                Bitmap icon          = null;
                var    iconAttribute = IconAttribute.GetIcon(attributes);
                if (iconAttribute != null)
                {
                    icon    = (Bitmap)Properties.Resources.ResourceManager.GetObject(iconAttribute.resourceName);
                    hasIcon = true;
                }

                Items.Add(name);
                list.Add((T)f.GetValue(null));
                iconBitmaps.Add(icon);
            }
            enums = list.ToArray();

            if (hasIcon)
            {
                // アイコンが存在するときはカスタム描画に切り替える
                icons       = iconBitmaps.ToArray();
                DrawMode    = DrawMode.OwnerDrawFixed;
                DrawItem   += new DrawItemEventHandler(Enum_OnDrawItem);
                ItemHeight += icons[0].Height / 2;
            }

            Reading = false;
            Writing = false;

            Reading = true;
            Read();
            Reading = false;

            HandleCreated        += new EventHandler(Enum_HandleCreated);
            HandleDestroyed      += new EventHandler(Enum_HandleDestroyed);
            SelectedIndexChanged += new EventHandler(Enum_SelectedIndexChanged);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取删除sql
 /// </summary>
 /// <returns></returns>
 public static string GetSqlDelete()
 {
     if (string.IsNullOrEmpty(sqlDelete))
     {
         #region 记录
         //Type type = typeof(T);
         //Type attributeType = typeof(NameAttribute);
         //NameAttribute nameAttributeTable = type.GetCustomAttribute(attributeType) as NameAttribute;
         //string tableName = type.Name;
         //if (nameAttributeTable != null)
         //    tableName = nameAttributeTable.Name;
         //PropertyInfo basePropertyInfo = type.BaseType.GetProperties().FirstOrDefault();
         //string baseColumnName = basePropertyInfo.Name;
         //if (basePropertyInfo.IsDefined(typeof(NameAttribute), true))
         //{
         //    NameAttribute columnNameAttribute = basePropertyInfo.GetCustomAttribute(typeof(NameAttribute), true) as NameAttribute;
         //    if (null != columnNameAttribute)
         //        baseColumnName = columnNameAttribute.Name;
         //}
         //sqlDelete = $@"DELETE FROM [{type.Name}] WHERE {baseColumnName}=@{baseColumnName}";
         #endregion
         Type          type               = typeof(T);
         Type          attributeType      = typeof(NameAttribute);
         NameAttribute nameAttributeTable = type.GetCustomAttribute(attributeType) as NameAttribute;
         string        tableName          = type.Name;
         if (nameAttributeTable != null)
         {
             tableName = nameAttributeTable.Name;
         }
         PropertyInfo basePropertyInfo = type.BaseType.GetProperties().FirstOrDefault();
         sqlDelete = $@"DELETE FROM [{tableName}] WHERE {basePropertyInfo.GetPropName()}=@{basePropertyInfo.Name}";
     }
     return(sqlDelete);
 }
Ejemplo n.º 5
0
        private static string PrintObject(object obj)
        {
            var result = new List <string>();

            obj.GetFields().ForEach(field =>
            {
                var value       = field.GetValue(obj);
                string strValue = null;
                if (value == null)
                {
                    strValue = "#NULL#";
                }
                else if (value is string)
                {
                    strValue = (string)value;
                }
                else if (value is IConvertible)
                {
                    strValue = value.ToString();
                }
                else if (ComplexAttribute.IsPresent(field))
                {
                    strValue = "#(#" + PrintObject(value) + "#)#";
                }
                if (strValue != null)
                {
                    result.Add($"{NameAttribute.GetElementName(field)}#:#{strValue}");
                }
            });
            return(result.Print("#;#"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// get the entitymodel for a type
        /// </summary>
        /// <param name="entitytype">type of entity for which to get a model</param>
        /// <returns>entity model for the specified entity type</returns>
        public EntityModel Get(Type entitytype)
        {
            EntityModel model;

            lock (modellock) {
                if (!models.TryGetValue(entitytype, out model))
                {
                    model = new EntityModel();
                    foreach (PropertyInfo property in entitytype.GetProperties())
                    {
                        if (Attribute.IsDefined(property, typeof(IgnoreDataMemberAttribute)))
                        {
                            continue;
                        }

                        string        mappingname = property.Name.ToLower();
                        NameAttribute name        = Attribute.GetCustomAttribute(property, typeof(NameAttribute)) as NameAttribute;
                        if (name != null)
                        {
                            mappingname = name.Name;
                        }
                        model.AddProperty(property, mappingname);
                    }

                    models[entitytype] = model;
                }
            }

            return(model);
        }
Ejemplo n.º 7
0
        public GuiLanguage()
        {
            InitializeComponent();

            EnableUndo = true;

            var list   = new List <Language>();
            var fields = typeof(Language).GetFields();

            foreach (var f in fields)
            {
                if (f.FieldType != typeof(Language))
                {
                    continue;
                }

                var name = NameAttribute.GetName(f.GetCustomAttributes(false));
                Items.Add(name);
                list.Add((Language)f.GetValue(null));
            }
            enums = list.ToArray();

            Reading = false;
            Writing = false;

            Reading = true;
            Read();
            Reading = false;

            HandleCreated            += new EventHandler(GuiLanguage_HandleCreated);
            HandleDestroyed          += new EventHandler(GuiLanguage_HandleDestroyed);
            SelectedIndexChanged     += new EventHandler(GuiLanguage_SelectedIndexChanged);
            SelectionChangeCommitted += new EventHandler(GuiLanguage_SelectionChangeCommitted);
        }
Ejemplo n.º 8
0
        public void Initialize(Type enumType)
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            // to avoid to change placesGetValues, use  GetFields
            var list   = new List <int>();
            var fields = enumType.GetFields();

            //var iconBitmaps = new List<Bitmap>();
            //bool hasIcon = false;

            foreach (var f in fields)
            {
                if (f.FieldType != enumType)
                {
                    continue;
                }

                var attributes = f.GetCustomAttributes(false);

                object name = f.ToString();


                var key     = KeyAttribute.GetKey(attributes);
                var nameKey = key + "_Name";
                if (string.IsNullOrEmpty(key))
                {
                    nameKey = f.FieldType.ToString() + "_" + f.ToString() + "_Name";
                }

                if (MultiLanguageTextProvider.HasKey(nameKey))
                {
                    name = new MultiLanguageString(nameKey);
                }
                else
                {
                    name = NameAttribute.GetName(attributes);
                    if (name.ToString() == string.Empty)
                    {
                        name = f.ToString();
                    }
                    //System.IO.File.AppendAllText("kv.csv", nameKey + "," + name.ToString() + "\r\n");
                }

                var iconAttribute = IconAttribute.GetIcon(attributes);
                if (iconAttribute != null)
                {
                    name = iconAttribute.code + name;
                }

                list.Add((int)f.GetValue(null));
                FieldNames.Add(name);
            }
            enums = list.ToArray();
        }
Ejemplo n.º 9
0
        public static BaseEnumItem[] enumToArray(Type source)
        {
            ArrayList <BaseEnumItem>       items        = new ArrayList <BaseEnumItem>();
            SortedList <int, BaseEnumItem> _sortedItems = new SortedList <int, BaseEnumItem>();
            int  sortIndex = 0;
            bool autoOrder = true;

            try
            {
                FieldInfo[] fields = source.GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public);
                foreach (FieldInfo field in fields)
                {
                    int    value = (int)field.GetValue(null);
                    string name  = Enum.GetName(source, value);
                    autoOrder = (field.GetCustomAttributes(typeof(OrderAttribute), false) != null);

                    foreach (Attribute attrib in field.GetCustomAttributes(true))
                    {
                        if (attrib is NameAttribute)
                        {
                            NameAttribute at = (NameAttribute)attrib;
                            name = at.Name;
                        }
                        if (attrib is OrderAttribute)
                        {
                            OrderAttribute at = (OrderAttribute)attrib;
                            sortIndex = at.Order;
                        }
                    }

                    items.put(new BaseEnumItem(value, name));

                    if (!autoOrder)
                    {
                        _sortedItems.Add(sortIndex, new BaseEnumItem(value, name));
                    }
                    else
                    {
                        _sortedItems.Add(sortIndex++, new BaseEnumItem(value, name));
                    }
                }

                if (_sortedItems.Count != 0)
                {
                    BaseEnumItem[] ret = new BaseEnumItem[_sortedItems.Count];
                    _sortedItems.Values.CopyTo(ret, 0);
                    return(ret);
                }

                return(items.toArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }
Ejemplo n.º 10
0
        private void CreateVisibilityControl(NameAttribute displayNameAttribute)
        {
            var visibilityControl = new ConfigVisibilityControl(_localController.GetLocalStrings <SDGuiStrings>(), _coreConfigSection, _buildController);

            visibilityControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);

            configItemPanel.Children.Add(visibilityControl);
        }
Ejemplo n.º 11
0
        public static Sensor Create(Sensor prototype, IdAttribute id, NameAttribute name, ParentIdAttribute parentId)
        {
            var newSensor = new Sensor(prototype);

            newSensor.IdAttribute.Value   = id;
            newSensor.NameAttribute.Value = name;
            newSensor.ParentId            = IdAttribute.Empty; // Root
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Convert contents of a NameType object to another form
 /// </summary>
 public static object ConvertName(object o)
 {
     if (o.GetType().IsEnum)
     {
         o = NameAttribute.GetName((Enum)o);
     }
     return(o);
 }
Ejemplo n.º 13
0
        private void SetName(FieldInfo viElement, ref VIElement instance)
        {
            var nameAttr = NameAttribute.GetName(viElement);

            instance.Name = (!string.IsNullOrEmpty(nameAttr))
                ? nameAttr
                : viElement.Name;
        }
Ejemplo n.º 14
0
        private void CreateCheckboxControl(NameAttribute displayNameAttribute, Binding b)
        {
            var boolItemControl = new ConfigBoolControl();

            boolItemControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            boolItemControl.SetBinding(ConfigBoolControl.ConfigItemValueProperty, b);

            configItemPanel.Children.Add(boolItemControl);
        }
Ejemplo n.º 15
0
        private void CreateColorpickerControl(NameAttribute displayNameAttribute, Binding b)
        {
            var colorControl = new ConfigColorControl();

            colorControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            colorControl.SetBinding(ConfigColorControl.ConfigItemValueProperty, b);

            configItemPanel.Children.Add(colorControl);
        }
Ejemplo n.º 16
0
        public void ParseNameAttributeTest()
        {
            //Parse tokens
            MarkupParser  markupParser        = new MarkupParser(Init("nametest"));
            NameAttribute parsedNameAttribute = markupParser.ParseNameAttribute();

            //Check Id Attribute
            Assert.AreEqual("nametest", parsedNameAttribute.GetName());
        }
Ejemplo n.º 17
0
        public Task <NameResult> MapAsync(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            NameAttribute attribute = method.GetCustomAttributes(typeof(NameAttribute), false).Cast <NameAttribute>().SingleOrDefault();

            return((attribute != null ? NameResult.NameMapped(attribute.Name) : NameResult.NameNotMapped()).AsCompletedTask());
        }
Ejemplo n.º 18
0
        public static string GetElementName(Type type)
        {
            NameAttribute name = type.GetCustomAttribute <NameAttribute>(false);

            if (name != null)
            {
                return(name.Name);
            }
            return(SplitCamelCase(type.Name));
        }
Ejemplo n.º 19
0
        private void CreateCheckboxListControl(NameAttribute displayNameAttribute, CheckBoxList sourceList, Binding b)
        {
            var checkBoxListControl = new ConfigCheckBoxListControl(_localController.GetLocalStrings <SDGuiStrings>());

            checkBoxListControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            checkBoxListControl.SourceList            = sourceList;
            checkBoxListControl.SetBinding(ConfigCheckBoxListControl.SelectedItemsProperty, b);

            configItemPanel.Children.Add(checkBoxListControl);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Parser for NameAttribute
        /// </summary>
        /// <returns>Parsed NameAttribute</returns>
        public NameAttribute ParseNameAttribute()
        {
            NameAttribute nameAttribute = new NameAttribute();

            //Get name token
            CurrentToken = TokenStream.NextToken();
            nameAttribute.SetName(CurrentToken.GetValue().ToString());

            return(nameAttribute);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Create signalR event bus
 /// </summary>
 /// <param name="config"></param>
 public SignalRServiceEndpoint(ISignalRServiceConfig config)
 {
     Resource = NameAttribute.GetName(typeof(THub));
     if (!string.IsNullOrEmpty(config?.SignalRConnString) && config.SignalRServerLess)
     {
         _serviceManager = new ServiceManagerBuilder().WithOptions(option => {
             option.ConnectionString     = config.SignalRConnString;
             option.ServiceTransportType = ServiceTransportType.Persistent;
         }).Build();
     }
 }
Ejemplo n.º 22
0
        public static EditableValue Create(object o, System.Reflection.PropertyInfo info)
        {
            var ret = new EditableValue();

            ret.Value = o;

            var p          = info;
            var attributes = p.GetCustomAttributes(false);

            var undo = attributes.Where(_ => _.GetType() == typeof(UndoAttribute)).FirstOrDefault() as UndoAttribute;

            if (undo != null && !undo.Undo)
            {
                ret.IsUndoEnabled = false;
            }
            else
            {
                ret.IsUndoEnabled = true;
            }

            var shown = attributes.Where(_ => _.GetType() == typeof(ShownAttribute)).FirstOrDefault() as ShownAttribute;

            if (shown != null && !shown.Shown)
            {
                ret.IsShown = false;
            }

            var selector_attribute = (from a in attributes where a is Data.SelectorAttribute select a).FirstOrDefault() as Data.SelectorAttribute;

            if (selector_attribute != null)
            {
                ret.SelfSelectorID = selector_attribute.ID;
            }

            // collect selected values
            var selectedAttributes = attributes.OfType <Data.SelectedAttribute>();

            if (selectedAttributes.Count() > 0)
            {
                if (selectedAttributes.Select(_ => _.ID).Distinct().Count() > 1)
                {
                    throw new Exception("Same IDs are required.");
                }

                ret.TargetSelectorID       = selectedAttributes.First().ID;
                ret.RequiredSelectorValues = selectedAttributes.Select(_ => _.Value).ToArray();
            }

            ret.Title       = NameAttribute.GetName(attributes);
            ret.Description = DescriptionAttribute.GetDescription(attributes);

            return(ret);
        }
Ejemplo n.º 23
0
        private static MenuItem CreateMenuItemFromCommands(Func <bool> onClicked)
        {
            var item       = new MenuItem();
            var attributes = onClicked.Method.GetCustomAttributes(false);
            var uniquename = UniqueNameAttribute.GetUniqueName(attributes);

            item.Label    = NameAttribute.GetName(attributes);
            item.Shortcut = Shortcuts.GetShortcutText(uniquename);
            item.Clicked += () => onClicked();

            return(item);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 静态构造函数初始化当前类特性名称
        /// </summary>
        static SqlCache()
        {
            Type type = typeof(T);

            tableName = type.Name;
            NameAttribute nameAttribute = type.GetCustomAttribute(typeof(NameAttribute), true) as NameAttribute;

            if (nameAttribute != null)
            {
                tableName = nameAttribute.Name;
            }
        }
Ejemplo n.º 25
0
        public void Initialize(Type enumType)
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            // to avoid to change placesGetValues, use  GetFields
            var list   = new List <int>();
            var fields = enumType.GetFields();

            //var iconBitmaps = new List<Bitmap>();
            //bool hasIcon = false;

            foreach (var f in fields)
            {
                if (f.FieldType != enumType)
                {
                    continue;
                }

                var attributes = f.GetCustomAttributes(false);
                var name       = NameAttribute.GetName(attributes);
                if (name == string.Empty)
                {
                    name = f.ToString();
                }

                //Bitmap icon = null;
                //var iconAttribute = IconAttribute.GetIcon(attributes);
                //if (iconAttribute != null)
                //{
                //	icon = (Bitmap)Properties.Resources.ResourceManager.GetObject(iconAttribute.resourceName);
                //	hasIcon = true;
                //}
                //
                //Items.Add(name);
                list.Add((int)f.GetValue(null));
                names.Add(name);
                //iconBitmaps.Add(icon);
            }
            enums = list.ToArray();

            //if (hasIcon)
            //{
            //	// アイコンが存在するときはカスタム描画に切り替える
            //	icons = iconBitmaps.ToArray();
            //	DrawMode = DrawMode.OwnerDrawFixed;
            //	DrawItem += new DrawItemEventHandler(Enum_OnDrawItem);
            //	ItemHeight += icons[0].Height / 2;
            //}
        }
Ejemplo n.º 26
0
        private void CreateTextboxControl(NameAttribute displayNameAttribute, RequiredAttribute requiredAttribute, Binding b)
        {
            var textItemControl = new ConfigTextControl();

            textItemControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            textItemControl.SetBinding(ConfigTextControl.ConfigItemValueProperty, b);
            textItemControl.WaterMarkText = requiredAttribute != null?_localController.GetLocalStrings <SDGuiStrings>().Mandatory : _localController.GetLocalStrings <SDGuiStrings>().Optional;

            textItemControl.WaterMarkColor = requiredAttribute != null ? (SolidColorBrush)TryFindResource("Color_FadedRed") : (SolidColorBrush)TryFindResource("Color_FadedGray");

            configItemPanel.Children.Add(textItemControl);
        }
Ejemplo n.º 27
0
 private bool FindClassTypeByNameAttr(String currentAttr, ref Type currentType)
 {
     foreach (Type currentClass in classesTypesLibrary)
     {
         NameAttribute attr = (NameAttribute)currentClass.GetCustomAttribute(typeof(NameAttribute));
         if ((attr != null) && (currentAttr == attr.Name))
         {
             currentType = currentClass;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 28
0
    /// <summary>
    /// 获取枚举的Name特性值
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="thisTypeValue">枚举值</param>
    /// <returns></returns>
    public static string GetEnumName <T>(T thisTypeValue) where T : struct
    {
        Type type = thisTypeValue.GetType();

        if (!type.IsEnum)
        {
               return("");
        }
        FieldInfo     info = type.GetField(thisTypeValue.ToString());
        NameAttribute attr = info.GetCustomAttribute(typeof(NameAttribute)) as NameAttribute;

        return(attr == null ? "" : attr.name);
    }
Ejemplo n.º 29
0
        private void CreateFilesystemControl(NameAttribute displayNameAttribute, RequiredAttribute requiredAttribute, ConfigEditorAttribute editorTypeAttribute, Binding b)
        {
            var fileSystemControl = new ConfigFileSystemControl();

            fileSystemControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            fileSystemControl.SetBinding(ConfigFileSystemControl.ConfigItemValueProperty, b);
            fileSystemControl.WaterMarkText = requiredAttribute != null?_localController.GetLocalStrings <SDGuiStrings>().Mandatory : _localController.GetLocalStrings <SDGuiStrings>().Optional;

            fileSystemControl.WaterMarkColor = requiredAttribute != null ? (SolidColorBrush)TryFindResource("Color_FadedRed") : (SolidColorBrush)TryFindResource("Color_FadedGray");
            fileSystemControl.IsFileSelector = editorTypeAttribute.Editor == EditorType.Filepicker;

            configItemPanel.Children.Add(fileSystemControl);
        }
Ejemplo n.º 30
0
        private void CreateComboboxControl(NameAttribute displayNameAttribute, RequiredAttribute requiredAttribute, ConfigEditorAttribute editorTypeAttribute, Binding b)
        {
            var dropDownControl = new ConfigComboBoxControl();

            dropDownControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName);
            dropDownControl.SourceList            = (ComboBoxList)Activator.CreateInstance(editorTypeAttribute.SourceListType);
            dropDownControl.SetBinding(ConfigComboBoxControl.SelectedValueProperty, b);
            dropDownControl.WaterMarkText = requiredAttribute != null?_localController.GetLocalStrings <SDGuiStrings>().Mandatory : _localController.GetLocalStrings <SDGuiStrings>().Optional;

            dropDownControl.WaterMarkColor = requiredAttribute != null ? (SolidColorBrush)TryFindResource("Color_FadedRed") : (SolidColorBrush)TryFindResource("Color_FadedGray");

            configItemPanel.Children.Add(dropDownControl);
        }