import { Injectable, Injector } from '@angular/core'
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest
} from '@angular/common/http'
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/throw'
import 'rxjs/add/operator/catch'
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('intercepted request ... ')
return next.handle(req).catch((error, caught) => {
// Проверяем код ошибки. Берём роутер и перенаправляем куда вам угодно.
return Observable.throw(error)
}) as any
}
}
Console.WriteLine((1.0 / 7).ToString());
Console.WriteLine((1 / 7.0).ToString());
Console.WriteLine((1f / 7).ToString());
Console.WriteLine((1 / 7d).ToString());
Console.WriteLine((((double)1) / 7).ToString());
Console.WriteLine((1 /((float)(7))).ToString());
Console.WriteLine(((float)(1 / 7)).ToString("0.##"));
Давно я конечно не писал на C#..
..или изменилась правила деления?
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
class HeaderA
{
public string Signature {get;set;}
public DateTime CreatedDate {get;set;}
public int Version {get;set;}
}
class HeaderB
{
public string Signature {get;set;}
public DateTime CreatedDate {get;set;}
public long AuthorId {get;set;}
public string MagicString {get;set;}
}
public class A<TData>
{
//header
public HeaderA Header {get;set;}
//data
public TData Data {get;set;}
}
public class B<TData>
{
//header
public HederB Header {get;set;}
//data
public TData Data {get;set;}
}
class HederData<THeder, TData>
{
public THeder Header {get;set;}
public TData Data {get;set;}
}
var a = new DataHaeder<HeaderA, string>();
var b = new DataHeader<HeaderB, int>();
(var headerA, dataA)
class CommonProp
{
public string Signature {get;set;}
public DateTime CreatedDate {get;set;}
}
class HeaderA : CommonProp
{
public int Version {get;set;}
}
class HeaderB : CommonProp
{
public long AuthorId {get;set;}
public string MagicString {get;set;}
}
public interface ISignable
{
ISignature Signature { get; set; }
byte[] Serialize();
}
public interface ISignature
{
}
public interface ISignatureService
{
bool Validate(ISignable signable);
void Sign(ISignable signable);
}
class MyObject : ISignable
{
public ISignature Signature { get; set; }
public long Param1 { get; set; }
public string Param2 { get; set; }
public string InnerData { get; set; }
public byte[] Serialize()
{
return Encoding.UTF8.GetBytes(Param1 + Param2 + InnerData);
}
}
public class HashCodeSignatureService : ISignatureService
{
public void Sign(ISignable signable)
{
var signature = CalculateSignature(signable);
signable.Signature = signature;
}
public bool Validate(ISignable signable)
{
var s1 = CalculateSignature(signable);
var s2 = signable.Signature as SimpleHashCodeSignature;
return s1?.HashCode == s2?.HashCode;
}
private static SimpleHashCodeSignature CalculateSignature(ISignable signable)
{
var body = signable.Serialize();
var signature = new SimpleHashCodeSignature(body.Aggregate(0, (a, b) => a + b.GetHashCode()));
return signature;
}
}
public class SimpleHashCodeSignature : ISignature
{
public int HashCode { get; }
public SimpleHashCodeSignature(int hashCode)
{
HashCode = hashCode;
}
}
class Program
{
static void Main(string[] args)
{
var obj = new MyObject {Param1 = 1, Param2 = "asd", InnerData = "some data"};
var signatureService = new HashCodeSignatureService();
signatureService.Sign(obj);
// Passing the object across untrusted boundary
signatureService.Validate(obj);
}
}