Esempio n. 1
0
        // Public Methods 

        public static PropertyTranslationInfo FromPropertyInfo(PropertyInfo propInfo)
        {
            var result = new PropertyTranslationInfo();
            var gm     = propInfo.GetGetMethod();
            var sm     = propInfo.GetSetMethod();

            if (gm == null && sm == null)
            {
                throw new Exception(string.Format("Unable to get getter or setter for {0}", propInfo));
            }
            result.IsStatic = (gm != null && gm.IsStatic) ||
                              (sm != null && sm.IsStatic);
            var autoImplemented = IsAutoProperty(propInfo, result.IsStatic);

            if (autoImplemented)
            {
                result.FieldScriptName = propInfo.Name; // just field with the same name
            }
            else
            {
                var name = propInfo.Name;
                result.FieldScriptName = name.Substring(0, 1).ToLower() + name.Substring(1); // lowecase field name
            }
            {
                var at = propInfo.GetCustomAttribute <ScriptNameAttribute>(false);
                if (at != null)
                {
                    result.FieldScriptName = at.Name;// preserve case
                }
            }
            if (autoImplemented)
            {
                result.GetSetByMethod = false;
            }
            else
            {
                result.GetSetByMethod = true;
                if (propInfo.CanRead)
                {
                    result.GetMethodName = propInfo.GetGetMethod().Name;
                }
                if (propInfo.CanWrite)
                {
                    result.SetMethodName = propInfo.GetSetMethod().Name;
                }
            }
            return(result);
        }
        // Public Methods 

        public static PropertyTranslationInfo FromPropertyInfo(PropertyInfo propInfo)
        {
            var result = new PropertyTranslationInfo();
            var gm = propInfo.GetGetMethod();
            var sm = propInfo.GetSetMethod();
            if (gm == null && sm == null)
                throw new Exception(string.Format("Unable to get getter or setter for {0}", propInfo));
            result._isStatic = (gm != null && gm.IsStatic)
                               || (sm != null && sm.IsStatic);
            var autoImplemented = IsAutoProperty(propInfo, result._isStatic);
            if (autoImplemented)
                result.FieldScriptName = propInfo.Name; // just field with the same name 
            else
            {
                var name = propInfo.Name;
                result.FieldScriptName = name.Substring(0, 1).ToLower() + name.Substring(1); // lowecase field name
            }
            {
                var at = propInfo.GetCustomAttribute<ScriptNameAttribute>(false);
                if (at != null)
                    result.FieldScriptName = at.Name;// preserve case
            }
            if (autoImplemented)
            {
                result._getSetByMethod = false;
            }
            else
            {
                result._getSetByMethod = true;
                if (propInfo.CanRead)
                    result.GetMethodName = propInfo.GetGetMethod().Name;
                if (propInfo.CanWrite)
                    result.SetMethodName = propInfo.GetSetMethod().Name;
            }
            return result;
        }