mercredi 17 février 2016

System.Reflection.TypeInfo does not contain a definition for ImplementInterface in c# [on hold]

Here is my code,

// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
/*=============================================================================
**
** Class: TypeInfo
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Notion of a type definition
**
**
=============================================================================*/

namespace System.Reflection
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;

    //all today's runtime Type derivations derive now from TypeInfo
    //we make TypeInfo implement IRCT - simplifies work
    [System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
    public abstract class TypeInfo : Type, IReflectableType
    {

        internal TypeInfo() { }

        TypeInfo IReflectableType.GetTypeInfo()
        {
            return this;
        }
        public virtual Type AsType()
        {
            return (Type)this;
        }

        public virtual Type[] GenericTypeParameters
        {
            get
            {
                if (IsGenericTypeDefinition)
                {
                    return GetGenericArguments();
                }
                else
                {
                    return Type.EmptyTypes;
                }

            }
        }
        //a re-implementation of ISAF from Type, skipping the use of UnderlyingType
        [Pure]
        public virtual bool IsAssignableFrom(TypeInfo typeInfo)
        {
            if (typeInfo == null)
                return false;

            if (this == typeInfo)
                return true;

            // If c is a subclass of this class, then c can be cast to this type.
            if (typeInfo.IsSubclassOf(this))
                return true;

            if (this.IsInterface)
            {
                return typeInfo.ImplementInterface(this);
            }
            else if (IsGenericParameter)
            {
                Type[] constraints = GetGenericParameterConstraints();
                for (int i = 0; i < constraints.Length; i++)
                    if (!constraints[i].IsAssignableFrom(typeInfo))
                        return false;

                return true;
            }

            return false;
        }
        #region moved over from Type
        // Fields

        public virtual EventInfo GetDeclaredEvent(String name)
        {
            return GetEvent(name, Type.DeclaredOnlyLookup);
        }
        public virtual FieldInfo GetDeclaredField(String name)
        {
            return GetField(name, Type.DeclaredOnlyLookup);
        }
        public virtual MethodInfo GetDeclaredMethod(String name)
        {
            return GetMethod(name, Type.DeclaredOnlyLookup);
        }

        public virtual IEnumerable<MethodInfo> GetDeclaredMethods(String name)
        {
            foreach (MethodInfo method in GetMethods(Type.DeclaredOnlyLookup))
            {
                if (method.Name == name)
                    yield return method;
            }
        }
        public virtual System.Reflection.TypeInfo GetDeclaredNestedType(String name)
        {
            var nt = GetNestedType(name, Type.DeclaredOnlyLookup);
            if (nt == null)
            {
                return null; //the extension method GetTypeInfo throws for null
            }
            else
            {
                return nt.GetTypeInfo();
            }
        }
        public virtual PropertyInfo GetDeclaredProperty(String name)
        {
            return GetProperty(name, Type.DeclaredOnlyLookup);
        }





        // Properties

        public virtual IEnumerable<ConstructorInfo> DeclaredConstructors
        {
            get
            {
                return GetConstructors(Type.DeclaredOnlyLookup);
            }
        }

        public virtual IEnumerable<EventInfo> DeclaredEvents
        {
            get
            {
                return GetEvents(Type.DeclaredOnlyLookup);
            }
        }

        public virtual IEnumerable<FieldInfo> DeclaredFields
        {
            get
            {
                return GetFields(Type.DeclaredOnlyLookup);
            }
        }

        public virtual IEnumerable<MemberInfo> DeclaredMembers
        {
            get
            {
                return GetMembers(Type.DeclaredOnlyLookup);
            }
        }

        public virtual IEnumerable<MethodInfo> DeclaredMethods
        {
            get
            {
                return GetMethods(Type.DeclaredOnlyLookup);
            }
        }
        public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
        {
            get
            {
                foreach (var t in GetNestedTypes(Type.DeclaredOnlyLookup))
                {
                    yield return t.GetTypeInfo();
                }
            }
        }

        public virtual IEnumerable<PropertyInfo> DeclaredProperties
        {
            get
            {
                return GetProperties(Type.DeclaredOnlyLookup);
            }
        }


        public virtual IEnumerable<Type> ImplementedInterfaces
        {
            get
            {
                return GetInterfaces();
            }
        }


        #endregion

    }
}

When i run this source code, it shows error like this

'System.Reflection.TypeInfo' does not contain a definition for 'ImplementInterface' and no extension method 'ImplementInterface' accepting a first argument of type 'System.Reflection.TypeInfo' could be found (are you missing a using directive or an assembly reference?)

this is default.cs:

protected void Page_Load(object sender, EventArgs e)
        {
            ShopifyAuthorizationState state = HttpContext.Current.Session["Shopify.AuthState"] as ShopifyAuthorizationState;
            ShopifyAPIClient client
                = new ShopifyAPIClient(state);
            string shopData = (string)client.Get("/admin/products.json");
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            // Here Product is a object class which contains all of the attribute that JSON has.
            List<Product> lstProduct = serializer.Deserialize<List<Product>>(shopData); 
            GridView1.DataSource = lstProduct;
            GridView1.DataBind();
        }


        public class Product
        {
            public long id{ get; set; }
            public string title{ get; set; }
            public string body_html { get; set; }
        }

When i search System.Reflection.TypeInfo class in online, i can't able to find out.

Can anybody help me to fix this?

Any help would be highly appreciated,

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire