예제 #1
0
        public void Merge(Script script)
        {
            Dictionary <ScriptPropertyKey, FieldInfo> dictionary1 = new Dictionary <ScriptPropertyKey, FieldInfo>();
            Dictionary <string, FieldInfo>            dictionary2 = new Dictionary <string, FieldInfo>();

            foreach (FieldInfo fieldInfo in script.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if ((fieldInfo.FieldType.IsValueType || fieldInfo.FieldType.IsEnum || fieldInfo.FieldType == typeof(string)) && fieldInfo.GetCustomAttributes(typeof(ParameterAttribute), true).Length > 0)
                {
                    dictionary1.Add(new ScriptPropertyKey(fieldInfo.Name, fieldInfo.FieldType), fieldInfo);
                    if (fieldInfo.FieldType.IsEnum)
                    {
                        dictionary2[fieldInfo.Name] = fieldInfo;
                    }
                }
            }
            List <ScriptPropertyKey> list = new List <ScriptPropertyKey>();

            foreach (ScriptPropertyKey key in this.scriptProperties.Keys)
            {
                if (!dictionary1.ContainsKey(key))
                {
                    list.Add(key);
                }
            }
            foreach (ScriptPropertyKey key in list)
            {
                ScriptProperty scriptProperty = this.scriptProperties[key];
                if ((scriptProperty.Type == (Type)null || scriptProperty.Type.IsEnum) && dictionary2.ContainsKey(scriptProperty.Name))
                {
                    FieldInfo fieldInfo = dictionary2[scriptProperty.Name];
                    if (fieldInfo != (FieldInfo)null && Enum.IsDefined(fieldInfo.FieldType, scriptProperty.Value.ToString()))
                    {
                        scriptProperty.Type  = fieldInfo.FieldType;
                        scriptProperty.Value = Enum.Parse(fieldInfo.FieldType, scriptProperty.Value.ToString());
                        this.scriptProperties.Add(new ScriptPropertyKey(scriptProperty.Name, scriptProperty.Type), scriptProperty);
                    }
                }
                this.scriptProperties.Remove(key);
            }
            foreach (KeyValuePair <ScriptPropertyKey, FieldInfo> keyValuePair in dictionary1)
            {
                ScriptProperty scriptProperty;
                if (this.scriptProperties.ContainsKey(keyValuePair.Key))
                {
                    scriptProperty = this.scriptProperties[keyValuePair.Key];
                }
                else
                {
                    scriptProperty = this.CreateProperty(keyValuePair.Value, script);
                    this.scriptProperties.Add(new ScriptPropertyKey(scriptProperty.Name, scriptProperty.Type), scriptProperty);
                }
                this.UpdateValue(scriptProperty, keyValuePair.Value.GetValue(script));
                this.UpdateAttributes(keyValuePair.Value, scriptProperty);
            }
        }
예제 #2
0
 private void UpdateValue(ScriptProperty property, object codeValue)
 {
     if (property.CodeValue == null)
     {
         property.CodeValue = codeValue;
     }
     if (this.EqualValues(property.CodeValue, codeValue))
     {
         return;
     }
     property.Value     = codeValue;
     property.CodeValue = codeValue;
 }
예제 #3
0
        private void UpdateAttributes(FieldInfo field, ScriptProperty scriptProperty)
        {
            object[]           customAttributes   = field.GetCustomAttributes(typeof(ParameterAttribute), true);
            ParameterAttribute parameterAttribute = (ParameterAttribute)null;

            if (customAttributes.Length > 0)
            {
                parameterAttribute = (ParameterAttribute)customAttributes[0];
            }
            if (parameterAttribute != null)
            {
                scriptProperty.Category    = parameterAttribute.Category;
                scriptProperty.Description = parameterAttribute.Description;
            }
            else
            {
                scriptProperty.Category    = "";
                scriptProperty.Description = "";
            }
        }
예제 #4
0
		public ScriptPropertyDescriptor(ScriptProperty property)
      : base(property.Name, null)
		{
			this.property = property;
		}
예제 #5
0
 public ScriptPropertyDescriptor(ScriptProperty property)
     : base(property.Name, null)
 {
     this.property = property;
 }
예제 #6
0
		private void UpdateAttributes(FieldInfo field, ScriptProperty scriptProperty)
		{
			object[] customAttributes = field.GetCustomAttributes(typeof(ParameterAttribute), true);
			ParameterAttribute parameterAttribute = (ParameterAttribute)null;
			if (customAttributes.Length > 0)
				parameterAttribute = (ParameterAttribute)customAttributes[0];
			if (parameterAttribute != null)
			{
				scriptProperty.Category = parameterAttribute.Category;
				scriptProperty.Description = parameterAttribute.Description;
			}
			else
			{
				scriptProperty.Category = "";
				scriptProperty.Description = "";
			}
		}
예제 #7
0
		private void UpdateValue(ScriptProperty property, object codeValue)
		{
			if (property.CodeValue == null)
				property.CodeValue = codeValue;
			if (this.EqualValues(property.CodeValue, codeValue))
				return;
			property.Value = codeValue;
			property.CodeValue = codeValue;
		}