示例#1
0
    public TypeTool GetTypeTool(int idItem)
    {
        TypeTool typeTool = (TypeTool)idItem;

        switch (typeTool)
        {
        case TypeTool.AxePrimitive: typeTool = TypeTool.AxePrimitive; break;

        case TypeTool.Axe: typeTool = TypeTool.Axe; break;

        case TypeTool.AxeMetal: typeTool = TypeTool.AxeMetal; break;

        case TypeTool.PickPrimitive: typeTool = TypeTool.PickPrimitive; break;

        case TypeTool.Pick: typeTool = TypeTool.Pick; break;

        case TypeTool.PickMetal: typeTool = TypeTool.PickMetal; break;

        case TypeTool.SwordWood: typeTool = TypeTool.SwordWood; break;

        case TypeTool.SwordLegend: typeTool = TypeTool.SwordLegend; break;

        case TypeTool.SwordMetal: typeTool = TypeTool.SwordMetal; break;

        default:
            typeTool = TypeTool.None;
            break;
        }
        return(typeTool);
    }
示例#2
0
        public void FindValidatorTypeFromReferences()
        {
            var targetType           = typeof(User);
            var validatorGenericType = typeof(IValidator <>).MakeGenericType(new[] { targetType });

            validatorGenericType.IsGenericType.Should().Be.True();

#if !SILVERLIGHT
            var validatorConcreteType =
                AppDomain.CurrentDomain
                .GetAssemblies()
                .SelectMany(asm => asm.GetTypes())
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorGenericType));
#else
            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .Where(type => RwType.IsSameOrSubclassOrImplementedOf(type, validatorGenericType))
                .FirstOrDefault();
#endif

            validatorConcreteType.Should().Not.Be.Null();

            validatorConcreteType.Should().Be(typeof(UserValidator));
        }
示例#3
0
        /// <summary>
        /// 지정한 객체가 Numeric 수형이여야 합니다. Numeric 수형이 아니면 예외를 발생시킨다.
        /// </summary>
        /// <param name="value">검사할 값</param>
        /// <param name="valueName">명칭</param>
        /// <exception cref="InvalidOperationException">값이 Numeric 수형이 아닌 경우</exception>
        public static void ShouldBeNumeric(this object value, string valueName)
        {
            if (value != null && TypeTool.IsNumeric(value))
            {
                return;
            }

            throw new InvalidOperationException(string.Format(SR.IsNotNumeric, valueName, value));
        }
示例#4
0
        /// <summary>
        /// 지정한 수형이 Numeric 수형이어야 합니다.
        /// </summary>
        /// <param name="type">검사할 수형</param>
        /// <exception cref="InvalidOperationException">값이 Numeric 수형이 아닌 경우</exception>
        public static void ShouldBeNumericType(this Type type)
        {
            type.ShouldNotBeNull("type");

            if (TypeTool.IsNumericType(type))
            {
                return;
            }

            throw new InvalidOperationException(string.Format(SR.IsNotNumeric, type.Name, type));
        }
示例#5
0
 public void SetActiveTool(TypeTool typeToolActive)
 {
     for (int i = 0; i < listTools.Count; i++)
     {
         if (listTools[i].TypeTool == typeToolActive)
         {
             listTools[i].Tool.SetActive(true);
         }
         else
         {
             listTools[i].Tool.SetActive(false);
         }
     }
 }
        private static void GenerateXmlAttributes <T>(XmlWriter writer, IDynamicAccessor accessor, T instance) where T : IChartObject
        {
            foreach (var propertyName in accessor.GetPropertyNames())
            {
                var propertyValue = accessor.GetPropertyValue(instance, propertyName);
                if (propertyValue != null)
                {
                    Type propertyType = accessor.GetPropertyType(propertyName);

                    if (propertyType.IsSimpleType() || propertyType.IsValueType)
                    {
                        if (IsDebugEnabled)
                        {
                            log.Debug("Property name={0}, type={1}, value={2}", propertyName, propertyType, propertyValue);
                        }

                        // NOTE : Color인 경우는 HexString으로, Enum 값은 HashCode 값으로...
                        if (propertyType == typeof(Color?))
                        {
                            var color = (Color?)propertyValue;
                            writer.WriteAttributeString(propertyName, color.Value.ToHexString());
                        }
                        else if (propertyType.IsEnum)
                        {
                            writer.WriteAttributeString(propertyName, propertyValue.GetHashCode().ToString());
                        }
                        else
                        {
                            writer.WriteAttributeString(propertyName, propertyValue.ToString());
                        }
                    }
                    else if (propertyType.IsSameOrSubclassOf(typeof(ChartAttributeBase)))
                    {
                        var accessor2 = DynamicAccessorFactory.CreateDynamicAccessor(propertyType, false);
                        GenerateXmlAttributes(writer, accessor2, propertyValue as ChartAttributeBase);
                    }
                    else if (TypeTool.IsSameOrSubclassOrImplementedOf(propertyType, typeof(IEnumerable)))
                    {
                        // Nothing to do.
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("지원하지 않는 속성입니다.  property name={0}, type={1}", propertyName,
                                                                      propertyType.FullName));
                    }
                }
            }
        }
