Ejemplo n.º 1
0
            public ResourceIdentity(IGetResourceIdentity getResourceIdentity)
            {
                Contract.Requires(getResourceIdentity != null);

                this.ApiResourceType = getResourceIdentity.Type;
                this.ApiResourceId   = getResourceIdentity.Id;
            }
        public static bool IsUndefined(this IGetResourceIdentity getResourceIdentity)
        {
            Contract.Requires(getResourceIdentity != null);

            return(getResourceIdentity == null ||
                   String.IsNullOrWhiteSpace(getResourceIdentity.Type) ||
                   String.IsNullOrWhiteSpace(getResourceIdentity.Id));
        }
Ejemplo n.º 3
0
        protected static void WriteId(JsonWriter writer, JsonSerializer serializer, IGetResourceIdentity getResourceIdentity)
        {
            Contract.Requires(writer != null);
            Contract.Requires(serializer != null);
            Contract.Requires(getResourceIdentity != null);

            WriteString(writer, serializer, Keywords.Id, getResourceIdentity.Id);
        }
        public static int GetHashCode(this IGetResourceIdentity getResourceIdentity)
        {
            Contract.Requires(getResourceIdentity != null);

            var typeHashCode = getResourceIdentity.Type?.GetHashCode();
            var idHashCode   = getResourceIdentity.Id?.GetHashCode();

            var hashCode = typeHashCode.GetValueOrDefault() ^ idHashCode.GetValueOrDefault();

            return(hashCode);
        }
        public static bool Equals(this IGetResourceIdentity getResourceIdentity, IGetResourceIdentity other)
        {
            if (Object.ReferenceEquals(getResourceIdentity, other))
            {
                return(true);
            }

            if (other == null)
            {
                return(false);
            }

            return(getResourceIdentity.Type == other.Type && getResourceIdentity.Id == other.Id);
        }
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Extension Methods
        public static int CompareTo(this IGetResourceIdentity getResourceIdentity, IGetResourceIdentity other)
        {
            if (Object.ReferenceEquals(getResourceIdentity, other))
            {
                return(0);
            }

            if (other == null)
            {
                return(1);
            }

            var typeCompare = String.Compare(getResourceIdentity.Type, other.Type, System.StringComparison.Ordinal);

            return(typeCompare != 0
                ? typeCompare
                : String.Compare(getResourceIdentity.Id, other.Id, System.StringComparison.Ordinal));
        }
        public static bool Equals(this IGetResourceIdentity getResourceIdentity, object obj)
        {
            if (Object.ReferenceEquals(getResourceIdentity, obj))
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            var objAsHasResourceIdentity = obj as IGetResourceIdentity;

            if (objAsHasResourceIdentity == null)
            {
                return(false);
            }

            return(getResourceIdentity.Type == objAsHasResourceIdentity.Type && getResourceIdentity.Id == objAsHasResourceIdentity.Id);
        }
Ejemplo n.º 8
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Factory Methods
        public static DomId CreateFromApiResourceIdentity(IResourceType resourceType, IGetResourceIdentity apiResourceIdentity)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(apiResourceIdentity != null);

            var apiId = apiResourceIdentity.Id;

            var resourceIdentity = resourceType.ResourceIdentityInfo;
            var clrId            = resourceIdentity.ToClrId(apiId);
            var clrPropertyName  = resourceIdentity.Id.ClrPropertyName;
            var clrPropertyType  = resourceIdentity.Id.ClrPropertyType;

            var domId = new DomId(apiId, clrId, clrPropertyName, clrPropertyType);

            return(domId);
        }
        public static void MapApiIdToClrResource(this IResourceType resourceType, object clrResource, IGetResourceIdentity apiGetResourceIdentity)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(clrResource != null);
            Contract.Requires(apiGetResourceIdentity != null);

            var apiId = apiGetResourceIdentity.Id;
            var clrId = resourceType.ToClrId(apiId);

            resourceType.SetClrId(clrResource, clrId);
        }
        public static bool IsDefined(this IGetResourceIdentity getResourceIdentity)
        {
            Contract.Requires(getResourceIdentity != null);

            return(!getResourceIdentity.IsUndefined());
        }
 public static int CompareTo(this IGetResourceIdentity getResourceIdentity, object obj)
 {
     return(getResourceIdentity.CompareTo((IGetResourceIdentity)obj));
 }
Ejemplo n.º 12
0
        public static int GetHashCode(this IGetResourceIdentity getResourceIdentity)
        {
            Contract.Requires(getResourceIdentity != null);

            return(getResourceIdentity.Type.GetHashCode() ^ getResourceIdentity.Id.GetHashCode());
        }