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


C# Type.IsInstanceOfType方法代码示例

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


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

示例1: SetExtension

 ///////////////////////////////////////////////////////////////////////
 /// <summary>Replaces or adds an extension of the given type
 /// to the list.
 ///
 /// This method looks for the first element on the list of the
 /// given type and replaces it with the new value. If there are
 /// no element of this type yet, a new element is added at the
 /// end of the list.
 /// </summary>
 /// <param name="extensionElements">list of IExtensionElement</param>
 /// <param name="type">type of the element to be added, removed
 /// or replaced</param>
 /// <param name="newValue">new value for this element, null to
 /// remove it</param>
 ///////////////////////////////////////////////////////////////////////
 public static void SetExtension(IList<IExtensionElementFactory> extensionElements,
                                 Type type,
                                 IExtensionElementFactory newValue)
 {
     int count = extensionElements.Count;
     for (int i = 0; i < count; i++)
     {
         object element = extensionElements[i];
         if (type.IsInstanceOfType(element))
         {
             if (newValue == null)
             {
                 extensionElements.RemoveAt(i);
             }
             else
             {
                 extensionElements[i] = newValue;
             }
             return;
         }
     }
     if (newValue != null)
     {
         extensionElements.Add(newValue);
     }
 }
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:41,代码来源:gbaseutilities.cs

示例2: Annotation

        public static object Annotation(object annotations, Type type)
        {
            Guard.NotNull(() => type, type);

            if (annotations != null)
            {
                var annotationsArray = annotations as object[];
                if (annotationsArray == null)
                {
                    if (type.IsInstanceOfType(annotations))
                        return annotations;
                }
                else
                {
                    for (int i = 0; i < annotationsArray.Length; i++)
                    {
                        var value = annotationsArray[i];
                        if (value == null)
                            break;

                        if (type.IsInstanceOfType(value))
                            return value;
                    }
                }
            }

            return null;
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:28,代码来源:Annotator.cs

示例3: ReadFile_

        public static object ReadFile_(string file, Type expectedType, IProgressMonitor monitor)
        {
            bool clearLoadedPrjList = AlreadyLoadedPackages == null;
            if (clearLoadedPrjList)
                AlreadyLoadedPackages = new List<string> ();

            if (AlreadyLoadedPackages.Contains (file))
                return null;
            AlreadyLoadedPackages.Add (file);

            DubProject defaultPackage;
            try{
                using (var s = File.OpenText (file))
                using (var r = new JsonTextReader (s))
                    defaultPackage = ReadPackageInformation(file, r, monitor);
            }catch(Exception ex){
                if (clearLoadedPrjList)
                    AlreadyLoadedPackages = null;
                monitor.ReportError ("Couldn't load dub package \"" + file + "\"", ex);
                return null;
            }

            if (expectedType.IsInstanceOfType (defaultPackage)) {
                LoadDubProjectReferences (defaultPackage, monitor);

                if (clearLoadedPrjList)
                    AlreadyLoadedPackages = null;

                return defaultPackage;
            }

            var sln = new DubSolution();

            if (!expectedType.IsInstanceOfType (sln)) {
                if (clearLoadedPrjList)
                    AlreadyLoadedPackages = null;
                return null;
            }

            sln.RootFolder.AddItem(defaultPackage, false);
            sln.StartupItem = defaultPackage;

            // Introduce solution configurations
            foreach (var cfg in defaultPackage.Configurations)
                sln.AddConfiguration(cfg.Name, false).Platform = cfg.Platform;

            LoadDubProjectReferences (defaultPackage, monitor, sln);

            sln.LoadUserProperties();

            if (clearLoadedPrjList) {
                AlreadyLoadedPackages = null;

                // Clear 'dub list' outputs
                DubReferencesCollection.DubListOutputs.Clear ();
            }

            return sln;
        }
开发者ID:Geod24,项目名称:Mono-D,代码行数:59,代码来源:PackageJsonParser.cs

示例4: GetValue

        public object GetValue(Type targetType)
        {
            var stringValue = _underlyingValue as string;
            if (_underlyingValue == null)
            {
                if (targetType.IsValueType && !(targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                {
                    var valueAsString = string.IsNullOrEmpty(stringValue) ? "<null>" : string.Format("\"{0}\"", _underlyingValue);
                    throw new ArgumentException(string.Format("Cannot convert {0} to {1} (Column: '{2}', Row: {3})", valueAsString, targetType.Name, Header, Row));
                }
                return null;
            }

            ValueHasBeenUsed = true;
            if (targetType.IsInstanceOfType(_underlyingValue))
                return _underlyingValue;

            if (targetType.IsEnum && _underlyingValue is string)
                return Enum.Parse(targetType, (string)_underlyingValue);

            if (targetType == typeof(DateTime))
                return DateTime.Parse(stringValue);

            try
            {
                return Convert.ChangeType(_underlyingValue, targetType);
            }
            catch (InvalidCastException ex)
            {
                throw new UnassignableExampleException(string.Format(
                    "{0} cannot be assigned to {1} (Column: '{2}', Row: {3})", 
                    _underlyingValue == null ? "<null>" : _underlyingValue.ToString(),
                    targetType.Name, Header, Row), ex, this);
            }
        }
开发者ID:jason-roberts,项目名称:TestStack.BDDfy,代码行数:35,代码来源:ExampleValue.cs

示例5: DeserializeCache

 internal static StateFileBase DeserializeCache(string stateFile, TaskLoggingHelper log, Type requiredReturnType)
 {
     StateFileBase o = null;
     try
     {
         if (((stateFile == null) || (stateFile.Length <= 0)) || !File.Exists(stateFile))
         {
             return o;
         }
         using (FileStream stream = new FileStream(stateFile, FileMode.Open))
         {
             object obj2 = new BinaryFormatter().Deserialize(stream);
             o = obj2 as StateFileBase;
             if ((o == null) && (obj2 != null))
             {
                 log.LogMessageFromResources("General.CouldNotReadStateFileMessage", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
             }
             if ((o != null) && !requiredReturnType.IsInstanceOfType(o))
             {
                 log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
                 o = null;
             }
         }
     }
     catch (Exception exception)
     {
         log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, exception.Message });
     }
     return o;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:StateFileBase.cs

示例6: GetCustomAttribute

 public object GetCustomAttribute(object obj, Type type, bool inherit)
 {
     foreach (object att in GetCustomAttributes (obj, type, inherit))
         if (type.IsInstanceOfType (att))
             return att;
     return null;
 }
开发者ID:NALSS,项目名称:Telegraph,代码行数:7,代码来源:Reflector.cs

示例7: GetService

		public virtual object GetService (WorkspaceItem item, Type type)
		{
			if (type.IsInstanceOfType (this))
				return this;
			else
				return GetNext (item).GetService (item, type);
		}
开发者ID:jgranick,项目名称:haxedevelop,代码行数:7,代码来源:ProjectServiceExtension.cs

示例8: GetAdapter

        //IAdaptable
        public virtual IAdaptable GetAdapter(Type adapter) {
#if UNITTEST
            return adapter.IsInstanceOfType(this) ? this : null; //UnitTestではPoderosaの起動にならないケースもある
#else
            return ProtocolsPlugin.Instance.PoderosaWorld.AdapterManager.GetAdapter(this, adapter);
#endif
        }
开发者ID:Ricordanza,项目名称:poderosa,代码行数:8,代码来源:TerminalParameter.cs

示例9: SerializeRoot

 public XElement SerializeRoot(object obj, Type rootType, XName name, XSerializerNamespaceCollection namespaces, SerializationScope globalScope)
 {
     Debug.Assert(rootType.IsInstanceOfType(obj));
     Debug.Assert(namespaces != null);
     var root = SerializeXElement(obj, rootType, name, globalScope);
     //导入命名空间。
     foreach (var ns in namespaces)
         root.SetAttributeValue(XNamespace.Xmlns + ns.Prefix, ns.Uri);
     //处理导入的类型。
     var nsCounter = 0;
     foreach (var descendant in root.Descendants())
     {
         var actualTypeName = descendant.Annotation<XName>();
         if (actualTypeName != null)
         {
             if (actualTypeName.Namespace == descendant.GetDefaultNamespace())
             {
                 descendant.SetAttributeValue(SerializationHelper.Xsi + "type", actualTypeName.LocalName);
             }
             else
             {
                 var prefix = descendant.GetPrefixOfNamespace(actualTypeName.Namespace);
                 if (prefix == null)
                 {
                     nsCounter++;
                     prefix = "nss" + nsCounter;
                     descendant.SetAttributeValue(XNamespace.Xmlns + prefix, actualTypeName.NamespaceName);
                 }
                 descendant.SetAttributeValue(SerializationHelper.Xsi + "type", prefix + ":" + actualTypeName.LocalName);
             }
             descendant.RemoveAnnotations<XName>();
         }
     }
     return root;
 }
开发者ID:CXuesong,项目名称:XSerializer,代码行数:35,代码来源:XSerializationState.cs

示例10: EncodeObject

 static ByteString EncodeObject (object value, Type type, MemoryStream buffer, CodedOutputStream stream)
 {
     buffer.SetLength (0);
     if (value != null && !type.IsInstanceOfType (value))
         throw new ArgumentException ("Value of type " + value.GetType () + " cannot be encoded to type " + type);
     if (value == null && !type.IsSubclassOf (typeof(RemoteObject)) && !IsACollectionType (type))
         throw new ArgumentException ("null cannot be encoded to type " + type);
     if (value == null)
         stream.WriteUInt64 (0);
     else if (value is Enum)
         stream.WriteInt32 ((int)value);
     else {
         switch (Type.GetTypeCode (type)) {
         case TypeCode.Int32:
             stream.WriteInt32 ((int)value);
             break;
         case TypeCode.Int64:
             stream.WriteInt64 ((long)value);
             break;
         case TypeCode.UInt32:
             stream.WriteUInt32 ((uint)value);
             break;
         case TypeCode.UInt64:
             stream.WriteUInt64 ((ulong)value);
             break;
         case TypeCode.Single:
             stream.WriteFloat ((float)value);
             break;
         case TypeCode.Double:
             stream.WriteDouble ((double)value);
             break;
         case TypeCode.Boolean:
             stream.WriteBool ((bool)value);
             break;
         case TypeCode.String:
             stream.WriteString ((string)value);
             break;
         default:
             if (type.Equals (typeof(byte[])))
                 stream.WriteBytes (ByteString.CopyFrom ((byte[])value));
             else if (IsAClassType (type))
                 stream.WriteUInt64 (((RemoteObject)value).id);
             else if (IsAMessageType (type))
                 ((IMessage)value).WriteTo (buffer);
             else if (IsAListType (type))
                 WriteList (value, type, buffer);
             else if (IsADictionaryType (type))
                 WriteDictionary (value, type, buffer);
             else if (IsASetType (type))
                 WriteSet (value, type, buffer);
             else if (IsATupleType (type))
                 WriteTuple (value, type, buffer);
             else
                 throw new ArgumentException (type + " is not a serializable type");
             break;
         }
     }
     stream.Flush ();
     return ByteString.CopyFrom (buffer.GetBuffer (), 0, (int)buffer.Length);
 }
开发者ID:paperclip,项目名称:krpc,代码行数:60,代码来源:Encoder.cs

示例11: ChangeType

        public static object ChangeType(object value, Type conversionType)
        {
            if (value == null)
            {
                return null;
            }
            Type valueType = value.GetType();
            bool valueIsJava = valueType.IsSubclassOf(_javaObjectType) || valueType == _javaObjectType;
            bool expectedIsJava = conversionType.IsSubclassOf(_javaObjectType) || conversionType == _javaObjectType;

            if (expectedIsJava)
            {
                if (valueIsJava)
                {
                    return value;
                }
                return value.WrapIntoJava();
            }
            if (valueIsJava)
            {
                object underlyingObject = (value as Object).ToManaged();
                if (underlyingObject != null)
                {
                    value = underlyingObject;
                }
            }

            if (conversionType.IsInstanceOfType(value))
            {
                return value;
            }

            return Convert.ChangeType(value, conversionType);
        }
开发者ID:snipervld,项目名称:StormXamarin,代码行数:34,代码来源:ConverterHelper.cs

示例12: ConvertImpl

        /// <inheritdoc />
        protected override object ConvertImpl(object sourceValue, Type targetType)
        {
            if (sourceValue == null || targetType.IsInstanceOfType(sourceValue))
                return sourceValue;

            throw new InvalidOperationException("The null converter does not support conversions.");
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:8,代码来源:NullConverter.cs

示例13: Add

        public int Add(int jobId, object data, Type dataType)
        {
            if (!dataType.IsInstanceOfType(data))
                throw new Exception("Incompatible type against data");

            return AddInternal(jobId, data, dataType, DataEntryType.Direct);
        }
开发者ID:mikezhuyuan,项目名称:simpleflow,代码行数:7,代码来源:InMemoryDataStore.cs

示例14: KeepOriginal

 static bool KeepOriginal(object arg, Type targetType)
 {
     return arg == null
         || targetType == typeof(object)
         || targetType.IsInstanceOfType(arg)
         || (targetType.IsEnum && arg.GetType() == typeof(int));
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:7,代码来源:ConePadTest.cs

示例15: ChangeToCompatibleType

        public static bool ChangeToCompatibleType(string value, Type destinationType, out object result)
        {
            if (string.IsNullOrEmpty(value))
            {
                result = null;
                return false;
            }

            if (destinationType.IsInstanceOfType(value))
            {
                result = value;
                return true;
            }

            try
            {
                result = TypeDescriptor.GetConverter(destinationType).ConvertFrom(value);
                return true;
            }
            catch
            {
                result = null;
                return false;
            }
        }
开发者ID:qhme,项目名称:OrchardLite,代码行数:25,代码来源:HostComponentsConfigModule.cs


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