示例#7
0
        public static string GetSqlType(Type type)
        {
            DbTypeBase res;

            if (type == typeof(SqlString))
            {
                res = new DbTypeString();
            }
            else if (type == typeof(SqlInt32))
            {
                res = new DbTypeInt {
                    Bytes = 4
                }
            }
            ;
            else if (type == typeof(SqlInt16))
            {
                res = new DbTypeInt {
                    Bytes = 2
                }
            }
            ;
            else if (type == typeof(SqlInt64))
            {
                res = new DbTypeInt {
                    Bytes = 8
                }
            }
            ;
            else if (type == typeof(SqlDecimal))
            {
                res = new DbTypeNumeric();
            }
            else
            {
                res = TypeTool.GetDatAdminType(type);
            }

            if (res is DbTypeString)
            {
                var stype = (DbTypeString)res;
                stype.Length    = 4000;
                stype.IsUnicode = true;
            }
            return(MsSqlDialect.Instance.GenericTypeToSpecific(res).ToString());
        }
示例#8
0
 public bool TryChangeTool(TypeTool typeTool)
 {
     if (typeTool == TypeTool.Nothing)
     {
         CurrentTool = null;
         return(true);
     }
     foreach (var tool in Tools)
     {
         if (tool.GetToolType() == typeTool)
         {
             CurrentTool = tool;
             return(true);
         }
     }
     return(false);
 }
示例#9
0
        public void FindValidatorType()
        {
            var targetType           = typeof(User);
            var validatorGenericType = typeof(IValidator <>).MakeGenericType(new[] { targetType });

            validatorGenericType.IsGenericType.Should().Be.True();

            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorGenericType));

            validatorConcreteType.Should().Not.Be.Null();

            validatorConcreteType.Should().Be(typeof(UserValidator));
        }
示例#10
0
    // Update is called once per frame
    void Update()
    {
        #region Test
        if (isMethold_SetActiveTool)
        {
            isMethold_SetActiveTool = false;
            weapon.SetActiveTool(typeToolActiveTest);
        }

        if (isMethold_GetTypeTool)
        {
            isMethold_GetTypeTool = false;
            returnTypeTool        = weapon.GetTypeTool(idItem);

            returnTypeTool = returnTypeTool;
        }
        #endregion
    }
示例#11
0
        /// <summary>
        /// IValidator<T> 형식을 구현한 Validator의 인스턴스를 제공합니다.
        /// </summary>
        /// <param name="validatorType"></param>
        /// <returns></returns>
        public override IValidator CreateInstance(Type validatorType)
        {
            // NOTE: http://docs.castleproject.org/Windsor.Referencing-types-in-XML.ashx

            if (IoC.IsInitialized && IoC.Container.Kernel.HasComponent(validatorType))
            {
                if (IsDebugEnabled)
                {
                    log.Debug("Validator 수형 [{0}] 을 구현한 Concrete Class를 Windsor Container로부터 인스턴싱합니다...", validatorType);
                }

                var result = IoC.Resolve(validatorType);

                if (result != null)
                {
                    return(result as IValidator);
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("Validator 수형 [{0}] 을 구현한 Concrete Class를 Assembly에서 찾아서 인스턴싱합니다...", validatorType);
            }

            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorType));

            if (validatorConcreteType != null)
            {
                return(CreateValidatorInstance(validatorConcreteType));
            }

#if !SILVERLIGHT
            validatorConcreteType =
                AppDomain.CurrentDomain
                .GetAssemblies()
                .SelectMany(asm => asm.GetTypes())
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorType));
#endif
            return(CreateValidatorInstance(validatorConcreteType));
        }
示例#12
0
 public int GetInt(string session, string key, int defaultValue = 0)
 {
     return(TypeTool.ToInt(GetString(session, key, ""), defaultValue));
 }
示例#13
0
 public float GetFloat(string session, string key, float defaultValue = 0)
 {
     return(TypeTool.ToFloat(GetString(session, key, ""), defaultValue));
 }
示例#14
0
 public double GetDouble(string session, string key, double defaultValue = 0)
 {
     return(TypeTool.ToDouble(GetString(session, key, ""), defaultValue));
 }
