Пример #1
0
        public static string CreateTable(System.Type SystemType)
        {
            int Seed = 1;

            foreach (var Attribute in SystemType.GetCustomAttributes(true))
            {
                if (Attribute is AutoAttribute)
                {
                    AutoAttribute AutoAttribute = (AutoAttribute)Attribute;
                    Seed = AutoAttribute.Seed;
                    break;
                }
            }

            string Query = "\nCREATE TABLE [dbo].[" + EncryptTableName(SystemType.Name) + "] ([ID] INT IDENTITY(" + Seed + ",1) NOT NULL PRIMARY KEY CLUSTERED); ";

            foreach (System.Reflection.PropertyInfo SystemAttribute in SystemType.GetProperties())
            {
                if (Attribute.IsDefined(SystemAttribute, typeof(NoDataAttribute)))
                {
                    continue;
                }

                if (SystemAttribute.Name != "ID")
                {
                    Query += AddColumn(SystemAttribute, SystemType.Name, "");
                }
            }
            return(Query);
        }
Пример #2
0
 static IEnumerable <Field> EnumerateQualifiedFields(Type type)
 {
     foreach (FieldInfo fieldInfo in EnumerateFieldInfos(type))
     {
         AutoAttribute autoAttribute = fieldInfo.GetCustomAttributes(true).Select(obj => obj as AutoAttribute).FirstOrDefault(att => att != null);
         if (autoAttribute != null)
         {
             yield return(new Field(fieldInfo, autoAttribute));
         }
     }
 }
Пример #3
0
        public static void SetComponentAutomatilcally(Component component)
        {
            var componentType = component.GetType();

            foreach (var field in Cache.GetFields(componentType))
            {
                FieldInfo     fieldInfo          = field.FieldInfo;
                AutoAttribute autoAttribute      = field.AutoAttribute;
                Type          fieldType          = fieldInfo.FieldType;
                Component     necessaryComponent = component.GetComponent(fieldType);
                if (necessaryComponent != null)
                {
                    // 何もする必要はない
                    // necessary to do nothing
                }
                else if (!autoAttribute.ShouldAddAutomatilcally)
                {
                    Debug.LogError($"cannot get {fieldType.Name}: Name ={component.gameObject.name}, Type ={component.GetType().Name}");
                }
                else
                {
                    Debug.Log($"add {fieldType.Name}: Name ={component.gameObject.name}, Type ={component.GetType().Name}");
                    necessaryComponent = component.gameObject.AddComponent(fieldType);

                    if (necessaryComponent == null)
                    {
                        Debug.LogError($"cannot add {fieldType.Name}: Name ={component.gameObject.name}, Type ={component.GetType().Name}");
                    }

                    var modifiedComponent = necessaryComponent as IModifiedComponent;
                    if (modifiedComponent != null)
                    {
                        modifiedComponent.Modify();
                    }
                }

                if (necessaryComponent != null)
                {
                    autoAttribute.SetDefault(necessaryComponent);
                    fieldInfo.SetValue(component, necessaryComponent);
                }
            }
        }
Пример #4
0
 public Field(FieldInfo fieldInfo, AutoAttribute autoAttribute)
 {
     this.FieldInfo     = fieldInfo;
     this.AutoAttribute = autoAttribute;
 }