当前位置: 首页>>代码示例>>C#>>正文


C# Object.GetType方法代码示例

本文整理汇总了C#中System.Object.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetType方法的具体用法?C# Object.GetType怎么用?C# Object.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Object的用法示例。


在下文中一共展示了Object.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: field_DataBinding

 private void field_DataBinding(Object sender, EventArgs e)
 {
     Control c = (Control)sender;
     GridViewRow row = (GridViewRow)c.NamingContainer;
     if (sender.GetType() == typeof(Label))
     {
         (c as Label).Text = DataBinder.Eval(row.DataItem, columnNameData).ToString();
         (c as Label).Font.Size = 7;
         (c as Label).Font.Name = "Arial";
     }
     else if (sender.GetType() == typeof(TextBox))
     {
         (c as TextBox).Text = DataBinder.Eval(row.DataItem, columnNameData).ToString();
         (c as TextBox).Font.Size = 7;
         (c as TextBox).Font.Name = "Arial";
     }
     else if (sender.GetType() == typeof(DropDownList))
     {
         (c as DropDownList).SelectedValue = DataBinder.Eval(row.DataItem, columnNameData).ToString();
         (c as DropDownList).Font.Size = 7;
         (c as DropDownList).Font.Name = "Arial";
     }
     else if (sender.GetType() == typeof(CheckBox))
     {
         (c as CheckBox).Checked = (bool)DataBinder.Eval(row.DataItem, columnNameData);
     }
 }
开发者ID:hoangtung56pm,项目名称:KPINew,代码行数:27,代码来源:GridViewTemplate.cs

示例2: UpdateContextItem

        public static object UpdateContextItem(DbContext context,Object obj)
        {
            //将foreign key制空
            obj.GetType().GetProperties().ToList().ForEach(delegate (PropertyInfo pi)
            {
                var att = pi.GetCustomAttribute(typeof(ForeignKeyAttribute));
                if (att != null)
                {
                    pi.SetValue(obj, null);
                }

            });

            //修改操作为修改
            context.Entry(obj).State = EntityState.Modified;

            //重新加载foreign key的对象。
            obj.GetType().GetProperties().ToList().ForEach(delegate (PropertyInfo pi)
            {
                var att = pi.GetCustomAttribute(typeof(ForeignKeyAttribute));
                if (att != null)
                {
                    context.Entry(obj).Reference(pi.Name).Load();
                }
            });
            return obj;
        }
开发者ID:amwtke,项目名称:bkwecaht,代码行数:27,代码来源:RepositoryHelper.cs

