Ejemplo n.º 1
0
 public static bool JsonReadBoolean(JSONObject data, string fieldName, bool defaultValue = false)
 {
     if (!data.Contains(fieldName))
     {
         return(defaultValue);
     }
     return((bool)data[fieldName]);
 }
Ejemplo n.º 2
0
 public static string JsonReadString(JSONObject data, string fieldName, string defaultValue = "")
 {
     if (!data.Contains(fieldName))
     {
         return(defaultValue);
     }
     return(data[fieldName] as string);
 }
Ejemplo n.º 3
0
 public static int JsonReadInt(JSONObject data, string fieldName, int defaultValue = 0)
 {
     if (!data.Contains(fieldName))
     {
         return(defaultValue);
     }
     return((int)(double)data[fieldName]);
 }
Ejemplo n.º 4
0
    public override void PreprocessDirective(string directiveName, System.Collections.IDictionary attributes)
    {
        if (attributes.Contains(WhiteSpaceDirectiveName))
        {
            _whiteSpaceCleaning = (WhiteSpaceCleaning)Enum.Parse(typeof(WhiteSpaceCleaning), (string)attributes[WhiteSpaceDirectiveName]);
            attributes.Remove(WhiteSpaceDirectiveName);
        }

        base.PreprocessDirective(directiveName, attributes);
    }
Ejemplo n.º 5
0
        internal static bool TryGetValue(JSONObject data, string key, out object value)
        {
            value = null;
            if (data == null || !data.Contains(key))
            {
                return(false);
            }

            value = data[key];
            return(true);
        }
Ejemplo n.º 6
0
        private string FindObjectFieldName(string name, System.Collections.IDictionary value)
        {
            if (value.Contains(name))
            {
                return(name);
            }

            name = SerializationHelper.SnakeCaseToPascalCase(name);

            if (value.Contains(name))
            {
                return(name);
            }

            name = SerializationHelper.PascalCaseToSnakeCase(name);

            if (value.Contains(name))
            {
                return(name);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public bool FilterAttributes(System.ComponentModel.IComponent component, System.Collections.IDictionary attributes)
        {
            if (oldService != null)
            {
                oldService.FilterAttributes(component, attributes);
            }

            // Creates a designer attribute to compare its TypeID with the TypeID of existing attributes of the component.
            DesignerAttribute da = new DesignerAttribute(typeof(ColorCycleButtonDesigner));

            // Adds the designer attribute if the attribute collection does not contain a DesignerAttribute of the same TypeID.
            if (component is System.Windows.Forms.Button && attributes.Contains(da.TypeId))
            {
                attributes[da.TypeId] = da;
            }
            return(true);
        }
Ejemplo n.º 8
0
 protected override void OnBeforeUninstall(System.Collections.IDictionary savedState)
 {
     base.OnBeforeUninstall(savedState);
     if (savedState.Contains(ArrayKey))
     {
         string[] files = savedState[ArrayKey] as string[];
         if (files != null)
         {
             foreach (string file in files)
             {
                 try
                 {
                     File.Delete(file);
                 }
                 catch { }
             }
         }
     }
 }
Ejemplo n.º 9
0
        protected static T GetOption <T>(SC.IDictionary options, string name, T defVal)
        {
            if (options == null || !options.Contains(name))
            {
                return(defVal);
            }
            object v = options[name];

            if (typeof(T).IsAssignableFrom(v.GetType()))
            {
                return((T)v);
            }
            if (typeof(T).IsEnum)
            {
                return((T)Enum.Parse(typeof(T), Convert.ToString(v), true));
            }
            else
            {
                return((T)Convert.ChangeType(v, typeof(T)));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 根据Id得到实体
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public object Get(object Id)
        {
            if (Id == null)
            {
                throw new ArgumentNullException("Id should not be null!");
            }

            if (m_buffers == null)
            {
                Load();
            }

            if (m_buffers.Contains(Id))
            {
                return(m_buffers[Id]);
            }
            else
            {
                //throw new ArgumentException("There is no " + this.PersistentClass + " with id = " + Id);
                return(null);
            }
        }
Ejemplo n.º 11
0
            private static void DeepMergeInto(JSONObject destination, JSONObject source)
            {
                if (destination == null)
                {
                    throw new ArgumentNullException(nameof(destination));
                }
                if (source == null)
                {
                    throw new ArgumentNullException(nameof(source));
                }

                foreach (DictionaryEntry pair in source)
                {
                    if (destination.Contains(pair.Key))
                    {
                        var value        = destination[pair.Key];
                        var firstObject  = value as JSONObject;
                        var secondObject = pair.Value as JSONObject;
                        if (firstObject != null && secondObject != null)
                        {
                            DeepMergeInto(firstObject, secondObject);
                            continue;
                        }

                        var firstArray  = value as IList;
                        var secondArray = pair.Value as IList;
                        if (firstArray != null && secondArray != null)
                        {
                            DeepMergeArray(firstArray, secondArray);
                            continue;
                        }
                    }

                    destination[pair.Key] = DeepClone(pair.Value);
                }
            }