示例#15
0
        protected internal static NSJSValue ToObject(NSJSVirtualMachine machine, object obj)
        {
            if (machine == null)
            {
                return(null);
            }
            if (obj == null)
            {
                return(NSJSValue.Null(machine));
            }
            Type       owner     = obj.GetType();
            NSJSObject objective = NSJSObject.New(machine);

            foreach (MemberInfo mi in InternalCheckKeyMembers(owner).Values)
            {
                PropertyInfo pi    = mi as PropertyInfo;
                FieldInfo    fi    = mi as FieldInfo;
                object       value = null;
                Type         clazz = null;
                string       key   = mi.Name;
                if (pi != null)
                {
                    clazz = pi.PropertyType;
                    value = pi.GetValue(obj, null);
                }
                else
                {
                    clazz = fi.FieldType;
                    value = fi.GetValue(obj);
                }
                NSJSValue result = null;
                do
                {
                    if (value == null)
                    {
                        break;
                    }
                    Type element = TypeTool.GetArrayElement(clazz);
                    if (element == null && value is IList)
                    {
                        result = ArrayAuxiliary.ToArray(machine, element, (IList)value);
                    }
                    else if (TypeTool.IsBasicType(clazz) && !TypeTool.IsIPAddress(clazz))
                    {
                        result = value.As(machine);
                    }
                    else
                    {
                        result = ToObject(machine, value);
                    }
                } while (false);
                if (result == null)
                {
                    result = NSJSValue.Null(machine);
                }
                objective.Set(key, result);
            }
            NetToObjectCallables callables = InternalCheckNetToObjectCallables(owner);

            if (callables != null)
            {
                if (callables.funcs != null)
                {
                    foreach (MethodInfo m in callables.funcs)
                    {
                        objective.Set(m.Name, NSJSPinnedCollection.Pinned(Complier(m)));
                    }
                }
                if (callables.props != null)
                {
                    foreach (PropertyInfo p in callables.props)
                    {
                        MethodInfo           gm  = p.GetGetMethod();
                        NSJSFunctionCallback get = null;
                        NSJSFunctionCallback set = null;
                        if (gm != null)
                        {
                            get = NSJSPinnedCollection.Pinned(Complier(gm));
                        }
                        MethodInfo sm = p.GetSetMethod();
                        if (sm != null)
                        {
                            set = NSJSPinnedCollection.Pinned(Complier(sm));
                        }
                        if (set != null || get != null)
                        {
                            objective.DefineProperty(p.Name, get, set);
                        }
                    }
                }
                objective.Set("Dispose", FDEFAULTDISPOSE);
                if (!objective.IsDefined("Close"))
                {
                    objective.Set("Close", FDEFAULTDISPOSE);
                }
                NSJSKeyValueCollection.Set(objective, obj);
            }
            return(objective);
        }
示例#16
0
    public void SetActiveTool(int idItem)
    {
        TypeTool typeTool = GetTypeTool(idItem);

        SetActiveTool(typeTool);
    }
示例#17
0
 public long GetLong(string session, string key, long defaultValue = 0)
 {
     return(TypeTool.ToLong(GetString(session, key, ""), defaultValue));
 }
示例#18
0
 public bool GetBool(string session, string key, bool defaultValue = false)
 {
     return(TypeTool.ToBool(GetString(session, key, ""), defaultValue));
 }
示例#19
0
        public static IList <T> ToList <T>(this DataTable value) where T : class
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }
            IList <KeyValuePair <PropertyInfo, int> > properties = new List <KeyValuePair <PropertyInfo, int> >();

            foreach (PropertyInfo property in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                foreach (DataColumn cols in value.Columns)
                {
                    if ((cols.ColumnName).ToUpper() == (property.Name).ToUpper())
                    {
                        properties.Add(new KeyValuePair <PropertyInfo, int>(property, cols.Ordinal));
                    }
                }
            }
            var       ctor   = typeof(T).GetConstructor(Type.EmptyTypes);
            IList <T> buffer = new List <T>();

            foreach (DataRow row in value.Rows)
            {
                T model = (T)ctor.Invoke(null);
                try
                {
                    buffer.Add(model);
                }
                finally
                {
                    foreach (KeyValuePair <PropertyInfo, int> pair in properties)
                    {
                        object args = row[pair.Value];
                        if (args == DBNull.Value)
                        {
                            args = null;
                        }
                        Type prop = pair.Key.PropertyType;
                        if (args != null && !prop.IsInstanceOfType(args))
                        {
                            if (prop.IsEnum)
                            {
                                prop = prop.GetEnumUnderlyingType();
                            }
                            if (TypeTool.IsFloat(prop))
                            {
                                args = ValuetypeFormatter.Parse(Convert.ToString(args), prop, NumberStyles.Number | NumberStyles.Float);
                            }
                            if (TypeTool.IsNumber(prop))
                            {
                                args = ValuetypeFormatter.Parse(Convert.ToString(args), prop, NumberStyles.Number | NumberStyles.Float);
                            }
                            else
                            {
                                args = ValuetypeFormatter.Parse(Convert.ToString(args), prop);
                            }
                        }
                        else if (args != null && prop == typeof(bool))
                        {
                            if (args is bool)
                            {
                                args = (bool)args;
                            }
                            else
                            {
                                args = (Convert.ToInt64(prop) != 0);
                            }
                        }
                        pair.Key.SetValue(model, args, null);
                    }
                }
            }
            return(buffer);
        }