示例3: Json

        public Json(Object value, MemberInfo descriptor)
        {
            if (value == null && descriptor == null) return;
            var mi = descriptor ?? (value == null ? null : value.GetType());
            var pi = mi as PropertyInfo;
            var t = mi is Type ? (Type)mi : (value == null ? null : value.GetType());

            pi.Config().Validators.ForEach(validator => validator.Validate(pi, value));
            t.Config().Validators.ForEach(validator => validator.Validate(t, value));
            // todo. after BeforeSerialize value might have become undesirably changed in-place!
            // how do we revert such changes and hydrate the object back to life?!
            value = pi.Config().Adapters.Fold(value, (curr, adapter) => adapter.BeforeSerialize(pi, curr));
            value = t.Config().Adapters.Fold(value, (curr, adapter) => adapter.BeforeSerialize(t, curr));

            if (value == null)
            {
                _my_state = State.Primitive;
                _my_primitive = null;
            }
            else if (value is Json)
            {
                _wrappee = value.AssertCast<Json>();
            }
            else
            {
                var engine = pi.Config().Engine ?? t.Config().Engine ?? (Engine)new DefaultEngine();
                if (engine is TypeEngine && !(mi is Type)) mi = mi.Type();
                _wrappee = engine.Serialize(mi, value);
            }
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:30,代码来源:Json.Serialize.cs

示例4: Dispatch

        public void Dispatch(Object @event)
        {
            //remember to use datetime.now to set an unique value for this event.
            _logger.SetOpType("event", @event.GetType().FullName + " " + DateTime.Now.ToString());

            _logger.Info("[evt dispatcher] dispatching event " + @event.ToString());
            var eventType = @event.GetType();
            var handlerInvokerList = _domainEventHandlerCatalog.GetAllHandlerFor(eventType);
            _logger.Debug("[evt dispatcher] dispatching event " + @event.ToString() + " found " + handlerInvokerList.Count() + " handlers");
            foreach (var invoker in handlerInvokerList)
            {
                invoker.Invoke(@event as IDomainEvent);
            }
            _logger.Debug("[evt dispatcher] dispatching event " + @event.ToString() + " done");
            _logger.RemoveOpType();
            //var eventHandlerType = typeof(IDomainEventHandler<>).MakeGenericType(eventType);
            
            //var handlers = _domainEventHandlerFactory.CreateHandlers(eventHandlerType);
            //if (handlers != null)
            //{
            //    foreach (var handler in handlers)
            //    {
            //        var handlerType = handler.GetType();
            //        MethodInfo mi = handlerType.GetMethod("Handle", new[] { eventType });
            //        mi.Invoke(handler, new[] { @event });
            //    }

            //    _domainEventHandlerFactory.ReleaseHandlers(handlers);
            //}
        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:30,代码来源:DefaultDomainEventRouter.cs

示例5: addNode

 public void addNode(Object node, HashTree subTree)
 {
     if (typeof(TestElement).IsAssignableFrom(node.GetType()) && !typeof(TestPlan).IsAssignableFrom(node.GetType()))
     {
         ((TestElement) node).SetRunningVersion(true);
     }
 }
开发者ID:RalphC,项目名称:NetMeter,代码行数:7,代码来源:TurnElementsOn.cs

示例6: createSerializedXmlStringFromObject

        public static String createSerializedXmlStringFromObject(Object oObjectToProcess , Type[] extraTypes)
        {
            if (oObjectToProcess == null)
                DI.log.error("in createSerializedXmlStringFromObject: oObjectToProcess == null");
            else
            {
                try
                {
                    /*// handle cases file names are bigger than 220
                    if (sTargetFile.Length > 220)
                    {
                        sTargetFile = sTargetFile.Substring(0, 200) + ".xml";
                        DI.log.error("sTargetFile.Length was > 200, so renamig it to: {0}", sTargetFile);
                    }*/
                    var xnsXmlSerializerNamespaces = new XmlSerializerNamespaces();
                    xnsXmlSerializerNamespaces.Add("", "");
                    var xsXmlSerializer = (extraTypes != null)
                                              ? new XmlSerializer(oObjectToProcess.GetType(), extraTypes)
                                              : new XmlSerializer(oObjectToProcess.GetType());
                    var memoryStream = new MemoryStream();
                    xsXmlSerializer.Serialize(memoryStream, oObjectToProcess, xnsXmlSerializerNamespaces);

                    return Encoding.ASCII.GetString(memoryStream.ToArray());
                }
                catch (Exception ex)
                {
                    DI.log.ex(ex,"In createSerializedXmlStringFromObject");
                }
            }
            return "";
        }
开发者ID:pusp,项目名称:o2platform,代码行数:31,代码来源:Serialize.cs

示例7: modifyRecursively

 /// <summary>
 /// 
 /// </summary>
 /// <param name="ob"></param>
 /// <param name="fieldPath"></param>
 /// <param name="fieldValue"></param>
 public static void modifyRecursively(Object ob, String fieldPath, String fieldValue)
 {
     if (ob == null)
     {
         return;
     }
     if (!fieldPath.Contains("."))
     {
         modifyValueOfFieldAccordingToTable(ob, fieldPath, fieldValue);
     }
     else
     {
         String prefix = fieldPath.Substring(0, fieldPath.IndexOf('.'));
         Object o;
         o = ob.GetType().GetProperty(prefix, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
         if (o != null)
         {
             PropertyInfo myProp = (PropertyInfo)o;
             Object subObject = myProp.GetValue(ob, null);
             String toPass = fieldPath.Substring(fieldPath.IndexOf('.') + 1);
             modifyRecursively(subObject, toPass, fieldValue);
         }
         else
         {
             o = ob.GetType().GetField(prefix, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
             FieldInfo myField = (FieldInfo)o;
             Object subObject = myField.GetValue(ob);
             String toPass = fieldPath.Substring(fieldPath.IndexOf('.') + 1);
             modifyRecursively(subObject, toPass, fieldValue);
         }
     }
 }
开发者ID:tonyx,项目名称:LabelsLocalization,代码行数:38,代码来源:LabelUtils.cs

示例8: ToString

        public static string ToString(Object obj)
        {
            if (obj == null) {
                return "null";
            }

            StringBuilder sb = new StringBuilder();
            PropertyInfo[] props = obj.GetType().GetProperties();

            sb.AppendLine("[" + obj.GetType().Name + "]");
            foreach (PropertyInfo prop in props) {
                if (prop.GetIndexParameters().Length == 0) {
                    sb.Append(prop.Name);
                    sb.Append(" = ");
                    sb.Append(prop.GetValue(obj, null));
                    sb.AppendLine();
                }
            }

            if (obj is IEnumerable<object>) {
                foreach (object item in (IEnumerable<object>)obj) {
                    sb.AppendLine();
                    sb.Append(ToString(item));
                }
            }

            return sb.ToString();
        }
开发者ID:sohong,项目名称:greenfleet-viewer,代码行数:28,代码来源:ObjectUtil.cs

示例9: IsTypeOf

        public static bool IsTypeOf(Object obj, string typeFullName, bool shallow)
        {
            if (obj != null)
            {
                if (shallow)
                {
                    return obj.GetType().FullName.Equals(typeFullName);
                }
                else
                {
                    Type type = obj.GetType();
                    string fullName = type.FullName;

                    while (!fullName.Equals("System.Object"))
                    {
                        if (fullName.Equals(typeFullName))
                        {
                            return true;
                        }
                        type = type.BaseType;
                        fullName = type.FullName;
                    }
                }
            }

            return false;
        }
开发者ID:pgodwin,项目名称:Ext.net,代码行数:27,代码来源:ReflectionUtils.cs

示例10: Equals

        public static Boolean Equals(Object a, Object b) 
        {
            if (a == null || b == null) 
            {
                return b == null && a == null;
            }

            if (a.GetType() != b.GetType()) return false;
            var propA = a.GetType().GetProperties();
            var propB = b.GetType().GetProperties();

            if (propA.Length != propB.Length) return false;

            return propA.All(p => {

                if (propertyBlackList.Contains(p.Name)) return true;

                var pinfo = propB.SingleOrDefault(pb => pb.Name == p.Name);
                if (pinfo == null) return false;

                var bvalue = pinfo.GetValue(b, null);
                var avalue = p.GetValue(a, null);
                return Object.Equals(avalue, bvalue);
            });
        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:25,代码来源:GenericEquals.cs

示例11: GetEntityField

        public static FieldInfo GetEntityField( Object gameEntity, string fieldName, bool suppressErrors = false )
        {
            try
            {
                FieldInfo field = gameEntity.GetType( ).GetField( fieldName );
                if ( field == null )
                {
                    //Recurse up through the class heirarchy to try to find the field
                    Type type = gameEntity.GetType( );
                    while ( type != typeof( Object ) )
                    {
                        field = type.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
                        if ( field != null )
                            break;

                        type = type.BaseType;
                    }
                }
                return field;
            }
            catch ( Exception ex )
            {
                if ( !suppressErrors )
                {
                    Log.Error( "Failed to get entity field '{0}'", fieldName );
                    Log.Error( ex );
                }
                return null;
            }
        }
开发者ID:LoganRickert,项目名称:SEServerExtender,代码行数:30,代码来源:Reflection.cs

示例12: Execute

            public override Object Execute(Object o, IList args)
            {
                AppDomain domain = null;
                Object remote = null;
                try
                {
                    // creating remote domain
                    domain = AppDomain.CreateDomain(o.GetType().FullName);

                    // create fixture type
                    remote = domain.CreateInstanceAndUnwrap(
                        o.GetType().Assembly.GetName().Name,
                        o.GetType().FullName
                        );

                    // run invoker on remoted type
                    return this.Invoker.Execute(remote, args);
                }
                finally
                {
                    IDisposable disposable = remote as IDisposable;
                    if (disposable!=null)
                        disposable.Dispose();
                    remote = null;
                    if (domain != null)
                    {
                        AppDomain.Unload(domain);
                    }
                }
            }
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:30,代码来源:RemotingAttribute.cs

示例13: GetEntityField

        internal static FieldInfo GetEntityField(Object gameEntity, string fieldName)
        {
            try
            {
                FieldInfo field = gameEntity.GetType().GetField(fieldName);
                if (field == null)
                {
                    //Recurse up through the class heirarchy to try to find the field
                    Type type = gameEntity.GetType();
                    while (type != typeof(Object))
                    {
                        field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                        if (field != null)
                            break;

                        type = type.BaseType;
                    }
                }
                return field;
            }
            catch (Exception ex)
            {
                LogManager.APILog.WriteLine("Failed to get entity field '" + fieldName + "'");
                if (SandboxGameAssemblyWrapper.IsDebugging)
                    LogManager.ErrorLog.WriteLine(Environment.StackTrace);
                LogManager.ErrorLog.WriteLine(ex);
                return null;
            }
        }
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:29,代码来源:Wrapper.cs

示例14: GetPropertyValue

        public static Object GetPropertyValue(Object obj, String property)
        {
            try
            {
                if (property.Contains("."))
                {
                    String objProp = property.Remove(property.IndexOf("."));
                    String prop = property.Substring(property.IndexOf(".") + 1);

                    if (objProp == obj.GetType().Name)
                    {
                        return GetPropertyValue(obj, prop);
                    }
                    else
                    {
                        Object newObj = obj.GetType().GetProperty(objProp).GetValue(obj, null);
                        return GetPropertyValue(newObj, prop);
                    }
                }
                else
                {
                    return obj.GetType().GetProperty(property).GetValue(obj, null);
                }
            }
            catch (ApplicationException exc)
            {
                throw new ApplicationException(String.Format("Cannot find property: {0} ({1})", property, exc.Message));
            }
        }
开发者ID:marciotoshio,项目名称:Pigeon-Mailer,代码行数:29,代码来源:ReflectionHelper.cs

示例15: Deserialize

 /// <summary>
 /// Deserializes the specified object from a binary file
 /// </summary>
 public static Object Deserialize(String file, Object obj, Boolean checkValidity)
 {
     try
     {
         FileHelper.EnsureUpdatedFile(file);
         Object settings = InternalDeserialize(file, obj.GetType());
         if (checkValidity)
         {
             Object defaults = Activator.CreateInstance(obj.GetType());
             PropertyInfo[] properties = settings.GetType().GetProperties();
             foreach (PropertyInfo property in properties)
             {
                 Object current = GetValue(settings, property.Name);
                 if (current == null || (current is Color && (Color)current == Color.Empty))
                 {
                     Object value = GetValue(defaults, property.Name);
                     SetValue(settings, property.Name, value);
                 }
             }
         }
         return settings;
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
         return obj;
     }
 }
开发者ID:heon21st,项目名称:flashdevelop,代码行数:31,代码来源:ObjectSerializer.cs


注:本文中的System.Object.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。