當前位置: 首頁>>代碼示例>>C#>>正文


C# Android.GetType方法代碼示例

本文整理匯總了C#中Android.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# Android.GetType方法的具體用法?C# Android.GetType怎麽用?C# Android.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Android的用法示例。


在下文中一共展示了Android.GetType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PersistStepContext

        /// <summary>
        /// Extracts the data from the Fragment and stores it into the Bundle
        /// </summary>
        /// <param name="step"></param>
        public void PersistStepContext(Android.Support.V4.App.Fragment step)
        {
            var fields = step.GetType().GetFields();

            foreach (var field in fields) {
                if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute)))
                    continue; // Only process those fields that are decorated with WizardStateAttribute

                try {
                    if (field.FieldType == typeof(string)) {
                        ContextBundle.PutString(field.Name, field.GetValue(step) as string);
                    }
                    else if (field.FieldType == typeof(int)) {
                        ContextBundle.PutInt(field.Name, (int)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(bool)) {
                        ContextBundle.PutBoolean(field.Name, (bool)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(double)) {
                        ContextBundle.PutDouble(field.Name, (double)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(float)) {
                        ContextBundle.PutFloat(field.Name, (float)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(short)) {
                        ContextBundle.PutShort(field.Name, (short)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(DateTime)) {
                        ContextBundle.PutLong(field.Name, ((DateTime)field.GetValue(step)).Ticks);
                    }
                    else if (field.FieldType == typeof(char)) {
                        ContextBundle.PutChar(field.Name, (char)field.GetValue(step));
                    }
                    else if (typeof(Parcelable).IsAssignableFrom(field.FieldType)) {
                        ContextBundle.PutParcelable(field.Name, field.GetValue(step) as IParcelable);
                    }
                    else if (field.FieldType is Java.IO.ISerializable) {
                        ContextBundle.PutSerializable(field.Name, field.GetValue(step) as Java.IO.ISerializable);
                    }
                    else {
                        //TODO: Add support for arrays
                        throw new ArgumentException(string.Format("Unsuported type. Cannot pass value to variable {0} of step {1}. Variable type is unsuported.",
                                field.Name, step.GetType().FullName));
                    }
                }
                catch (FieldAccessException f) {
                    throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f);
                }
            }
        }
開發者ID:pacificIT,項目名稱:WizarDroid.Net,代碼行數:54,代碼來源:StateManager.cs

示例2: LoadStepContext

        /// <summary>
        /// Populates the Fields in the Fragment with values stored within the BundleContext
        /// </summary>
        /// <param name="step"></param>
        public void LoadStepContext(Android.Support.V4.App.Fragment step)
        {
            var fields = step.GetType().GetFields();

            var args = step.Arguments;

            if (args == null)
                args = new Bundle();

            foreach (var field in fields) {
                if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute)))
                    continue; // Only process those fields that are decorated with WizardStateAttribute

                try {

                    if (field.FieldType == typeof(string)) {
                        args.PutString(field.Name, ContextBundle.GetString(field.Name));
                    }
                    else if (field.FieldType == typeof(int)) {
                        args.PutInt(field.Name, ContextBundle.GetInt(field.Name));
                    }
                    else if (field.FieldType == typeof(bool)) {
                        args.PutBoolean(field.Name, ContextBundle.GetBoolean(field.Name));
                    }
                    else if (field.FieldType == typeof(double)) {
                        args.PutDouble(field.Name, ContextBundle.GetDouble(field.Name));
                    }
                    else if (field.FieldType == typeof(float)) {
                        args.PutFloat(field.Name, ContextBundle.GetFloat(field.Name));
                    }
                    else if (field.FieldType == typeof(short)) {
                        args.PutShort(field.Name, ContextBundle.GetShort(field.Name));
                    }
                    else if (field.FieldType == typeof(DateTime)) {
                        args.PutLong(field.Name, ContextBundle.GetLong(field.Name));
                    }
                    else if (field.FieldType == typeof(char)) {
                        args.PutChar(field.Name, ContextBundle.GetChar(field.Name));
                    }
                    else if (typeof(Parcelable).IsAssignableFrom(field.FieldType)) {
                        args.PutParcelable(field.Name, ContextBundle.GetParcelable(field.Name) as IParcelable);
                    }
                    else if (field.FieldType is Java.IO.ISerializable) {
                        args.PutSerializable(field.Name, ContextBundle.GetSerializable(field.Name));
                    }
                    else if (field.FieldType.IsValueType == false) { //Runtime serialization for reference type.. use json.net serialization
                        args.PutString(field.Name, ContextBundle.GetString(field.Name));
                    }
                    else {
                        //TODO: Add support for arrays
                        throw new ArgumentException(string.Format("Unsuported type. Cannot pass value to variable {0} of step {1}. Variable type is unsuported.",
                                field.Name, step.GetType().FullName));
                    }
                }
                catch (FieldAccessException f) {
                    throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f);
                }
            }

            if (step is WizardFragment)
                BindFields((WizardFragment)step, args);
            else
                step.Arguments = args;
        }
開發者ID:cryptocoinx,項目名稱:WizarDroid.Net,代碼行數:68,代碼來源:StateManager.cs


注:本文中的Android.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。