ilyalatt / Telega

C# Telegram MTProto Client
https://ilyalatt.github.io/Telega/
MIT License
58 stars 15 forks source link

I Hate Functional ".AsTag().ToArray()[0];" #42

Closed GihanSoft closed 3 years ago

GihanSoft commented 3 years ago

Every thing I want to do need a damn .AsTag().ToArray()[0] why? why should you do this thing to your self?

GihanSoft commented 3 years ago

you yourself even added a extension function AssertSome

ilyalatt commented 3 years ago

Hi. It is the problem of the Telegram API that a lot of classes have a few tags and only one of them is actually used. It is not the only problem. I recommend you to use AssertSome for now. When I developed the library I thought it should be heavily functional. Now I think that it adds a lot of complexity for many cases. So a plan for simplifying this case is usage of nullable types. So .AsTag().AssertSome().Document.AsTag().AssertSome(), that can be simplified like .AsTag().Map(x => x.Document).Bind(Document.AsTag).AssertSome() will look like .AsTag()?.Document?.AsTag()! or maybe even .Tag?.Document?.Tag!. But I do not have time for this change for now. If you're interested in this change to be soon pull requests are welcome.

GihanSoft commented 3 years ago

Tanks for answer this fast. this would be good if use nullable. and please use properties and not fileds.

ilyalatt commented 3 years ago

Why do you want to use properties?

GihanSoft commented 3 years ago

It's C# standard. It's feel more natural and normal. But it's not important. Would it be a problem if I change it in pull request if I do? (you know I came to use this lib because TLSharp continuously throw Auth Key Unregistered any time I restart app. Oh ant it has a problem I just forced to download and fix and auth problem came up after that.)

ilyalatt commented 3 years ago

Ok. I think it is the right direction because I want to use C# 9 records and they use init only properties as well.

ilyalatt commented 3 years ago

Yeah, TLSharp state was the reason for this library :)

GihanSoft commented 3 years ago

C# 9 is great. but I don't know whether .NET standard support records or not. I think it is a (.NET5) thing.

ilyalatt commented 3 years ago

.NET 5 is needed for the new compiler that supports C# 9. This feature is just syntax sugar and can be used even in .NET FW 4.0. Here is the guide.

ilyalatt commented 3 years ago

It should be easier now. Try the last master. Do not forget to remove Rpc/Dto/Types and Rpc/Dto/Functions. Source generator is used now. Here is the commit with changes. The design is not certain for now and can be changed.