本文整理汇总了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);
}
}
}
示例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;
}